Change compose-up to create then start container to avoid double exec

Signed-off-by: Justin Zhang <schnell18@gmail.com>
This commit is contained in:
Justin Zhang 2025-05-10 13:49:50 +03:00 committed by Povilas Kanapickas
parent 8638eb9b6d
commit 9e0da82726
4 changed files with 8 additions and 16 deletions

View File

@ -0,0 +1 @@
- Fixed issue where short-lived containers would execute twice when using the up command in detached mode (#1176)

View File

@ -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

View File

@ -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([

View File

@ -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([