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

build refactor: replace config.ini with environment variables (via single .env file) and fix templating issues #696

Merged
merged 4 commits into from
Feb 22, 2024

Conversation

sgfost
Copy link
Contributor

@sgfost sgfost commented Feb 15, 2024

attempts to consolidate all app configuration into environment variables

.env is created from a template and generated secrets are placed in, all variables defined in .env are then fed into the server container. The django settings module then reads from os.getenv() rather than configparser


list of changes:

  • removed config.ini/config.ini.template
  • removed docker.env
  • removed targets for any non-generated secrets, should be managed directly in the .env file
  • removed pgpass.template in favor of just echoing the correct format
  • set environment variables in server container from .env via env_file attribute
  • add convenience script envreplace for setting values in a file with GNU or BSD sed

resolves comses/planning#145

@sgfost sgfost requested a review from alee February 15, 2024 04:50
attempts to consolidate all app configuration into environment variables

.env is created from a template and generated secrets are placed in, all
variables defined in .env are then fed into the server container via
env_file in docker-compose.yml. The django settings module then reads
from os.getenv() rather than configparser

resolves comses/planning#145
@alee
Copy link
Member

alee commented Feb 15, 2024

I'd like to move towards something like https://docs.docker.com/compose/use-secrets/ - sorry for not including it in earlier issues / docs. I think we can pivot this PR into that work though.

That would just be for secrets things, other actual ENV-y things should definitely continue to live in the .env.template that you've set up nicely here.

@sgfost
Copy link
Contributor Author

sgfost commented Feb 15, 2024

That should be straightforward to add. I hadn't already done so mostly because I wasn't entirely sure what the benefit of using secrets sans swarm-mode (files in a tmpfs mount, I think?) over environment variables was

@alee
Copy link
Member

alee commented Feb 15, 2024

I'm mostly going on their docs here:

Docker Compose provides a way for you to use secrets without having to use environment variables to store information. If you’re injecting passwords and API keys as environment variables, you risk unintentional information exposure. Environment variables are often available to all processes, and it can be difficult to track access. They can also be printed in logs when debugging errors without your knowledge. Using secrets mitigates these risks.

The other thing though is to support granular secrets for each thing that needs the secret so that updating or adding new environment variables or secrets doesn't blow away the previous set

config.read("/run/secrets/config.ini")

RELEASE_VERSION = config.get("default", "BUILD_ID", fallback="v2023.01")
RELEASE_VERSION = os.getenv("RELEASE_VERSION", "v2024.01")
Copy link
Member

Choose a reason for hiding this comment

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

need to make BUILD_ID match up with RELEASE_VERSION in .env.template

@@ -0,0 +1,55 @@
# app
BUILD_ID=
Copy link
Member

Choose a reason for hiding this comment

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

rename to RELEASE_VERSION here and in the Makefile

@alee alee merged commit f110e2f into comses:main Feb 22, 2024
6 checks passed
sgfost added a commit to sgfost/port-of-mars that referenced this pull request Feb 23, 2024
mirrors improvements in comses/comses.net#696

* use one shared .env for all non-secret config (replaces server/.env
  and client/.../config.ts)
* continue to use files for secrets, but with docker compose secrets
* remove `configure` script in favor of an editable config.mk generated
  from template defaulting to DEPLOY_ENVIRONMENT=dev and figuring out
  correct base url in shared/settings.ts
* replace server/deploy/ with top level deploy dir
* clean up anything unused or unecessary from Makefile
sgfost added a commit to sgfost/port-of-mars that referenced this pull request Feb 23, 2024
mirrors improvements in comses/comses.net#696

* use one shared .env for all non-secret config (replaces server/.env
  and client/.../config.ts)
* continue to use files for secrets, but with docker compose secrets
* move base_url mapping to shared/settings.ts from `configure` script
* replace server/deploy/ with top level deploy dir
* clean up anything unused or unecessary from Makefile
sgfost added a commit to sgfost/port-of-mars that referenced this pull request Jun 6, 2024
mirrors improvements in comses/comses.net#696

* use one shared .env for all non-secret config (replaces server/.env
  and client/.../config.ts)
* continue to use files for secrets, but with docker compose secrets
* move base_url mapping to shared/settings.ts from `configure` script
* replace server/deploy/ with top level deploy dir
* clean up anything unused or unecessary from Makefile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants