Skip to content

Commit c096bc2

Browse files
committed
fix: correctly modify volumes when normalizing services in a subdir
This fixes relative paths when using `extends` to include another service from a different directory Signed-off-by: Dominik Süß <dominik@suess.wtf>
1 parent 0df9bf4 commit c096bc2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

podman_compose.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,19 @@ def normalize_service(service: dict[str, Any], sub_dir: str = "") -> dict[str, A
18101810
for k, v in deps.items():
18111811
v.setdefault('condition', 'service_started')
18121812
service["depends_on"] = deps
1813+
if "volumes" in service and sub_dir:
1814+
new_volumes = []
1815+
for v in service["volumes"]:
1816+
if isinstance(v, str):
1817+
if is_relative_ref(v):
1818+
v = os.path.join(sub_dir,v)
1819+
elif isinstance(v, dict):
1820+
source = v["source"]
1821+
if is_relative_ref(source):
1822+
v["source"] = (os.path.join(sub_dir,source))
1823+
1824+
new_volumes.append(v)
1825+
service["volumes"] = new_volumes
18131826
return service
18141827

18151828

tests/unit/test_normalize_service.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ def test_simple(self, input: dict[str, Any], expected: dict[str, Any]) -> None:
4747
{"build": {"context": "./dir-1", "dockerfile": "dockerfile-1"}},
4848
{"build": {"context": "./sub_dir/dir-1", "dockerfile": "dockerfile-1"}},
4949
),
50+
(
51+
{"volumes": ["./nested/relative:/mnt","../dir-in-parent:/mnt","..:/mnt",".:/mnt"]},
52+
{"volumes": ["./sub_dir/./nested/relative:/mnt","./sub_dir/../dir-in-parent:/mnt","./sub_dir/..:/mnt","./sub_dir/.:/mnt"]},
53+
),
54+
(
55+
{
56+
"volumes": [
57+
{
58+
"type": "bind",
59+
"source": "./nested/relative",
60+
"target": "/mnt",
61+
}
62+
]
63+
},
64+
{
65+
"volumes": [
66+
{
67+
"type": "bind",
68+
"source": "./sub_dir/./nested/relative",
69+
"target": "/mnt",
70+
}
71+
]
72+
},
73+
),
5074
])
5175
def test_normalize_service_with_sub_dir(
5276
self, input: dict[str, Any], expected: dict[str, Any]

0 commit comments

Comments
 (0)