Skip to content

Instantly share code, notes, and snippets.

@ckujau
Last active January 14, 2025 18:05
Show Gist options
  • Save ckujau/701b6d15ef333461925984662319be43 to your computer and use it in GitHub Desktop.
Save ckujau/701b6d15ef333461925984662319be43 to your computer and use it in GitHub Desktop.
reproducer for podman-compose/issues/718

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment