compose-spec icon indicating copy to clipboard operation
compose-spec copied to clipboard

Proposal: Support nested parameter expansion

Open MarilynFranklin opened this issue 4 years ago • 3 comments

What is the problem you're trying to solve

Many of our docker-compose.yml files are shared between development and CI (Buildkite). Often, we will use a default value for an environment variable in development, but we will need to use a different value in CI to override the default value. Often, we would like to use another environment variable when defining the default value, but this is not currently possible with docker-compose.

Here are a few examples:

In development, we setup dns to support human readable subdomains and would like to set the default based on a SUBDOMAIN environment variable. However, this is not setup for CI so we set API_ENDPOINT in that context.

environment:
  API_ENDPOINT: “${API_ENDPOINT:-http://${SUBDOMAIN}.localhost:3000}“

In CI, we often have to override our images since they use a different registry, name, or tag, but we would still like to use environment variables when defining default image names for development.

backend:
  image: "${BACKEND_IMAGE:-${ORGANIZATION}/backend:latest}"

Describe the solution you'd like

I would like to use nested parameter expansion in docker-config.yml files:

environment:
  API_ENDPOINT: “${API_ENDPOINT:-http://${SUBDOMAIN}.localhost:3000}“

Additional context

There have been some discussions about only supporting expansions that are defined by POSIX: https://github.com/docker/compose/issues/7102

I was able to find an example of nested command substitution in their spec which seems to show that they intended to support nested parameter expansion: https://github.com/docker/compose/pull/7795#issuecomment-699266640

MarilynFranklin avatar Nov 01 '20 20:11 MarilynFranklin

Sounds like a fitting addition to the spec 👍 I really like the suggestion to use a familiar POSIX syntax, as many Compose users know it from their host shell or writing entrypoint scripts 🙂

EricHripko avatar Nov 03 '20 09:11 EricHripko

@ndeloof @hangyan @justincormack @kohidave what do you think?

EricHripko avatar Nov 03 '20 09:11 EricHripko

+1

hangyan avatar Nov 04 '20 11:11 hangyan

This looks already supported in https://github.com/compose-spec/compose-go/pull/76 (compose v2.2.0). Looks can be closed.

ikedam avatar Aug 06 '23 09:08 ikedam