Skip to content

Commit 04196dd

Browse files
Properly surface errors from build commands
the commit 38b13a3 ("Use asyncio for subprocess calls") broke the way exit codes are reported from the podman compose build command. The tasks are awaited as they finish which means that if a later build finishes sucessfully after a failing build, it overwrites status. Previously the `parse_return_code` function would skip updating the status if the new return code was zero, but in removing it, this logic was not carried forward. Fixes: 38b13a3 ("Use asyncio for subprocess calls") Signed-off-by: charliemirabile <[email protected]>
1 parent 52e2912 commit 04196dd

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

podman_compose.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,7 @@ async def compose_build(compose, args):
26132613
status = 0
26142614
for t in asyncio.as_completed(tasks):
26152615
s = await t
2616-
if s is not None:
2616+
if s is not None and s != 0:
26172617
status = s
26182618

26192619
return status

tests/integration/build_fail_multi/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM busybox
2+
3+
RUN false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3"
2+
services:
3+
bad:
4+
build:
5+
context: bad
6+
good:
7+
build:
8+
context: good
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM busybox
2+
#ensure that this build finishes second so that it has a chance to overwrite the return code
3+
RUN sleep 0.5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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():
12+
""" "Returns the path to the compose file used for this test module"""
13+
base_path = os.path.join(test_path(), "build_fail_multi")
14+
return os.path.join(base_path, "docker-compose.yml")
15+
16+
17+
class TestComposeBuildFailMulti(unittest.TestCase, RunSubprocessMixin):
18+
def test_build_fail_multi(self):
19+
output, error = self.run_subprocess_assert_returncode(
20+
[
21+
podman_compose_path(),
22+
"-f",
23+
compose_yaml_path(),
24+
"build",
25+
"--no-cache", # prevent the successful build from being cached to ensure it runs long enough
26+
],
27+
expected_returncode=1,
28+
)
29+
self.assertIn("RUN false", str(output))
30+
self.assertIn("while running runtime: exit status 1", str(error))

0 commit comments

Comments
 (0)