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

Environment Variable Default Not Working Correctly v1.3.0 #1105

Closed
damaestro opened this issue Jan 12, 2025 · 3 comments
Closed

Environment Variable Default Not Working Correctly v1.3.0 #1105

damaestro opened this issue Jan 12, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@damaestro
Copy link

damaestro commented Jan 12, 2025

Describe the bug

When using the shell default value syntax, the default is not always interpreted. Oddly, it does work if the source variable name doesn't match the destination variable name.

This works as expected with docker compose.

To Reproduce
Steps to reproduce the behavior:

Dockerfile:

FROM docker.io/library/busybox:latest
CMD ["/bin/sh"]

docker-compose.yaml:

version: '3'
services:
  test:
    build: .
    environment:
      TEST_EXPECT_WORKING: ${TEST_EXPECT_WORKING:-working}
      TEST_EXPECT_EMPTY: ${DOES_NOT_EXIST}
      TEST_EXPECT_ONE: 1
      TEST_ODDLY_WORKING: ${HOW_STRANGE:-working}
    command: ["/bin/sh", "-c", "printenv|grep TEST"]

Expected behavior

TEST_EXPECT_WORKING: ${TEST_EXPECT_WORKING:-working} is a common pattern for allowing user-set environment variables to be passed through, while also setting a default. This is working fine with docker compose.

Actual behavior

TEST_EXPECT_WORKING is set to ${TEST_EXPECT_WORKING:-working} not working or previously set $TEST_EXPECT_WORKING.

Output

Versions:

$ podman-compose version
podman-compose version 1.3.0
podman version 5.3.1

Defaults expected:

$ podman compose run test
TEST_EXPECT_EMPTY=
TEST_ODDLY_WORKING=working
TEST_EXPECT_ONE=1
TEST_EXPECT_WORKING=${TEST_EXPECT_WORKING:-working}

User-set expected:

$ TEST_EXPECT_WORKING='cli-working' podman compose run test
TEST_EXPECT_EMPTY=
TEST_ODDLY_WORKING=working
TEST_EXPECT_ONE=1
TEST_EXPECT_WORKING=cli-working

Environment:

  • OS: Linux
  • podman version: 5.3.1
  • podman compose version: 1.3.0

Additional context

This might have been working previously as I'm just now noticing it.

@damaestro damaestro added the bug Something isn't working label Jan 12, 2025
@damaestro
Copy link
Author

I've confirmed this is a bug with podman-compose 1.3.0. The following is working with 1.2.0:

Versions:

$ podman-compose version
podman-compose version 1.2.0
podman version 5.3.1

Defaults expected:

$ podman compose run test
TEST_EXPECT_ONE=1
TEST_EXPECT_WORKING=working
TEST_ODDLY_WORKING=working
TEST_EXPECT_EMPTY=

User-set expected:

$ TEST_EXPECT_WORKING='cli-working' podman compose run test
TEST_EXPECT_ONE=1
TEST_EXPECT_WORKING=cli-working
TEST_ODDLY_WORKING=working
TEST_EXPECT_EMPTY=

@damaestro damaestro changed the title Environment Variable Default Not Working Correctly Environment Variable Default Not Working Correctly v1.3.0 Jan 12, 2025
@indrat
Copy link
Contributor

indrat commented Jan 15, 2025

Also just ran in to this. The problematic line appears to be: https://github.com/containers/podman-compose/blob/main/podman_compose.py#L273

Removing the update to the subs_dict before the svc_envs are substituted appears to fix this issue for me.

@p12tic
Copy link
Collaborator

p12tic commented Jan 16, 2025

Fixed in #1110.

@p12tic p12tic closed this as completed Jan 16, 2025
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

3 participants