Skip to content

Commit 406596e

Browse files
authored
Merge pull request #1259 from mokibit/push-non-zero-exit-code
Properly surface errors from `push` command
2 parents 2ed50b9 + b3fd550 commit 406596e

File tree

8 files changed

+83
-33
lines changed

8 files changed

+83
-33
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: 0 additions & 31 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
import os
4+
import unittest
5+
6+
from tests.integration.test_utils import RunSubprocessMixin
7+
from tests.integration.test_utils import podman_compose_path
8+
from tests.integration.test_utils import test_path
9+
10+
11+
def compose_yaml_path() -> str:
12+
""" "Returns the path to the compose file used for this test module"""
13+
base_path = os.path.join(test_path(), "commands_fail_exit_code")
14+
return os.path.join(base_path, "docker-compose.yml")
15+
16+
17+
class TestComposeCommandsFailExitCodes(unittest.TestCase, RunSubprocessMixin):
18+
def test_build_command_fail(self) -> None:
19+
output, error = self.run_subprocess_assert_returncode(
20+
[
21+
podman_compose_path(),
22+
"-f",
23+
compose_yaml_path(),
24+
"build",
25+
# prevent the successful build from being cached to ensure it runs long enough
26+
"--no-cache",
27+
],
28+
expected_returncode=1,
29+
)
30+
self.assertIn("RUN false", str(output))
31+
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+
])
54+
55+
def test_run_command_fail(self) -> None:
56+
# test that run command is able to return other than "0" return code
57+
try:
58+
output, error = self.run_subprocess_assert_returncode(
59+
[
60+
podman_compose_path(),
61+
"-f",
62+
compose_yaml_path(),
63+
"run",
64+
"bad",
65+
],
66+
expected_returncode=125,
67+
)
68+
self.assertIn("RUN false", str(output))
69+
self.assertIn("while running runtime: exit status 1", str(error))
70+
finally:
71+
self.run_subprocess_assert_returncode([
72+
podman_compose_path(),
73+
"-f",
74+
compose_yaml_path(),
75+
"down",
76+
])

0 commit comments

Comments
 (0)