From 00db98bd753bb179e81c1b382c9f0cf0ea4d0a5d Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Thu, 13 Jun 2024 21:51:16 -0400 Subject: [PATCH 1/9] Impl --- app/local.env | 4 ++++ docker-compose.override.yml.example | 8 ++++++++ docs/app/getting-started.md | 9 +++++++++ 3 files changed, 21 insertions(+) create mode 100644 docker-compose.override.yml.example diff --git a/app/local.env b/app/local.env index 21c5a1b6..e99876b6 100644 --- a/app/local.env +++ b/app/local.env @@ -63,8 +63,12 @@ HIDE_SQL_PARAMETER_LOGS=TRUE # add them to this file to avoid mistakenly # committing them. Set these in your shell # by doing `export AWS_ACCESS_KEY_ID=whatever` +# if you are running the app directly, or +# in your `app/.env` if you are running the +# app in a Docker container AWS_ACCESS_KEY_ID=DO_NOT_SET_HERE AWS_SECRET_ACCESS_KEY=DO_NOT_SET_HERE + # These next two are commented out as we # don't have configuration for individuals # to use these at the moment and boto3 diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example new file mode 100644 index 00000000..e998d43c --- /dev/null +++ b/docker-compose.override.yml.example @@ -0,0 +1,8 @@ +version: '3' + +services: + + main-app: + env_file: + - ./app/local.env + - ./app/.env diff --git a/docs/app/getting-started.md b/docs/app/getting-started.md index 589c97eb..473d5c0a 100644 --- a/docs/app/getting-started.md +++ b/docs/app/getting-started.md @@ -33,6 +33,15 @@ A very simple [docker-compose.yml](/docker-compose.yml) has been included to sup 6. Run `make run-logs` to see the logs of the running API container 7. Run `make stop` when you are done to delete the container. +## (Optional) Configure local secrets + +If you need to pass secrets to the application via environment variables, copy the provided [/docker-compose.override.yml.example](/docker-compose.override.yml.example) to /docker-compose.override.yml. Then create an `/app/.env` file with your secrets. The override will pass this file to the Docker container with your application. + +```bash +cp docker-compose.override.yml.example docker-compose.override.yml +touch app/.env +``` + ## Next steps Now that you're up and running, read the [application docs](README.md) to familiarize yourself with the application. From be5f5b5c2137126537fceeca651ab44418fec1ed Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Thu, 13 Jun 2024 21:53:56 -0400 Subject: [PATCH 2/9] Add .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 5719cc0b..9e001135 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,8 @@ # IDE-specific files .vscode/* .idea + +# This file is used in local development to pass an /app/.env +# file to the container, for secrets. It should not be committed +# to the repo because tests and CI/CD will not have an .env file. +docker-compose.override.yml \ No newline at end of file From 870ed31f2bc8b9a6e09ccb8b599cc6b44ac8cace Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Mon, 24 Jun 2024 09:53:30 -0400 Subject: [PATCH 3/9] Move files and update docs --- .gitignore | 5 ----- app/.gitignore | 5 +++++ .../docker-compose.debug.yml | 0 .../docker-compose.override.yml.example | 0 docker-compose.yml => app/docker-compose.yml | 0 docs/app/getting-started.md | 19 ++++++++----------- 6 files changed, 13 insertions(+), 16 deletions(-) rename docker-compose.debug.yml => app/docker-compose.debug.yml (100%) rename docker-compose.override.yml.example => app/docker-compose.override.yml.example (100%) rename docker-compose.yml => app/docker-compose.yml (100%) diff --git a/.gitignore b/.gitignore index 9e001135..5719cc0b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,3 @@ # IDE-specific files .vscode/* .idea - -# This file is used in local development to pass an /app/.env -# file to the container, for secrets. It should not be committed -# to the repo because tests and CI/CD will not have an .env file. -docker-compose.override.yml \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore index d4c0859c..a85aca5b 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -29,3 +29,8 @@ coverage.* # Poetry installer local error logs poetry-installer-error-*.log + +# This file is used in local development to pass an /app/.env +# file to the container, for secrets. It should not be committed +# to the repo because tests and CI/CD will not have an .env file. +docker-compose.override.yml diff --git a/docker-compose.debug.yml b/app/docker-compose.debug.yml similarity index 100% rename from docker-compose.debug.yml rename to app/docker-compose.debug.yml diff --git a/docker-compose.override.yml.example b/app/docker-compose.override.yml.example similarity index 100% rename from docker-compose.override.yml.example rename to app/docker-compose.override.yml.example diff --git a/docker-compose.yml b/app/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to app/docker-compose.yml diff --git a/docs/app/getting-started.md b/docs/app/getting-started.md index 473d5c0a..906aff14 100644 --- a/docs/app/getting-started.md +++ b/docs/app/getting-started.md @@ -6,8 +6,6 @@ A very simple [docker-compose.yml](/docker-compose.yml) has been included to sup ## Prerequisites -**Note:** Run everything from within the `/app` folder: - 1. Install the version of Python specified in [.python-version](/app/.python-version) [pyenv](https://github.com/pyenv/pyenv#installation) is one popular option for installing Python, or [asdf](https://asdf-vm.com/). @@ -21,21 +19,20 @@ A very simple [docker-compose.yml](/docker-compose.yml) has been included to sup 3. If you are using an M1 mac, you will need to install postgres as well: `brew install postgresql` (The psycopg2-binary is built from source on M1 macs which requires the postgres executable to be present) -4. You'll also need [Docker Desktop](https://www.docker.com/products/docker-desktop/) +4. You'll also need [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed and running. ## Run the application -1. In your terminal, `cd` to the `app` directory of this repo. -2. Make sure you have [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed & running. -3. Run `make setup-local` to install dependencies -4. Run `make init start` to build the image and start the container. -5. Navigate to `localhost:8080/docs` to access the Swagger UI. -6. Run `make run-logs` to see the logs of the running API container -7. Run `make stop` when you are done to delete the container. +**Note:** Run everything from within the `/app` folder: + +1. Run `make init start` to build the image and start the container. +2. Navigate to `localhost:8080/docs` to access the Swagger UI. +3. Run `make run-logs` to see the logs of the running API container +4. Run `make stop` when you are done to delete the container. ## (Optional) Configure local secrets -If you need to pass secrets to the application via environment variables, copy the provided [/docker-compose.override.yml.example](/docker-compose.override.yml.example) to /docker-compose.override.yml. Then create an `/app/.env` file with your secrets. The override will pass this file to the Docker container with your application. +If you need to pass secrets to the application via environment variables, copy the provided [/app/docker-compose.override.yml.example](/docker-compose.override.yml.example) to `/app/docker-compose.override.yml`. Then create an `/app/.env` file with your secrets. The override will pass this file to the Docker container with your application. ```bash cp docker-compose.override.yml.example docker-compose.override.yml From 90c4ab4ec2927f2d89c8fffd5c9e0d5959185a3b Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Mon, 24 Jun 2024 09:56:17 -0400 Subject: [PATCH 4/9] Remove version from override example --- app/docker-compose.override.yml.example | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/docker-compose.override.yml.example b/app/docker-compose.override.yml.example index e998d43c..119f96c1 100644 --- a/app/docker-compose.override.yml.example +++ b/app/docker-compose.override.yml.example @@ -1,5 +1,3 @@ -version: '3' - services: main-app: From 31a0c228f2a2619a2aa14ed1d212643a405652ed Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Mon, 24 Jun 2024 10:04:01 -0400 Subject: [PATCH 5/9] Update paths in compose files --- app/docker-compose.debug.yml | 6 +++--- app/docker-compose.override.yml.example | 4 ++-- app/docker-compose.yml | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/docker-compose.debug.yml b/app/docker-compose.debug.yml index 602c799f..1e8a80ad 100644 --- a/app/docker-compose.debug.yml +++ b/app/docker-compose.debug.yml @@ -3,13 +3,13 @@ services: main-app: build: - context: ./app + context: ./ target: dev args: - RUN_UID=${RUN_UID:-4000} - RUN_USER=${RUN_USER:-app} container_name: main-app - env_file: ./app/local.env + env_file: local.env command: [ "poetry", "run", "python", "-m", "debugpy", "--listen", "0.0.0.0:5678", @@ -20,4 +20,4 @@ services: ports: - 5678:5678 volumes: - - ./app:/app + - ./:/ diff --git a/app/docker-compose.override.yml.example b/app/docker-compose.override.yml.example index 119f96c1..94443e81 100644 --- a/app/docker-compose.override.yml.example +++ b/app/docker-compose.override.yml.example @@ -2,5 +2,5 @@ services: main-app: env_file: - - ./app/local.env - - ./app/.env + - local.env + - .env diff --git a/app/docker-compose.yml b/app/docker-compose.yml index ddb0c307..c7ee6bd8 100644 --- a/app/docker-compose.yml +++ b/app/docker-compose.yml @@ -17,18 +17,18 @@ services: main-app: build: - context: ./app + context: ./ target: dev args: - RUN_UID=${RUN_UID:-4000} - RUN_USER=${RUN_USER:-app} command: ["poetry", "run", "flask", "--app", "src.app", "run", "--host", "0.0.0.0", "--port", "8080", "--reload"] container_name: main-app - env_file: ./app/local.env + env_file: local.env ports: - 8080:8080 volumes: - - ./app:/app + - ./:/ depends_on: - main-db From 5703d6a6dac68d3cb95c6b0ffef7414d07bb24da Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Mon, 24 Jun 2024 10:05:59 -0400 Subject: [PATCH 6/9] Fix mount dest --- app/docker-compose.debug.yml | 2 +- app/docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/docker-compose.debug.yml b/app/docker-compose.debug.yml index 1e8a80ad..2b840fa2 100644 --- a/app/docker-compose.debug.yml +++ b/app/docker-compose.debug.yml @@ -20,4 +20,4 @@ services: ports: - 5678:5678 volumes: - - ./:/ + - ./:/app diff --git a/app/docker-compose.yml b/app/docker-compose.yml index c7ee6bd8..f6c4011b 100644 --- a/app/docker-compose.yml +++ b/app/docker-compose.yml @@ -28,7 +28,7 @@ services: ports: - 8080:8080 volumes: - - ./:/ + - ./:/app depends_on: - main-db From 937a6a7d20df29c974e939d59f243e453fffb85c Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Fri, 28 Jun 2024 14:43:59 -0400 Subject: [PATCH 7/9] Patch documentation --- docs/app/README.md | 3 +-- docs/app/getting-started.md | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/app/README.md b/docs/app/README.md index 7723a9ce..3c1ef0de 100644 --- a/docs/app/README.md +++ b/docs/app/README.md @@ -31,8 +31,7 @@ root │ └── pyproject.toml Python project configuration file │ └── setup.cfg Python config for tools that don't support pyproject.toml yet │ └── Dockerfile Docker build file for project -│ -└── docker-compose.yml Config file for docker-compose tool, used for local development +└── └── docker-compose.yml Config file for docker-compose tool, used for local development ``` ## Information diff --git a/docs/app/getting-started.md b/docs/app/getting-started.md index 906aff14..df13fb3f 100644 --- a/docs/app/getting-started.md +++ b/docs/app/getting-started.md @@ -28,7 +28,7 @@ A very simple [docker-compose.yml](/docker-compose.yml) has been included to sup 1. Run `make init start` to build the image and start the container. 2. Navigate to `localhost:8080/docs` to access the Swagger UI. 3. Run `make run-logs` to see the logs of the running API container -4. Run `make stop` when you are done to delete the container. +4. Run `make stop` when you are done to stop the container. ## (Optional) Configure local secrets From f077472a7d8211761f47d9e96ed27704cde3208a Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Tue, 2 Jul 2024 11:38:36 -0400 Subject: [PATCH 8/9] Fake commit for CI --- app/src/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/app.py b/app/src/app.py index 4fdd90d9..b28f5fed 100644 --- a/app/src/app.py +++ b/app/src/app.py @@ -6,6 +6,8 @@ from flask import g from werkzeug.exceptions import Unauthorized + + import src.adapters.db as db import src.adapters.db.flask_db as flask_db import src.logging From 2dd4a10bda8d5a56ed24afc45e39921edc5367cb Mon Sep 17 00:00:00 2001 From: Kevin Boyer Date: Tue, 2 Jul 2024 11:38:55 -0400 Subject: [PATCH 9/9] Undo fake commit for CI --- app/src/app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/app.py b/app/src/app.py index b28f5fed..4fdd90d9 100644 --- a/app/src/app.py +++ b/app/src/app.py @@ -6,8 +6,6 @@ from flask import g from werkzeug.exceptions import Unauthorized - - import src.adapters.db as db import src.adapters.db.flask_db as flask_db import src.logging