Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for local secrets #227

Merged
merged 11 commits into from
Jul 2, 2024
Merged

Add support for local secrets #227

merged 11 commits into from
Jul 2, 2024

Conversation

KevinJBoyer
Copy link
Contributor

@KevinJBoyer KevinJBoyer commented Jun 14, 2024

Ticket

n/a

Changes

  • Provide an example docker compose override file
  • Update .gitignore to ensure non-example override files aren't committed
  • Update documentation (plus comment in local.env) to explain how to use it
  • Move the docker compose files to inside the app folder
  • Update the developer set up instructions

Context for reviewers

  • This allows developers to set local secrets that are passed to their Docker container.

Testing

Follow the instructions in the documentation and verify the contents of your .env match what's available to the Docker container.

.gitignore Outdated
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I wonder if the real issue here is where we keep the docker-compose file. Would there be any issue moving it to the app folder itself?

That's what we did on the simpler grants gov repo (this api folder is the equivalent of app): https://github.com/navapbc/simpler-grants-gov/tree/main/api

We do have a top-level docker-compose but just for the purposes of spinning up both the frontend and API together.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm open to that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that inside the app folder seems more appropriate to me.

Comment on lines +66 to +68
# if you are running the app directly, or
# in your `app/.env` if you are running the
# app in a Docker container
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Threading arbitrarily, - we might also need a change to the load_local_env_vars method which handles getting the local.env file into your env vars when you run outside of docker. Right now that automatically gets called for unit tests in the conftest file:

https://github.com/navapbc/template-application-flask/blob/main/app/tests/conftest.py#L21

I think if we just adjusted load_local_env_vars to do "if .env exists, load it before the local.env file" bit - then it would work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively - we could get rid of load_local_env_vars entirely and more accurately document how to do that properly when running outside of docker. Maybe I'll take that on next week.

main-app:
env_file:
- ./app/local.env
- ./app/.env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if we want to name the override env file something like override.env to make it clear on the behavior.

Copy link
Contributor

@lorenyu lorenyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies in advance for not providing more actionable or constructive feedback, but this approach feels kinda hacky and non-standard to me. i don't think this is a typical structure you see for projects using docker and docker compose. i prefer to come up with a "boring" solution that isn't something someone needs to learn if they come from another place.

@KevinJBoyer KevinJBoyer marked this pull request as ready for review June 24, 2024 13:55
Comment on lines -28 to -30
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
Copy link
Contributor Author

@KevinJBoyer KevinJBoyer Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed these lines:

  • 1 is redundant with the note about running from within the app folder (which I also moved to be directly above these steps)
  • 2 is redundant with the prerequisites above. If someone does miss that note, the error message is very clear ("Is Docker running?")
  • I believe 3 is not necessary since these steps assume running everything in the Docker container. For folks who do want to run things like formatting, etc, directly on their machine, the linked application docs under Next steps at the end of this do a great job explaining how to do so (including doing this step)

@KevinJBoyer KevinJBoyer requested review from lorenyu and chouinar June 24, 2024 14:55
Copy link
Contributor

@chouinar chouinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit misleading. Deleting might make someone think that the contents of their container will be removed when they run stop, but that isn't true as that's cached and/or stored in the volume.

Maybe we should adjust this to something like .. when you are done to stop the container.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 will make this change!

@KevinJBoyer KevinJBoyer merged commit ebe2640 into main Jul 2, 2024
4 checks passed
@KevinJBoyer KevinJBoyer deleted the kb/secrets-in-docker branch July 2, 2024 15:44
KevinJBoyer added a commit that referenced this pull request Jul 5, 2024
## Ticket

n/a

## Changes
- #227 moved the docker-compose.yml file out of the root and into /app,
but missed updating links to it in the documentation. This updates those
links.

## Context for reviewers
n/a

## Testing
n/a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants