From ac5150cd731b27ac5d23939c86ee736ce7eed304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=BC=C3=9F?= Date: Mon, 25 Aug 2025 08:49:37 +0200 Subject: [PATCH 1/2] fix: don't double join path for dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All code paths up to here already join the context path and with the check above we're sure the file exists so joining again leads to paths that don't exist Signed-off-by: Dominik Süß --- podman_compose.py | 2 +- tests/unit/test_container_to_build_args.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/podman_compose.py b/podman_compose.py index 0d0957f6..304bb5db 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -2917,7 +2917,7 @@ def cleanup_temp_dockfile() -> None: if path_exists(dockerfile): # normalize dockerfile path, as the user could have provided unpredictable file formats - dockerfile = os.path.normpath(os.path.join(ctx, dockerfile)) + dockerfile = os.path.normpath(dockerfile) build_args.extend(["-f", dockerfile]) else: if custom_dockerfile_given: diff --git a/tests/unit/test_container_to_build_args.py b/tests/unit/test_container_to_build_args.py index bc553a01..d9629709 100644 --- a/tests/unit/test_container_to_build_args.py +++ b/tests/unit/test_container_to_build_args.py @@ -352,3 +352,23 @@ def test_build_ssh_array(self): '.', ], ) + + def test_containerfile_in_context(self): + c = create_compose_mock() + + cnt = get_minimal_container() + cnt['build']['context'] = "./subdir" + args = get_minimal_args() + args = container_to_build_args(c, cnt, args, lambda path: True) + self.assertEqual( + args, + [ + '-f', + 'subdir/Containerfile', + '-t', + 'new-image', + '--no-cache', + '--pull-always', + './subdir', + ], + ) From 72d455436c11012880f31d36f3023f6b0bedecfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=BC=C3=9F?= Date: Mon, 25 Aug 2025 08:51:33 +0200 Subject: [PATCH 2/2] fix: correctly modify volumes when normalizing services in a subdir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes relative paths when using `extends` to include another service from a different directory Signed-off-by: Dominik Süß --- podman_compose.py | 22 ++++++++++++++++++++ tests/unit/test_normalize_service.py | 31 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/podman_compose.py b/podman_compose.py index 304bb5db..55c84a87 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -54,6 +54,15 @@ def is_list(list_object: Any) -> bool: ) +def is_relative_ref(path: str) -> bool: + return ( + path.startswith("./") + or path.startswith(".:") + or path.startswith("../") + or path.startswith("..:") + ) + + # identity filter def filteri(a: list[str]) -> list[str]: return list(filter(lambda i: i, a)) @@ -1810,6 +1819,19 @@ def normalize_service(service: dict[str, Any], sub_dir: str = "") -> dict[str, A for k, v in deps.items(): v.setdefault('condition', 'service_started') service["depends_on"] = deps + if "volumes" in service and sub_dir: + new_volumes = [] + for v in service["volumes"]: + if isinstance(v, str): + if is_relative_ref(v): + v = os.path.join(sub_dir, v) + elif isinstance(v, dict): + source = v["source"] + if is_relative_ref(source): + v["source"] = os.path.join(sub_dir, source) + + new_volumes.append(v) + service["volumes"] = new_volumes return service diff --git a/tests/unit/test_normalize_service.py b/tests/unit/test_normalize_service.py index b58d6067..e7089238 100644 --- a/tests/unit/test_normalize_service.py +++ b/tests/unit/test_normalize_service.py @@ -47,6 +47,37 @@ def test_simple(self, input: dict[str, Any], expected: dict[str, Any]) -> None: {"build": {"context": "./dir-1", "dockerfile": "dockerfile-1"}}, {"build": {"context": "./sub_dir/dir-1", "dockerfile": "dockerfile-1"}}, ), + ( + {"volumes": ["./nested/relative:/mnt", "../dir-in-parent:/mnt", "..:/mnt", ".:/mnt"]}, + { + "volumes": [ + "./sub_dir/./nested/relative:/mnt", + "./sub_dir/../dir-in-parent:/mnt", + "./sub_dir/..:/mnt", + "./sub_dir/.:/mnt", + ] + }, + ), + ( + { + "volumes": [ + { + "type": "bind", + "source": "./nested/relative", + "target": "/mnt", + } + ] + }, + { + "volumes": [ + { + "type": "bind", + "source": "./sub_dir/./nested/relative", + "target": "/mnt", + } + ] + }, + ), ]) def test_normalize_service_with_sub_dir( self, input: dict[str, Any], expected: dict[str, Any]