|
1 | 1 | # api.keyman.com |
2 | 2 |
|
3 | | -The following is outdated and will be replaced with Docker/Apache |
| 3 | +This is the source for the website https://api.keyman.com/, which hosts the |
| 4 | +database backend for Keyman websites. This site runs on Apache in a Docker |
| 5 | +container, and the database itself runs on SQL Server for Linux in a separate |
| 6 | +container. |
4 | 7 |
|
5 | | -## Configuration |
| 8 | +## Other Keyman websites |
6 | 9 |
|
7 | | -Currently, this site runs only on a Windows host with IIS and Microsoft SQL Server. |
| 10 | +* **[api.keyman.com]** - database backend for Keyman websites |
| 11 | +* **[help.keyman.com]** - documentation home for Keyman |
| 12 | +* **[keyman.com]** - Keyman home |
| 13 | +* **[keymanweb.com]** - KeymanWeb online keyboard |
| 14 | +* **[s.keyman.com]** - static Javascript, font, and related resources |
| 15 | +* **[website-local-proxy]** - run all Keyman sites on localhost on the same port |
8 | 16 |
|
9 | | -## Prerequisites |
| 17 | +## How to run api.keyman.com locally |
10 | 18 |
|
11 | | -* Windows |
12 | | -* Chocolatey |
13 | | -* PHP 7.4 |
14 | | -* MS SQL Server 2016 or later including FullText Search |
| 19 | +When run locally, this site can be accessed at http://localhost:8058 or |
| 20 | +http://api.keyman.com.localhost:8058. |
15 | 21 |
|
16 | | -* `configure.ps1` automatically installs chocolatey, PHP, Composer, SQL Server and PHP-PDO driver |
17 | | - for SQL Server. This script is not particularly sophisticated, so for manual config, copy and |
18 | | - paste elements from the script. |
| 22 | +**Recommended:** Use [website-local-proxy] to run multiple keyman.com sites |
| 23 | +all from the same port (default port 80). |
19 | 24 |
|
20 | | -## Setup |
| 25 | +**Recommended:** Use [shared-sites] to control startup and shutdown of all |
| 26 | +keyman.com sites together. |
21 | 27 |
|
22 | | -1. Install the dependencies: |
| 28 | +### Prerequisites |
23 | 29 |
|
24 | | -``` |
25 | | -composer install |
26 | | -``` |
27 | | - |
28 | | -2. Configure your local environment by copying tools/db/localenv.php.in to tools/db/localenv.php |
29 | | - and completing the details therein. |
30 | | - |
31 | | -3. Build the backend database from live data: |
| 30 | +The host machine needs the following apps installed: |
| 31 | +* [Git] |
| 32 | +* Bash 5.x (on Windows, you can use Git Bash that comes with [Git]) |
| 33 | +* [Docker Desktop] |
32 | 34 |
|
33 | | -``` |
34 | | -composer build |
35 | | -``` |
| 35 | + <details> |
| 36 | + <summary>Configuration of Docker on Windows</summary> |
36 | 37 |
|
37 | | -## Tests |
| 38 | + On Windows machines, you can setup Docker in two different ways, either of |
| 39 | + which should work: |
| 40 | + * [Enable Hyper-V on Windows 11](https://techcommunity.microsoft.com/t5/educator-developer-blog/step-by-step-enabling-hyper-v-for-use-on-windows-11/ba-p/3745905) |
| 41 | + * [WSL2](https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-10#1-overview) |
38 | 42 |
|
39 | | -Test suites run with mock data from the tests/data folder. If this data is refreshed, fixtures |
40 | | -will probably need to be updated accordingly as the data in them will have become stale. |
| 43 | + </details> |
41 | 44 |
|
42 | | -To run tests: |
| 45 | +### Actions |
43 | 46 |
|
44 | | -``` |
45 | | -composer test |
46 | | -``` |
| 47 | +#### Build the Docker image |
47 | 48 |
|
48 | | -To force a rebuild of the test database (e.g. if schema changes): |
| 49 | +The first time you want to start up the site, or if there have been Docker |
| 50 | +configuration changes, you will need to rebuild the Docker images. Start a bash |
| 51 | +shell, and from this folder, run: |
49 | 52 |
|
50 | | -``` |
51 | | -TEST_REBUILD=1 composer test |
| 53 | +```sh |
| 54 | +./build.sh build |
52 | 55 | ``` |
53 | 56 |
|
54 | | -## Configuring a new Azure Database |
| 57 | +#### Start the Docker container |
55 | 58 |
|
56 | | -1. Create an Azure SQL Server |
57 | | -2. Create an Azure SQL Database, e.g. called 'keymanapi' |
58 | | -3. Run the following script on the master database, replacing password as necessary: |
| 59 | +To start up the website, in bash, run: |
59 | 60 |
|
| 61 | +```sh |
| 62 | +./build.sh start --debug |
60 | 63 | ``` |
61 | | --- logins for staging |
62 | | -CREATE LOGIN [k0] WITH PASSWORD=N'password' |
63 | | -GO |
64 | | -
|
65 | | -CREATE LOGIN [k1] WITH PASSWORD=N'password' |
66 | | -GO |
67 | 64 |
|
68 | | --- logins for production |
69 | | -CREATE LOGIN [production_k0] WITH PASSWORD=N'password' |
70 | | -GO |
| 65 | +Once the container starts, you can access the api.keyman.com site at |
| 66 | +http://localhost:8058 or http://api.keyman.com.localhost:8058 |
71 | 67 |
|
72 | | -CREATE LOGIN [production_k1] WITH PASSWORD=N'password' |
73 | | -GO |
74 | | -``` |
| 68 | +#### Stop the Docker container |
75 | 69 |
|
76 | | -4. Run the following script on the keymanapi database: |
| 70 | +In bash, run: |
77 | 71 |
|
| 72 | +```sh |
| 73 | +./build.sh stop |
78 | 74 | ``` |
79 | | --- Schemas, users and roles for staging |
80 | | -CREATE SCHEMA [k0] |
81 | | -GO |
82 | | -
|
83 | | -CREATE SCHEMA [k1] |
84 | | -GO |
85 | 75 |
|
86 | | -CREATE USER [k0] FOR LOGIN [k0] WITH DEFAULT_SCHEMA=[k0] |
87 | | -GO |
| 76 | +#### Remove the Docker container and image |
88 | 77 |
|
89 | | -CREATE USER [k1] FOR LOGIN [k1] WITH DEFAULT_SCHEMA=[k1] |
90 | | -GO |
| 78 | +In bash, run: |
91 | 79 |
|
92 | | -ALTER ROLE db_owner ADD MEMBER k0 |
93 | | -GO |
| 80 | +```sh |
| 81 | +./build.sh clean |
| 82 | +``` |
94 | 83 |
|
95 | | -ALTER ROLE db_owner ADD MEMBER k1 |
96 | | -GO |
| 84 | +#### Running tests |
97 | 85 |
|
98 | | --- Schemas, users and roles for production |
99 | | -CREATE SCHEMA [production_k0] |
100 | | -GO |
| 86 | +Test suites run with mock data from the tests/data folder. To check APIs, broken |
| 87 | +links and .php file conformance, when the site is running, in bash, run: |
101 | 88 |
|
102 | | -CREATE SCHEMA [production_k1] |
103 | | -GO |
| 89 | +```sh |
| 90 | +./build.sh test |
| 91 | +``` |
104 | 92 |
|
105 | | -CREATE USER [production_k0] FOR LOGIN [production_k0] WITH DEFAULT_SCHEMA=[production_k0] |
106 | | -GO |
| 93 | +To force a rebuild of the test database from the mock data (for example if |
| 94 | +schema changes and this is not automatically detected): |
107 | 95 |
|
108 | | -CREATE USER [production_k1] FOR LOGIN [production_k1] WITH DEFAULT_SCHEMA=[production_k1] |
109 | | -GO |
| 96 | +```sh |
| 97 | +./build.sh test --rebuild-test-fixtures |
| 98 | +``` |
110 | 99 |
|
111 | | -ALTER ROLE db_owner ADD MEMBER production_k0 |
112 | | -GO |
| 100 | +[Git]: https://git-scm.com/downloads |
| 101 | +[Docker Desktop]: https://docs.docker.com/get-docker/ |
| 102 | +[api.keyman.com]: https://github.com/keymanapp/api.keyman.com |
| 103 | +[help.keyman.com]: https://github.com/keymanapp/help.keyman.com |
| 104 | +[keyman.com]: https://github.com/keymanapp/keyman.com |
| 105 | +[keymanweb.com]: https://github.com/keymanapp/keymanweb.com |
| 106 | +[s.keyman.com]: https://github.com/keymanapp/s.keyman.com |
| 107 | +[website-local-proxy]: https://github.com/keymanapp/website-local-proxy |
| 108 | +[shared-sites]: https://github.com/keymanapp/shared-sites |
| 109 | +[enable Hyper-V]: https://techcommunity.microsoft.com/t5/educator-developer-blog/step-by-step-enabling-hyper-v-for-use-on-windows-11/ba-p/3745905 |
| 110 | +[enable WSL2]: https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-10#1-overview |
113 | 111 |
|
114 | | -ALTER ROLE db_owner ADD MEMBER production_k1 |
115 | | -GO |
116 | | -``` |
0 commit comments