containers / podman-compose

a script to run docker-compose.yml using podman
GNU General Public License v2.0
4.85k stars 463 forks source link

Required variable syntax ("${BAR:?BAR variable missing}") not resolved when not in quotation marks since v1.1.0 (in command) #939

Open rugk opened 1 month ago

rugk commented 1 month ago

Describe the bug The required variable syntax (${BAR:?BAR variable missing}) is not resolved when not in quotation marks since v1.1.0.

To Reproduce Here is an full example/MWE: https://gist.github.com/rugk/ac09b28bc9de833e772cb1509364b421 (You can just git clone the gist.)

The relevant part is:

version: "3"

services:
  example:
    image: busybox
    env_file: .foo
    # here, variable replacing does not work
    command: /app/script.sh ${BAR:?BAR variable missing}
    # This works:
    # command: /app/script.sh "${BAR:?BAR variable missing}"
    # this fails with "FOO variable missing":
    # command: /app/script.sh "${FOO:?FOO variable missing}"
    volumes:
      # :z just needed because of SELinux
      - .:/app:z

script.sh:

#!/bin/sh
# chmod +x this script, if needed

set | grep -E 'FOO|BAR'
echo FOO=$FOO and BAR=$BAR
echo CMDARGS: "$@"

(copied/adjusted from https://github.com/containers/podman-compose/issues/848, which may or may not be related)

BAR can be there or not, in any case it is not handled at all.

Expected behavior AFAIK this has worked in versions before:

AFAIK this is the correct syntax/usage for required variables.

Actual behavior It is not expanded, and just passed/treated as is.

In podman-compose-test:

$ podman-compose down&&podman-compose up
podman-compose-test_example_1
podman-compose-test_example_1
a7974b799ede9b6f4ae6f3ef28163a23bd3a4ecd72b0ca74088690d95f857c85
22728b5a7933c90293f5260549317ef083be0ef346e557f680b6338bbbe27c1f
e77f8f7dbefe1a8c78fc63f929f3dc8cb1adc201b247b029ccd0e26f641a037f
[example] | FOO='test'
[example] | FOO=test and BAR=
[example] | CMDARGS: ${BAR:?BAR variable missing}

Output

$ podman-compose version
podman-compose version 1.1.0
podman version 5.0.2

$ podman --version
podman version 5.0.2

Environment:

$ rpm -q podman                                
podman-5.0.2-1.fc40.x86_64
$ rpm -q podman-compose                     
podman-compose-1.1.0-1.fc40.noarch
$ rpm-ostree status -b 
[…]
BootedDeployment:
● fedora:fedora/40/x86_64/silverblue
                  Version: 40.20240503.0 (2024-05-03T00:40:18Z)
               BaseCommit: fdbf6ec4dd710b503bd7528bd550f57b28fe28a6c31057cd9e48b061adc8686f
             GPGSignature: Valid signature by 115DF9AEF857853EE8445D0A0727707EA15B79CC
[…]

Additional context

Workaround; As indicated, to put the variable in quotation marks, as in command: /app/script.sh "${BAR:?BAR variable missing}". Then it works, as expected.

I am unsure about https://github.com/containers/podman-compose/issues/848, as you can see it also seems to treat foo and bar differently when set, so this may be a related issue. Note how BAR is never read, although it is certainly being set.