From bde25e1f427eb0c39f31581b0618f285e780d568 Mon Sep 17 00:00:00 2001 From: GerkinDev Date: Tue, 20 Jan 2026 10:05:17 +0100 Subject: [PATCH 1/5] feat: allow multiple `--env-file` flags Signed-off-by: GerkinDev --- podman_compose.py | 19 ++++++------ .../env_file_tests/env-files/project-2.env | 1 + .../project/container-compose.yaml | 1 + .../test_podman_compose_env_file.py | 31 +++++++++++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/podman_compose.py b/podman_compose.py index a0ea0587..48fe5fad 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -2302,15 +2302,16 @@ def _parse_compose_file(self) -> None: # env-file is relative to the CWD dotenv_dict = {} - if args.env_file: + if len(args.env_file) == 0: # Load .env from the Compose file's directory to preserve # behavior prior to 1.1.0 and to match with Docker Compose (v2). - if ".env" == args.env_file: - project_dotenv_file = os.path.realpath(os.path.join(dirname, ".env")) - if os.path.exists(project_dotenv_file): - dotenv_dict.update(dotenv_to_dict(project_dotenv_file)) - dotenv_path = os.path.realpath(args.env_file) - dotenv_dict.update(dotenv_to_dict(dotenv_path)) + project_dotenv_file = os.path.realpath(os.path.join(dirname, ".env")) + if os.path.exists(project_dotenv_file): + dotenv_dict.update(dotenv_to_dict(project_dotenv_file)) + else: + for env_file in args.env_file: + dotenv_path = os.path.realpath(env_file) + dotenv_dict.update(dotenv_to_dict(dotenv_path)) os.environ.update({ key: value # type: ignore[misc] @@ -2689,8 +2690,8 @@ def _init_global_parser(parser: argparse.ArgumentParser) -> None: "--env-file", help="Specify an alternate environment file", metavar="env_file", - type=str, - default=".env", + action="append", + default=[], ) parser.add_argument( "-f", diff --git a/tests/integration/env_file_tests/env-files/project-2.env b/tests/integration/env_file_tests/env-files/project-2.env index 236c5ffe..c564b585 100644 --- a/tests/integration/env_file_tests/env-files/project-2.env +++ b/tests/integration/env_file_tests/env-files/project-2.env @@ -1,2 +1,3 @@ ZZVAR1=podman-rocks-223 ZZVAR2=podman-rocks-224 +ZZVAR4=podman-rocks-225 diff --git a/tests/integration/env_file_tests/project/container-compose.yaml b/tests/integration/env_file_tests/project/container-compose.yaml index bd6a6bf3..6700b47f 100644 --- a/tests/integration/env_file_tests/project/container-compose.yaml +++ b/tests/integration/env_file_tests/project/container-compose.yaml @@ -7,3 +7,4 @@ services: - /tmp environment: ZZVAR1: $ZZVAR1 + ZZVAR4: $ZZVAR4 diff --git a/tests/integration/env_file_tests/test_podman_compose_env_file.py b/tests/integration/env_file_tests/test_podman_compose_env_file.py index 95038de9..98727ca2 100644 --- a/tests/integration/env_file_tests/test_podman_compose_env_file.py +++ b/tests/integration/env_file_tests/test_podman_compose_env_file.py @@ -44,6 +44,37 @@ def test_path_env_file_inline(self) -> None: "down", ]) + def test_path_env_file_inline_many(self) -> None: + # Test taking env variable value directly from env-file when its path is inline path + base_path = compose_base_path() + path_compose_file = os.path.join(base_path, "project/container-compose.yaml") + try: + self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + path_compose_file, + "--env-file", + os.path.join(base_path, "env-files/project-1.env"), + "--env-file", + os.path.join(base_path, "env-files/project-2.env"), + "up", + ]) + output, _ = self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + path_compose_file, + "logs", + ]) + # takes only value ZZVAR1 as container-compose.yaml file requires + self.assertEqual(output, b"ZZVAR1=podman-rocks-123\nZZVAR4=podman-rocks-225\n") + finally: + self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + path_compose_file, + "down", + ]) + def test_path_env_file_flat_in_compose_file(self) -> None: # Test taking env variable value from env-file/project-1.env which was declared in # compose file's env_file From 0692ee02d960b1379710934707ac1616493e2a71 Mon Sep 17 00:00:00 2001 From: GerkinDev Date: Tue, 20 Jan 2026 10:05:40 +0100 Subject: [PATCH 2/5] tests: actually check for precedence Signed-off-by: GerkinDev --- .../integration/env_file_tests/test_podman_compose_env_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/env_file_tests/test_podman_compose_env_file.py b/tests/integration/env_file_tests/test_podman_compose_env_file.py index 98727ca2..8a6bab83 100644 --- a/tests/integration/env_file_tests/test_podman_compose_env_file.py +++ b/tests/integration/env_file_tests/test_podman_compose_env_file.py @@ -66,7 +66,7 @@ def test_path_env_file_inline_many(self) -> None: "logs", ]) # takes only value ZZVAR1 as container-compose.yaml file requires - self.assertEqual(output, b"ZZVAR1=podman-rocks-123\nZZVAR4=podman-rocks-225\n") + self.assertEqual(output, b"ZZVAR1=podman-rocks-223\nZZVAR4=podman-rocks-225\n") finally: self.run_subprocess_assert_returncode([ podman_compose_path(), From 40218b2498ef4cef0da80f1fccd20a0bd3dc1fab Mon Sep 17 00:00:00 2001 From: GerkinDev Date: Tue, 20 Jan 2026 10:06:05 +0100 Subject: [PATCH 3/5] tests: fix tests Signed-off-by: GerkinDev --- tests/integration/env_file_tests/env-files/project-2.env | 1 - .../env_file_tests/project/container-compose.yaml | 2 +- .../env_file_tests/test_podman_compose_env_file.py | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/integration/env_file_tests/env-files/project-2.env b/tests/integration/env_file_tests/env-files/project-2.env index c564b585..236c5ffe 100644 --- a/tests/integration/env_file_tests/env-files/project-2.env +++ b/tests/integration/env_file_tests/env-files/project-2.env @@ -1,3 +1,2 @@ ZZVAR1=podman-rocks-223 ZZVAR2=podman-rocks-224 -ZZVAR4=podman-rocks-225 diff --git a/tests/integration/env_file_tests/project/container-compose.yaml b/tests/integration/env_file_tests/project/container-compose.yaml index 6700b47f..1f48e9a3 100644 --- a/tests/integration/env_file_tests/project/container-compose.yaml +++ b/tests/integration/env_file_tests/project/container-compose.yaml @@ -7,4 +7,4 @@ services: - /tmp environment: ZZVAR1: $ZZVAR1 - ZZVAR4: $ZZVAR4 + ZZVAR3: $ZZVAR3 diff --git a/tests/integration/env_file_tests/test_podman_compose_env_file.py b/tests/integration/env_file_tests/test_podman_compose_env_file.py index 8a6bab83..280cea35 100644 --- a/tests/integration/env_file_tests/test_podman_compose_env_file.py +++ b/tests/integration/env_file_tests/test_podman_compose_env_file.py @@ -35,7 +35,7 @@ def test_path_env_file_inline(self) -> None: "--no-color", ]) # takes only value ZZVAR1 as container-compose.yaml file requires - self.assertEqual(output, b"ZZVAR1=podman-rocks-123\n") + self.assertEqual(output, b"ZZVAR1=podman-rocks-123\nZZVAR3=podman-rocks-125\n") finally: self.run_subprocess_assert_returncode([ podman_compose_path(), @@ -66,7 +66,7 @@ def test_path_env_file_inline_many(self) -> None: "logs", ]) # takes only value ZZVAR1 as container-compose.yaml file requires - self.assertEqual(output, b"ZZVAR1=podman-rocks-223\nZZVAR4=podman-rocks-225\n") + self.assertEqual(output, b"ZZVAR1=podman-rocks-223\nZZVAR3=podman-rocks-125\n") finally: self.run_subprocess_assert_returncode([ podman_compose_path(), @@ -238,7 +238,7 @@ def test_var_value_inline_overrides_env_file_path_inline(self) -> None: "--no-color", ]) # takes only value ZZVAR1 as container-compose.yaml file requires - self.assertEqual(output, b"ZZVAR1=podman-rocks-321\n") + self.assertEqual(output, b"ZZVAR1=podman-rocks-321\nZZVAR3=podman-rocks-125\n") finally: self.run_subprocess_assert_returncode([ podman_compose_path(), From 21b7b0dfc67c9fd0e2f9716e62495d446d4f9ea7 Mon Sep 17 00:00:00 2001 From: GerkinDev Date: Tue, 20 Jan 2026 10:06:24 +0100 Subject: [PATCH 4/5] fix: test for None `env_file` Signed-off-by: GerkinDev --- podman_compose.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/podman_compose.py b/podman_compose.py index 48fe5fad..cd2f3031 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -2302,7 +2302,7 @@ def _parse_compose_file(self) -> None: # env-file is relative to the CWD dotenv_dict = {} - if len(args.env_file) == 0: + if args.env_file is None or len(args.env_file) == 0: # Load .env from the Compose file's directory to preserve # behavior prior to 1.1.0 and to match with Docker Compose (v2). project_dotenv_file = os.path.realpath(os.path.join(dirname, ".env")) From e53960ef49a339ca0f785b5dd061cf8a620d3742 Mon Sep 17 00:00:00 2001 From: GerkinDev Date: Tue, 20 Jan 2026 10:06:36 +0100 Subject: [PATCH 5/5] test: fix Signed-off-by: GerkinDev --- .../integration/env_file_tests/test_podman_compose_env_file.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/env_file_tests/test_podman_compose_env_file.py b/tests/integration/env_file_tests/test_podman_compose_env_file.py index 280cea35..542f2f0e 100644 --- a/tests/integration/env_file_tests/test_podman_compose_env_file.py +++ b/tests/integration/env_file_tests/test_podman_compose_env_file.py @@ -64,6 +64,8 @@ def test_path_env_file_inline_many(self) -> None: "-f", path_compose_file, "logs", + "--no-log-prefix", + "--no-color", ]) # takes only value ZZVAR1 as container-compose.yaml file requires self.assertEqual(output, b"ZZVAR1=podman-rocks-223\nZZVAR3=podman-rocks-125\n")