|
1 | 1 | # iAtlas API
|
2 | 2 |
|
3 |
| -A GraphQL API that serves data from the iAtlas Data Database. This is built in Python and developed and deployed in Docker. |
| 3 | +A GraphQL API that serves data from the iAtlas Data Database. This is built in Python and developed |
| 4 | +and deployed in Docker. |
4 | 5 |
|
5 |
| -## Status |
| 6 | +## Usage |
6 | 7 |
|
7 |
| -### Staging |
| 8 | +Show the tasks available to this project: |
8 | 9 |
|
9 |
| -[](https://cri-iatlas.gitlab.io/iatlas-api/) |
10 |
| - |
11 |
| -## Dependencies |
12 |
| - |
13 |
| -- [Docker Desktop](https://www.docker.com/products/docker-desktop) (`docker`) |
14 |
| -- [Visual Studio Code](https://code.visualstudio.com/) (`code`) - this is optional, but sure makes everything a lot easier. |
15 |
| - |
16 |
| -## Development |
17 |
| - |
18 |
| -The instructions below assume that there is a PostgreSQL server running locally with the iAtlas Database installed (see [iAtlas-Data](https://gitlab.com/cri-iatlas/iatlas-data)). If this is not the case, please see information on [running PostgreSQL in Docker](#running-postgres-in-docker) below. |
19 |
| - |
20 |
| -To change any of the environment variables used by the app see [Environment Variables](#environment-variables) below. |
21 |
| - |
22 |
| -The first time you checkout the project, run the following command to build the docker image, start the container, and start the API: |
23 |
| - |
24 |
| -```sh |
25 |
| -./start.sh |
| 10 | +```console |
| 11 | +nx show project iatlas-api |
26 | 12 | ```
|
27 | 13 |
|
28 |
| -This will build the Docker image and run the container. Once the container is created, the Flask server will be started. |
29 |
| - |
30 |
| -The GraphiQL playground interface should open automatically in your browser. |
31 |
| - |
32 |
| -**Note:** If you get _'Version in "./docker-compose.yml" is unsupported.'_, please update your version of Docker Desktop. |
| 14 | +## Create the project configuration file |
33 | 15 |
|
34 |
| -**Optional:** If you choose to use VS Code, you can use the [Dev-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension to develop from within the container itself. Using this approach, you don't need to install Python or any dependencies (besides Docker and VS Code itself) as everything is already installed inside the container. There is a volume mapped to your user .ssh folder so that your ssh keys are available inside the container as well as your user .gitconfig file. The user folder inside the container is also mapped to a volume so that it persists between starts and stops of the container. This means you may create a .bash_profile or similar for yourself within the container and it will persist between container starts and stops. |
35 |
| - |
36 |
| -The following command will stop the server and container: |
37 |
| - |
38 |
| -```sh |
39 |
| -./stop.sh |
| 16 | +```console |
| 17 | +nx create-config iatlas-api |
40 | 18 | ```
|
41 | 19 |
|
42 |
| -Restart the container with the following command: |
| 20 | +## Prepare the Python environment |
43 | 21 |
|
44 |
| -```sh |
45 |
| -./start.sh |
| 22 | +```console |
| 23 | +nx prepare iatlas-api |
46 | 24 | ```
|
47 | 25 |
|
48 |
| -If there are changes made to the container or image, first, stop the container `./stop.sh`, then rebuild it and restarted it with `./start.sh --build` or `./start.sh -b`. |
49 |
| - |
50 |
| -Remote into iatlas-dev container. |
51 |
| - |
52 |
| -Open the workspace by file -> Open workspace from file -> /project/iatlas-api.code-workspace |
53 |
| - |
54 |
| -### Non-Dockerized |
55 |
| - |
56 |
| -If you choose NOT to use the dockerized development method above, please ensure the following are installed: |
57 |
| - |
58 |
| -- [Python](https://www.python.org/) - version 3.8 |
59 |
| -- All the packages in the [`requirements.txt`](./requirements.txt) file at the versions specified. |
60 |
| -- All the packages in the [`requirements-dev.txt`](./requirements-dev.txt) file at the versions specified. |
61 |
| - |
62 |
| -See [https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) for information on installing Python packages for a specific project. |
| 26 | +## Build the Docker image |
63 | 27 |
|
64 |
| -Start the app with the following called from the root of the project. (Please note the dot(`.`) at the very beginning of the command. This will "source" the script.): |
65 |
| - |
66 |
| -```sh |
67 |
| -. set_env_variables.sh && python run.py |
| 28 | +```console |
| 29 | +nx build-image iatlas-api |
68 | 30 | ```
|
69 | 31 |
|
70 |
| -### Running Postgres in Docker |
71 |
| - |
72 |
| -A simple way to get PostgreSQL running locally is to use Docker. Here is a simple Dockerized PostgreSQL server with pgAdmin: |
73 |
| - |
74 |
| -["postgres_docker" on Github](https://github.com/generalui/postgres_docker) |
75 |
| - |
76 |
| -#### Linux ONLY |
77 |
| - |
78 |
| -If you are running on a Linux operating system the default connection to the docker container `host.docker.internal` will not work. To connect to the local dockerized PostgreSQL DB, ensure there is a `.env-dev` file ([`.env-SAMPLE`](./.env-SAMPLE) can be used as a reference.) In the `.env-dev` file, ensure the `POSTGRES_HOST` variable is set to `172.17.0.1` |
| 32 | +## Start the API with Docker Compose |
79 | 33 |
|
80 |
| -```.env-dev |
81 |
| -POSTGRES_HOST=172.17.0.1 |
| 34 | +```console |
| 35 | +nx serve-detach iatlas-api |
82 | 36 | ```
|
83 | 37 |
|
84 |
| -### Connecting to a different Database |
| 38 | +## Open the GraphQL Playground |
85 | 39 |
|
86 |
| -Alternatively, the app may be set up to connect to the existing staging database or another database. |
| 40 | +To access the GraphQL Playground, open your browser and navigate to: |
87 | 41 |
|
88 |
| -To connect to a different database (ie staging), the `.env-dev` file must also be used with values similar to: |
| 42 | +`http://http://localhost:5000/graphiql` |
89 | 43 |
|
90 |
| -```.env-dev |
91 |
| -POSTGRES_DB=iatlas_staging |
92 |
| -POSTGRES_HOST=iatlas-staging-us-west-2.cluster-cfb68nhqxoz9.us-west-2.rds.amazonaws.com |
93 |
| -POSTGRES_PASSWORD={Get_the_staging_password} |
94 |
| -POSTGRES_USER=postgres |
95 |
| -``` |
96 |
| - |
97 |
| -### Environment Variables |
| 44 | +Use the query shown below to test the API or use one included in `./example_queries`. |
98 | 45 |
|
99 |
| -All the environment variables used by the app have defaults. To set the environment variables, simply run the following bash script from the root of the project. (Please note the dot(`.`) at the very beginning of the command. This will "source" the script.): |
100 |
| - |
101 |
| -```sh |
102 |
| -. set_env_variables.sh |
| 46 | +```json |
| 47 | +{ |
| 48 | + __schema { |
| 49 | + queryType { |
| 50 | + name |
| 51 | + } |
| 52 | + } |
| 53 | +} |
103 | 54 | ```
|
104 |
| - |
105 |
| -The default environment variables' values may be over-written by adding the value to a `.env-dev` file in the root of the project. This file is not versioned in the repository. |
106 |
| - |
107 |
| -The [`.env-SAMPLE`](./.env-SAMPLE) file is an example of what the `.env-dev` could be like and may be used as a reference. |
108 |
| - |
109 |
| -## Testing |
110 |
| - |
111 |
| -All tests are in the [`tests/`](./tests/) folder. |
112 |
| - |
113 |
| -See: [TESTING.md](./tests/TESTING.md) in the [`tests/`](./tests/) folder |
114 |
| - |
115 |
| -## Performance Profiling |
116 |
| - |
117 |
| -See: [PROFILING.md](./api/telemetry/PROFILING.md) in the [`api/telemetry/`](./api/telemetry/) folder |
118 |
| - |
119 |
| -## Logging |
120 |
| - |
121 |
| -See: [LOGGING.md](./api/logger/LOGGING.md) in the [`api/logger/`](./api/logger/) folder |
0 commit comments