self-hosted
self-hosted copied to clipboard
Can overriding .env variable be done differently?
Problem Statement
Currently, overriding .env variables requires creating a .env.custom. This approach currently completely ignores .env if .env.custom exists. This is slightly problematic during upgrades if we forget to update the .env.custom file with the updated values from .env.
Solution Brainstorm
In order not to break compatibility or make it a significant change, my suggestion is something as follows:
- Support a
.env.overridefile during installation - If
.env.overrideexists,.env.customwill be overwritten with an auto-generated before this code block: https://github.com/getsentry/self-hosted/blob/0d3191d9ac0b09a16ab792d04e5dc8f6766e13e2/install/_lib.sh#L24-L28 - The auto-generated file can be something like
cat .env .env.override > .env.custom(of course, this can be done differently, but if the environment exists multiple times, the last one will take effect). - The rest of the process will stay as is, and starting the Docker containers will still be using
.env.custom.docker-compose --env-file /opt/sentry/.env.custom up -d
Thanks for bringing this up, will categorize this as an enhancement
Why not just merge them? Read .env first and then .env.custom (or .env.local?) to overwrite values we want to change. Is there any specific problem with such approach?
Why not just merge them? Read .env first and then .env.custom (or .env.local?) to overwrite values we want to change. Is there any specific problem with such approach?
No reason not to. We can definitely introduce some sort of logic to merge these two together.
Another way is now available with docker compose. However, this requires docker-compose v2.24+, which is only one month old. So, I'm not sure if it's something that can be used already (I am not sure what Sentry's policy is regarding this).
Anyway, docker compose now supports optional env files, so it can now be solved by changing the env_file section in the docker-compose.yml file:
env_file:
- path: ./.env
required: true
- path: ./.env.custom
required: false
ref: https://docs.docker.com/compose/environment-variables/set-environment-variables/#additional-information
Thanks for bringing this up. That's awesome, but we'll want to at least wait since this is a relatively new change and we have many users right now that are under docker compose v2.24.