From 256b51c8ee049f18ebdbf906d14fb9a14113b4e7 Mon Sep 17 00:00:00 2001 From: Monika Kairaityte Date: Wed, 2 Jul 2025 19:59:10 +0300 Subject: [PATCH] Properly surface errors from `push` command Failure exit code for `push` command is not currently forwarded as exit code for podman-compose. With this PR, podman-compose stops pushing when the underlying podman command fails and forwards its exit code. Signed-off-by: Monika Kairaityte --- ...rwarding-exit-code-for-push-command.bugfix | 1 + podman_compose.py | 8 +++++-- .../test_podman_compose_build_fail_multi.py | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 newsfragments/fix-forwarding-exit-code-for-push-command.bugfix diff --git a/newsfragments/fix-forwarding-exit-code-for-push-command.bugfix b/newsfragments/fix-forwarding-exit-code-for-push-command.bugfix new file mode 100644 index 0000000..0972449 --- /dev/null +++ b/newsfragments/fix-forwarding-exit-code-for-push-command.bugfix @@ -0,0 +1 @@ +Implemented forwarding failure exit code from `push` command. diff --git a/podman_compose.py b/podman_compose.py index 61c0a55..2b33248 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -2799,14 +2799,18 @@ async def compose_pull(compose: PodmanCompose, args: argparse.Namespace) -> None @cmd_run(podman_compose, "push", "push stack images") -async def compose_push(compose: PodmanCompose, args: argparse.Namespace) -> None: +async def compose_push(compose: PodmanCompose, args: argparse.Namespace) -> int | None: services = set(args.services) + status = 0 for cnt in compose.containers: if "build" not in cnt: continue if services and cnt["_service"] not in services: continue - await compose.podman.run([], "push", [cnt["image"]]) + s = await compose.podman.run([], "push", [cnt["image"]]) + if s is not None and s != 0: + status = s + return status def is_context_git_url(path: str) -> bool: diff --git a/tests/integration/build_fail_multi/test_podman_compose_build_fail_multi.py b/tests/integration/build_fail_multi/test_podman_compose_build_fail_multi.py index 167becb..f1afad8 100644 --- a/tests/integration/build_fail_multi/test_podman_compose_build_fail_multi.py +++ b/tests/integration/build_fail_multi/test_podman_compose_build_fail_multi.py @@ -29,3 +29,25 @@ class TestComposeBuildFailMulti(unittest.TestCase, RunSubprocessMixin): ) self.assertIn("RUN false", str(output)) self.assertIn("while running runtime: exit status 1", str(error)) + + def test_push_command_fail(self) -> None: + # test that push command is able to return other than "0" return code + # "push" command fails due to several steps missing before running it (logging, tagging) + try: + output, error = self.run_subprocess_assert_returncode( + [ + podman_compose_path(), + "-f", + compose_yaml_path(), + "push", + "good", + ], + expected_returncode=125, + ) + finally: + self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + compose_yaml_path(), + "down", + ])