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

Failure to expand environment variables properly cross-platform. #1134

Open
Thvyze opened this issue Feb 7, 2025 · 3 comments
Open

Failure to expand environment variables properly cross-platform. #1134

Thvyze opened this issue Feb 7, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@Thvyze
Copy link

Thvyze commented Feb 7, 2025

v1.3.0 broke my dev setup on Windows. Bash-style environment variables under environment section in docker-compose.yml are passed through unresolved to podman (run) command-line.

NOT a bug in Podman.

Steps to reproduce the behavior:

  1. Use an image such as: php:8.4-apache
  2. In the environment section of the docker-compose.yml, define variable(s) such as:

APACHE_LOG_DIR: "${APACHE_LOG_DIR:-/var/www/app/storage/logs/apache2}"
PHP_MEMORY_LIMIT: "${PHP_MEMORY_LIMIT:-128M}"

  1. Try a command such as: podman-compose.exe up --build

Expected behavior
Environment variable values such as above should be passed through as already resolved (evaluated).

Actual behavior
Environment variable values are passed through raw (unresolved).

Output

$ podman-compose version
podman-compose version 1.3.0
podman version 5.3.2

Environment:

  • OS: Windows 11 Pro 24H2 26100.2894
  • podman version: 5.3.2 remote
  • podman compose version: pip: podman_compose-1.3.0.dist

Additional context

This issue was did not manifest while using previous version from pip, probably because environment variables were not passed through at all ??

Solution/Workaround:


# LocalCache\local-packages\Python313\site-packages\podman_compose.py

from expandvars import expandvars

container_to_args():
    env = [expandvars(v) for v in env]

Discarded attempted fix: env = {k: expandvars(v) for k, v in env.items()}
@Thvyze Thvyze added the bug Something isn't working label Feb 7, 2025
@jorgehermo9
Copy link

jorgehermo9 commented Feb 7, 2025

I have found the same issue.

to reproduce, the following compose file:

services:
  postgres:
    image: docker.io/postgres:${CONFIG_VERSION}
    command: /postgres-init.sh
    volumes:
    - socket:/var/run/postgresql
    - ../../../tests/data/postgres-init.sh:/postgres-init.sh:ro
    - ../../../tests/data/ca:/certs:ro
    environment:
    - POSTGRES_USER=vector
    - POSTGRES_PASSWORD=vector
volumes:
  socket: {}
networks:
  default:
    external: 'true'
    name: vector-integration-tests-postgres

and execute export CONFIG_VERSION=13.1.

podman compose up fails while docker compose up runs successfully. The env vars are not interpolated into the compose file

The following error is shown:

Traceback (most recent call last):
  File "/usr/bin/podman-compose", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/usr/lib/python3.13/site-packages/podman_compose.py", line 3711, in main
    asyncio.run(async_main())
    ~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 720, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/podman_compose.py", line 3707, in async_main
    await podman_compose.run()
  File "/usr/lib/python3.13/site-packages/podman_compose.py", line 1861, in run
    retcode = await cmd(self, args)
              ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/podman_compose.py", line 2702, in compose_up
    podman_args = await container_to_args(compose, cnt, detached=args.detach)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/podman_compose.py", line 1099, in container_to_args
    podman_args.extend(get_net_args(compose, cnt))
                       ~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/podman_compose.py", line 934, in get_net_args
    return get_net_args_from_networks(compose, cnt)
  File "/usr/lib/python3.13/site-packages/podman_compose.py", line 983, in get_net_args_from_networks
    net_name = ext_desc.get("name") or net_desc.get("name") or default_net_name
               ^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get

I think the error message could be improved, as it did not say anything about unresolved environment vars (I found #1067 before reaching this issue)

@d-air1
Copy link

d-air1 commented Feb 19, 2025

Also present on Arch, downgrading to 1.2.0 for now solves the issue. Error message could definitely be improved. It was certainly a surprise that a previously working docker-compose.yml stopped working. The only reason I didn't notice earlier is because I hadn't needed to update my container images in a while.

@d-air1
Copy link

d-air1 commented Mar 10, 2025

ping

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