Reproducer for Missing support for variable interpolation in .env files #718:
$ cat c.yaml
services:
test:
image: busybox
command: ["/bin/busybox", "sh", "-c", "env | grep -e EXAMPLE -e AWS"]
environment:
EXAMPLE_1: "$A"
EXAMPLE_2: ${B:-preset}
EXAMPLE_3: ${EXAMPLE_3:-preset}
EXAMPLE_4: ${EXAMPLE_5:-preset}
$ A=one B=two podman-compose -f c.yaml run test
EXAMPLE_1=one
EXAMPLE_2=two
EXAMPLE_3=${EXAMPLE_3:-preset}
EXAMPLE_4=preset
$ A=one B=two EXAMPLE_5=foo podman-compose -f c.yaml run test
EXAMPLE_1=one
EXAMPLE_2=two
EXAMPLE_3=${EXAMPLE_3:-preset}
EXAMPLE_4=foo
So, in short: EXAMPLE_3=${EXAMPLE_3:-...}
does not work, meaning we cannot recursively assing variables here. A more real-world example would be:
[...]
environment:
AWS_PROFILE: ${AWS_PROFILE:-some-profile-name}
$ podman-compose -f c.yaml run test
AWS_PROFILE=${AWS_PROFILE:-some-profile-name}
$ AWS_PROFILE=foo podman-compose -f c.yaml run test
AWS_PROFILE=foo
The workaround would be of course to use a different variable name, e.g.:
[...]
environment:
AWS_PROFILE: ${awsprofile:-some-profile-name}
$ podman-compose -f c.yaml run test
AWS_PROFILE=some-profile-name
$ awsprofile=foo podman-compose -f c.yaml run test
AWS_PROFILE=foo