defang icon indicating copy to clipboard operation
defang copied to clipboard

Proposal: flag to expose OS env to compose loader

Open lionello opened this issue 1 year ago • 1 comments

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.

lionello avatar Sep 14 '24 19:09 lionello

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).

raphaeltm avatar Oct 03 '24 23:10 raphaeltm

Closing in favour of #761 warnings.

lionello avatar Oct 22 '24 17:10 lionello