Skip to content

Commit

Permalink
Merge pull request #1110 from indrat/1105-service-env-vars
Browse files Browse the repository at this point in the history
expand service environment_variables before adding to subs_dict
  • Loading branch information
p12tic authored Jan 16, 2025
2 parents a177603 + 2aa042b commit 0f2c717
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ def rec_subs(value, subs_dict):
svc_envs = {k: v for k, v in value['environment'].items() if k not in subs_dict}
# we need to add `svc_envs` to the `subs_dict` so that it can evaluate the
# service environment that reference to another service environment.
subs_dict.update(svc_envs)
svc_envs = rec_subs(svc_envs, subs_dict)
subs_dict.update(svc_envs)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_podman_compose_env_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def test_taking_env_variables_from_env_files_from_different_directories(self):
[
'ZZVAR1=This value is loaded but should be overwritten\r',
'ZZVAR2=This value is loaded from .env in project/ directory\r',
'ZZVAR3=$ZZVAR3\r',
'ZZVAR3=\r',
'',
],
)
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_rec_subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ class TestRecSubs(unittest.TestCase):
{"environment": {"non_var": "$$v1", "vx": "$non_var"}, "image": "abc:$non_var"},
{"environment": {"non_var": "$v1", "vx": "$v1"}, "image": "abc:$v1"},
),
(
"service environment with unpopulated ${VARIABLE:-default} format",
{"environment": {"v100": "${v100:-low priority}", "actual-v100": "$v100"}},
{"environment": {"v100": "low priority", "actual-v100": "low priority"}},
),
(
"service environment with populated ${VARIABLE:-default} format",
{"environment": {"v1": "${v1:-low priority}", "actual-v1": "$v1"}},
{"environment": {"v1": "high priority", "actual-v1": "high priority"}},
),
# list
(
"Values in list are substituted",
Expand Down

0 comments on commit 0f2c717

Please sign in to comment.