Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rugk opened this issue May 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@rugk
Copy link

rugk commented May 13, 2024

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 #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:

  • when BAR is not set, show an error BAR variable missing
  • when BAR is set, expand it with it's value

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

@rugk rugk added the bug Something isn't working label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant