Proposal: flag to expose OS env to compose loader
Adding --env (short -e) to expose OS env to the Compose loader, eg. for interpolation.
services:
service1:
image: alpine
environment:
- API_KEY
Could be overridden during "up" by doing:
defang compose up -e API_KEY
This is similar to docker run -e …, though docker compose offers no such flag.
Just adding to this... in a way line 12 represents what we're doing in this table:
https://docs.docker.com/compose/how-tos/environment-variables/envvars-precedence/#how-the-table-works
The main difference is that they're being explicit about exposing an external secret using a command line flag, but I think we're being explicit about it by having the user run defang config set.
I would say there's a big difference between the two situations, though:
- In the docker context, the host could be anything in any context: you wouldn't want a random env var from who knows what to override your compose file
- In our context, those values overriding the ones in your file can only come from you, and are explicitly scoped to your project.
I think that makes it significantly different and makes it akin to passing -e ENVNAME in the Docker context.
@nullfunc and I also chatted about specificity. In my view, the compose.yaml file is "general": it describes the general structure of your system. Each cloud context you deploy it to, including things like --mode and config vals, are more "specific" contexts that actually describe the actual application as it should run in that context. So to me the config vals are "more specific" (even though I'll admit that even I find it instinctively a bit weird).
Closing in favour of #761 warnings.