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

Variable interpolation with missing value not handled properly #895

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

Comments

@Victoremepunto
Copy link

Describe the bug

The variable interpolation does not work properly and sends a stack trace when parsing a template that has a variable using the construction: ${VARIABLE:?err}

The variable interpolation as described in and also here confirms this should be a valid construction, and this does in fact work in the latest version of docker-compose but it sends a stack trace when tested on podman-compose

please try to reproduce the bug in latest devel branch: This has been tested in both the latest stable release and in the current devel version (at the time, devel version is podman-compose version 1.0.7)

To Reproduce
Steps to reproduce the behavior:

  1. have a compose template that uses interpolation with missing values. I used:
#compose.yml 
services:
  foo:
    image: ${FOO:?}
  1. run a command that needs to interact with the template like: podman-compose -f compose.yml ps or simply podman-compose ps if your template is named "compose.yml"

please use minimal reproducible example for example give me a small busybox-based compose yaml

Expected behavior
docker-compose handles the error and displays a message appropriately, podman-compose should behave similarly:

$ docker-compose ps
ERROR: Missing mandatory value for "image" option interpolating ${FOO:?} in service "foo": FOO
$ echo $?
1

Actual behavior
podman-compose yields an exception and a stack trace

Output

$ podman-compose version
podman-compose version 1.0.7
podman version 4.9.3

$ podman-compose -f compose.yml ps
Traceback (most recent call last):
  File "/tmp/foo/.venv/bin/podman-compose", line 8, in <module>
    sys.exit(main())
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 3224, in main
    asyncio.run(async_main())
  File "/usr/lib64/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib64/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 3220, in async_main
    await podman_compose.run()
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 1548, in run
    self._parse_compose_file()
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 1634, in _parse_compose_file
    content = rec_subs(content, self.environ)
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 266, in rec_subs
    value = {k: rec_subs(v, subs_dict) for k, v in value.items()}
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 266, in <dictcomp>
    value = {k: rec_subs(v, subs_dict) for k, v in value.items()}
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 266, in rec_subs
    value = {k: rec_subs(v, subs_dict) for k, v in value.items()}
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 266, in <dictcomp>
    value = {k: rec_subs(v, subs_dict) for k, v in value.items()}
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 266, in rec_subs
    value = {k: rec_subs(v, subs_dict) for k, v in value.items()}
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 266, in <dictcomp>
    value = {k: rec_subs(v, subs_dict) for k, v in value.items()}
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 282, in rec_subs
    value = var_re.sub(convert, value)
  File "/tmp/foo/.venv/lib64/python3.9/site-packages/podman_compose.py", line 279, in convert
    raise RuntimeError(m.group("err"))
RuntimeError

Environment:

  • OS: Linux (Fedora 39)
  • podman version: 4.9.3
  • podman compose version: d704622

Additional context

N/A

@Victoremepunto Victoremepunto added the bug Something isn't working label Mar 13, 2024
@Victoremepunto Victoremepunto changed the title comp Variable interpolation with missing value not handled properly Mar 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