Merge aa998cd26673ea899a569243a4c893f29a74e4e6 into 342a39dcfe6944932561bf12150deeb687fb6c52

This commit is contained in:
Elsa Granger 2025-04-14 18:06:04 +03:00 committed by GitHub
commit 7cb30b9243
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 13 deletions

View File

@ -2759,11 +2759,15 @@ def deps_from_container(args, cnt):
@cmd_run(podman_compose, "up", "Create and start the entire stack or some of its services")
async def compose_up(compose: PodmanCompose, args):
excluded = get_excluded(compose, args)
if not args.no_build:
# `podman build` does not cache, so don't always build
build_args = argparse.Namespace(if_not_exists=(not args.build), **args.__dict__)
if await compose.commands["build"](compose, build_args) != 0:
build_exit_code = await compose.commands["build"](compose, build_args)
if build_exit_code != 0:
log.error("Build command failed")
if not args.dry_run:
return build_exit_code
hashes = (
(
@ -2793,6 +2797,7 @@ async def compose_up(compose: PodmanCompose, args):
podman_command = "run" if args.detach and not args.no_start else "create"
await create_pods(compose, args)
exit_code = 0
for cnt in compose.containers:
if cnt["_service"] in excluded:
log.debug("** skipping: %s", cnt["name"])
@ -2800,13 +2805,22 @@ async def compose_up(compose: PodmanCompose, args):
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:
await run_container(
subproc_exit_code = await compose.podman.run([], podman_command, podman_args)
if subproc_exit_code is not None and subproc_exit_code != 0:
exit_code = subproc_exit_code
if podman_command == "run" and subproc_exit_code is not None:
container_exit_code = 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
if container_exit_code is not None and container_exit_code != 0:
exit_code = container_exit_code
if args.dry_run:
return None
if args.no_start or args.detach:
return exit_code
# TODO: handle already existing
# TODO: if error creating do not enter loop
# TODO: colors if sys.stdout.isatty()

View File

@ -96,7 +96,7 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
]
try:
out, err = self.run_subprocess_assert_returncode(command_up)
out, err = self.run_subprocess_assert_returncode(command_up, 125)
self.assertEqual(b"Error: --userns and --pod cannot be set together" in err, True)
finally:
@ -221,7 +221,7 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
]
try:
out, err = self.run_subprocess_assert_returncode(command_up)
out, err = self.run_subprocess_assert_returncode(command_up, 125)
self.assertEqual(b"Error: --userns and --pod cannot be set together" in err, True)
finally:
@ -255,7 +255,7 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
]
try:
out, err = self.run_subprocess_assert_returncode(command_up)
out, err = self.run_subprocess_assert_returncode(command_up, 125)
self.assertEqual(b"Error: --userns and --pod cannot be set together" in err, True)
finally:
@ -334,7 +334,7 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
]
try:
out, err = self.run_subprocess_assert_returncode(command_up)
out, err = self.run_subprocess_assert_returncode(command_up, 125)
self.assertEqual(b"Error: --userns and --pod cannot be set together" in err, True)
finally:
@ -368,7 +368,7 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
]
try:
out, err = self.run_subprocess_assert_returncode(command_up)
out, err = self.run_subprocess_assert_returncode(command_up, 125)
self.assertEqual(b"Error: --userns and --pod cannot be set together" in err, True)
finally:
@ -402,7 +402,7 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
]
try:
out, err = self.run_subprocess_assert_returncode(command_up)
out, err = self.run_subprocess_assert_returncode(command_up, 125)
self.assertEqual(b"Error: --userns and --pod cannot be set together" in err, True)
finally:
@ -482,7 +482,7 @@ class TestPodmanComposeInPod(unittest.TestCase, RunSubprocessMixin):
]
try:
out, err = self.run_subprocess_assert_returncode(command_up)
out, err = self.run_subprocess_assert_returncode(command_up, 125)
self.assertEqual(b"Error: --userns and --pod cannot be set together" in err, True)
finally: