Skip to content

Commit 256b51c

Browse files
committed
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 <monika@kibit.lt>
1 parent 2ed50b9 commit 256b51c

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implemented forwarding failure exit code from `push` command.

podman_compose.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,14 +2799,18 @@ async def compose_pull(compose: PodmanCompose, args: argparse.Namespace) -> None
27992799

28002800

28012801
@cmd_run(podman_compose, "push", "push stack images")
2802-
async def compose_push(compose: PodmanCompose, args: argparse.Namespace) -> None:
2802+
async def compose_push(compose: PodmanCompose, args: argparse.Namespace) -> int | None:
28032803
services = set(args.services)
2804+
status = 0
28042805
for cnt in compose.containers:
28052806
if "build" not in cnt:
28062807
continue
28072808
if services and cnt["_service"] not in services:
28082809
continue
2809-
await compose.podman.run([], "push", [cnt["image"]])
2810+
s = await compose.podman.run([], "push", [cnt["image"]])
2811+
if s is not None and s != 0:
2812+
status = s
2813+
return status
28102814

28112815

28122816
def is_context_git_url(path: str) -> bool:

tests/integration/build_fail_multi/test_podman_compose_build_fail_multi.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,25 @@ def test_build_fail_multi(self):
2929
)
3030
self.assertIn("RUN false", str(output))
3131
self.assertIn("while running runtime: exit status 1", str(error))
32+
33+
def test_push_command_fail(self) -> None:
34+
# test that push command is able to return other than "0" return code
35+
# "push" command fails due to several steps missing before running it (logging, tagging)
36+
try:
37+
output, error = self.run_subprocess_assert_returncode(
38+
[
39+
podman_compose_path(),
40+
"-f",
41+
compose_yaml_path(),
42+
"push",
43+
"good",
44+
],
45+
expected_returncode=125,
46+
)
47+
finally:
48+
self.run_subprocess_assert_returncode([
49+
podman_compose_path(),
50+
"-f",
51+
compose_yaml_path(),
52+
"down",
53+
])

0 commit comments

Comments
 (0)