Implement short syntax for env variables in compose.yml "environment:"

This commit allows compose file to directly use environment variable
values in "environment:" section when variables were set in `.env` file.
This functionality was missing, as docker-compose supports both: short
and variable interpolation syntax forms:
environment:
	- FOO
and
environment:
	- FOO=${FOO}
Relevant docker-compose documentation:
https://docs.docker.com/compose/how-tos/environment-variables/set-environment-variables/
podman-compose is more compatible with docker-compose after this change.

Signed-off-by: Monika Kairaityte <monika@kibit.lt>
This commit is contained in:
Monika Kairaityte
2025-06-25 14:41:48 +03:00
parent 7105198ae1
commit 0cbf70a4e9
6 changed files with 90 additions and 2 deletions

View File

@@ -1159,7 +1159,14 @@ async def container_to_args(
podman_args.extend(["-e", e])
env = norm_as_list(cnt.get("environment", {}))
for e in env:
podman_args.extend(["-e", e])
# new environment variable is set
if "=" in e:
podman_args.extend(["-e", e])
else:
# environment variable already exists in environment so pass its value
if e in compose.environ.keys():
podman_args.extend(["-e", f"{e}={compose.environ[e]}"])
tmpfs_ls = cnt.get("tmpfs", [])
if isinstance(tmpfs_ls, str):
tmpfs_ls = [tmpfs_ls]