From 9e0da82726f1ac20608f8c8b01768e4f2ed7c5bd Mon Sep 17 00:00:00 2001 From: Justin Zhang Date: Sat, 10 May 2025 13:49:50 +0300 Subject: [PATCH] Change compose-up to create then start container to avoid double exec Signed-off-by: Justin Zhang --- newsfragments/1176.bugfix | 1 + podman_compose.py | 11 ++++------- .../filesystem/test_podman_compose_filesystem.py | 3 +-- .../integration/ulimit/test_podman_compose_ulimit.py | 9 ++------- 4 files changed, 8 insertions(+), 16 deletions(-) create mode 100644 newsfragments/1176.bugfix diff --git a/newsfragments/1176.bugfix b/newsfragments/1176.bugfix new file mode 100644 index 0000000..ec861da --- /dev/null +++ b/newsfragments/1176.bugfix @@ -0,0 +1 @@ +- Fixed issue where short-lived containers would execute twice when using the up command in detached mode (#1176) diff --git a/podman_compose.py b/podman_compose.py index 4808dd9..69613e3 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -2898,21 +2898,18 @@ async def compose_up(compose: PodmanCompose, args): log.info("recreating: done\n\n") # args.no_recreate disables check for changes (which is not implemented) - podman_command = "run" if args.detach and not args.no_start else "create" - await create_pods(compose, args) for cnt in compose.containers: if cnt["_service"] in excluded: log.debug("** skipping: %s", cnt["name"]) continue - podman_args = await container_to_args( - compose, cnt, detached=args.detach, no_deps=args.no_deps - ) - subproc = await compose.podman.run([], podman_command, podman_args) - if podman_command == "run" and subproc is not None: + podman_args = await container_to_args(compose, cnt, detached=False, no_deps=args.no_deps) + subproc = await compose.podman.run([], "create", podman_args) + if not args.no_start and args.detach and subproc is not None: await run_container( compose, cnt["name"], deps_from_container(args, cnt), ([], "start", [cnt["name"]]) ) + if args.no_start or args.detach or args.dry_run: return # TODO: handle already existing diff --git a/tests/integration/filesystem/test_podman_compose_filesystem.py b/tests/integration/filesystem/test_podman_compose_filesystem.py index d78e369..9539e6e 100644 --- a/tests/integration/filesystem/test_podman_compose_filesystem.py +++ b/tests/integration/filesystem/test_podman_compose_filesystem.py @@ -35,8 +35,7 @@ class TestFilesystem(unittest.TestCase, RunSubprocessMixin): "container1", ]) - # BUG: figure out why cat is called twice - self.assertEqual(out, b'data_compose_symlink\ndata_compose_symlink\n') + self.assertEqual(out, b'data_compose_symlink\n') finally: out, _ = self.run_subprocess_assert_returncode([ diff --git a/tests/integration/ulimit/test_podman_compose_ulimit.py b/tests/integration/ulimit/test_podman_compose_ulimit.py index 283cd27..4d2ef28 100644 --- a/tests/integration/ulimit/test_podman_compose_ulimit.py +++ b/tests/integration/ulimit/test_podman_compose_ulimit.py @@ -34,14 +34,11 @@ class TestUlimit(unittest.TestCase, RunSubprocessMixin): for el in split_output if not el.startswith(b"soft process") and not el.startswith(b"hard process") ] - # BUG: figure out why echo is called twice self.assertEqual( output_part, [ b"soft nofile limit 1001", b"hard nofile limit 1001", - b"soft nofile limit 1001", - b"hard nofile limit 1001", ], ) @@ -53,8 +50,7 @@ class TestUlimit(unittest.TestCase, RunSubprocessMixin): self.assertEqual( out, b"soft process limit 1002\nhard process limit 2002\nsoft nofile limit 1002\n" - b"hard nofile limit 1002\nsoft process limit 1002\nhard process limit 2002\n" - b"soft nofile limit 1002\nhard nofile limit 1002\n", + b"hard nofile limit 1002\n", ) out, _ = self.run_subprocess_assert_returncode([ @@ -65,8 +61,7 @@ class TestUlimit(unittest.TestCase, RunSubprocessMixin): self.assertEqual( out, b"soft process limit 1003\nhard process limit 2003\nsoft nofile limit 1003\n" - b"hard nofile limit 1003\nsoft process limit 1003\nhard process limit 2003\n" - b"soft nofile limit 1003\nhard nofile limit 1003\n", + b"hard nofile limit 1003\n", ) finally: self.run_subprocess_assert_returncode([