From f3e9a96c96b87c9f0c66a6b38fd669f65d4f07e5 Mon Sep 17 00:00:00 2001
From: Hedayat Vatankhah <hedayat.fwd@gmail.com>
Date: Tue, 9 Apr 2024 01:13:33 +0330
Subject: [PATCH 1/3] Fixes #908: Add support for multi-line environment files

Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
---
 podman_compose.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/podman_compose.py b/podman_compose.py
index c9b7fd6a..27a9a2d8 100755
--- a/podman_compose.py
+++ b/podman_compose.py
@@ -1072,7 +1072,11 @@ async def container_to_args(compose, cnt, detached=True):
             if not required:
                 continue
             raise ValueError("Env file at {} does not exist".format(i))
-        podman_args.extend(["--env-file", i])
+        dotenv_dict = {}
+        dotenv_dict = dotenv_to_dict(i)
+        env = norm_as_list(dotenv_dict)
+        for e in env:
+            podman_args.extend(["-e", e])
     env = norm_as_list(cnt.get("environment", {}))
     for e in env:
         podman_args.extend(["-e", e])

From 040b73adabf9ae2997f4447dbcc5cb6958a07aa2 Mon Sep 17 00:00:00 2001
From: Monika Kairaityte <monika@kibit.lt>
Date: Sat, 25 May 2024 00:12:34 +0300
Subject: [PATCH 2/3] pytests: Add tests for several multi-line environment
 files

Signed-off-by: Monika Kairaityte <monika@kibit.lt>
---
 pytests/test_container_to_args.py            | 56 +++++++++++++++++---
 tests/env-file-tests/env-files/project-1.env |  2 +
 tests/env-file-tests/env-files/project-2.env |  2 +
 3 files changed, 53 insertions(+), 7 deletions(-)
 create mode 100644 tests/env-file-tests/env-files/project-2.env

diff --git a/pytests/test_container_to_args.py b/pytests/test_container_to_args.py
index 150dbfac..f584f72e 100644
--- a/pytests/test_container_to_args.py
+++ b/pytests/test_container_to_args.py
@@ -251,8 +251,12 @@ async def test_env_file_str(self):
             [
                 "--name=project_name_service_name1",
                 "-d",
-                "--env-file",
-                env_file,
+                "-e",
+                "ZZVAR1=podman-rocks-123",
+                "-e",
+                "ZZVAR2=podman-rocks-124",
+                "-e",
+                "ZZVAR3=podman-rocks-125",
                 "--network=bridge",
                 "--network-alias=service_name",
                 "busybox",
@@ -268,7 +272,7 @@ async def test_env_file_str_not_exists(self):
         with self.assertRaises(ValueError):
             await container_to_args(c, cnt)
 
-    async def test_env_file_str_arr(self):
+    async def test_env_file_str_array_one_path(self):
         c = create_compose_mock()
 
         cnt = get_minimal_container()
@@ -281,8 +285,42 @@ async def test_env_file_str_arr(self):
             [
                 "--name=project_name_service_name1",
                 "-d",
-                "--env-file",
-                env_file,
+                "-e",
+                "ZZVAR1=podman-rocks-123",
+                "-e",
+                "ZZVAR2=podman-rocks-124",
+                "-e",
+                "ZZVAR3=podman-rocks-125",
+                "--network=bridge",
+                "--network-alias=service_name",
+                "busybox",
+            ],
+        )
+
+    async def test_env_file_str_array_two_paths(self):
+        c = create_compose_mock()
+
+        cnt = get_minimal_container()
+        env_file = path.realpath('tests/env-file-tests/env-files/project-1.env')
+        env_file_2 = path.realpath('tests/env-file-tests/env-files/project-2.env')
+        cnt['env_file'] = [env_file, env_file_2]
+
+        args = await container_to_args(c, cnt)
+        self.assertEqual(
+            args,
+            [
+                "--name=project_name_service_name1",
+                "-d",
+                "-e",
+                "ZZVAR1=podman-rocks-123",
+                "-e",
+                "ZZVAR2=podman-rocks-124",
+                "-e",
+                "ZZVAR3=podman-rocks-125",
+                "-e",
+                "ZZVAR1=podman-rocks-223",
+                "-e",
+                "ZZVAR2=podman-rocks-224",
                 "--network=bridge",
                 "--network-alias=service_name",
                 "busybox",
@@ -302,8 +340,12 @@ async def test_env_file_obj_required(self):
             [
                 "--name=project_name_service_name1",
                 "-d",
-                "--env-file",
-                env_file,
+                "-e",
+                "ZZVAR1=podman-rocks-123",
+                "-e",
+                "ZZVAR2=podman-rocks-124",
+                "-e",
+                "ZZVAR3=podman-rocks-125",
                 "--network=bridge",
                 "--network-alias=service_name",
                 "busybox",
diff --git a/tests/env-file-tests/env-files/project-1.env b/tests/env-file-tests/env-files/project-1.env
index f49c6217..617c3d5b 100644
--- a/tests/env-file-tests/env-files/project-1.env
+++ b/tests/env-file-tests/env-files/project-1.env
@@ -1 +1,3 @@
 ZZVAR1=podman-rocks-123
+ZZVAR2=podman-rocks-124
+ZZVAR3=podman-rocks-125
diff --git a/tests/env-file-tests/env-files/project-2.env b/tests/env-file-tests/env-files/project-2.env
new file mode 100644
index 00000000..236c5ffe
--- /dev/null
+++ b/tests/env-file-tests/env-files/project-2.env
@@ -0,0 +1,2 @@
+ZZVAR1=podman-rocks-223
+ZZVAR2=podman-rocks-224

From 2e8ed2f924399342539a68365422341cfb2bce55 Mon Sep 17 00:00:00 2001
From: Monika Kairaityte <monika@kibit.lt>
Date: Sun, 26 May 2024 21:07:18 +0300
Subject: [PATCH 3/3] pytests: Add test for object required but path non
 existent

Signed-off-by: Monika Kairaityte <monika@kibit.lt>
---
 pytests/test_container_to_args.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/pytests/test_container_to_args.py b/pytests/test_container_to_args.py
index f584f72e..9346b9b9 100644
--- a/pytests/test_container_to_args.py
+++ b/pytests/test_container_to_args.py
@@ -352,6 +352,15 @@ async def test_env_file_obj_required(self):
             ],
         )
 
+    async def test_env_file_obj_required_non_existent_path(self):
+        c = create_compose_mock()
+
+        cnt = get_minimal_container()
+        cnt['env_file'] = {'path': 'not-exists', 'required': True}
+
+        with self.assertRaises(ValueError):
+            await container_to_args(c, cnt)
+
     async def test_env_file_obj_optional(self):
         c = create_compose_mock()