mirror of
https://github.com/containers/podman-compose.git
synced 2024-11-29 11:23:50 +01:00
Exit code managed at PodmanCompose.run()
Signed-off-by: BugFest <bugfest.dev@pm.me>
This commit is contained in:
parent
1eb166445b
commit
5a3bdbf89b
@ -1487,7 +1487,9 @@ class PodmanCompose:
|
|||||||
if compose_required:
|
if compose_required:
|
||||||
self._parse_compose_file()
|
self._parse_compose_file()
|
||||||
cmd = self.commands[cmd_name]
|
cmd = self.commands[cmd_name]
|
||||||
cmd(self, args)
|
retcode = cmd(self, args)
|
||||||
|
if isinstance(retcode, int):
|
||||||
|
sys.exit(retcode)
|
||||||
|
|
||||||
def _parse_compose_file(self):
|
def _parse_compose_file(self):
|
||||||
args = self.global_args
|
args = self.global_args
|
||||||
@ -2109,14 +2111,16 @@ def compose_build(compose, args):
|
|||||||
cnt = compose.container_by_name[container_names_by_service[service][0]]
|
cnt = compose.container_by_name[container_names_by_service[service][0]]
|
||||||
p = build_one(compose, args, cnt)
|
p = build_one(compose, args, cnt)
|
||||||
status = parse_return_code(p, status)
|
status = parse_return_code(p, status)
|
||||||
|
if status != 0:
|
||||||
|
return status
|
||||||
else:
|
else:
|
||||||
for cnt in compose.containers:
|
for cnt in compose.containers:
|
||||||
p = build_one(compose, args, cnt)
|
p = build_one(compose, args, cnt)
|
||||||
status = parse_return_code(p, status)
|
status = parse_return_code(p, status)
|
||||||
|
if status != 0:
|
||||||
|
return status
|
||||||
|
|
||||||
# When calling the "build" command, exit with the last non-Ok exit code found
|
return status
|
||||||
if args.command == "build" or status != 0:
|
|
||||||
sys.exit(status)
|
|
||||||
|
|
||||||
|
|
||||||
def create_pods(compose, args): # pylint: disable=unused-argument
|
def create_pods(compose, args): # pylint: disable=unused-argument
|
||||||
|
22
tests/build_fail/README.md
Normal file
22
tests/build_fail/README.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Test podman-compose with build (fail scenario)
|
||||||
|
|
||||||
|
```shell
|
||||||
|
podman-compose build || echo $?
|
||||||
|
```
|
||||||
|
|
||||||
|
expected output would be something like
|
||||||
|
|
||||||
|
```
|
||||||
|
STEP 1/3: FROM busybox
|
||||||
|
STEP 2/3: RUN this_command_does_not_exist
|
||||||
|
/bin/sh: this_command_does_not_exist: not found
|
||||||
|
Error: building at STEP "RUN this_command_does_not_exist": while running runtime: exit status 127
|
||||||
|
|
||||||
|
exit code: 127
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected `podman-compose` exit code:
|
||||||
|
```shell
|
||||||
|
echo $?
|
||||||
|
127
|
||||||
|
```
|
3
tests/build_fail/context/Dockerfile
Normal file
3
tests/build_fail/context/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM busybox
|
||||||
|
RUN this_command_does_not_exist
|
||||||
|
CMD ["sh"]
|
9
tests/build_fail/context/Dockerfile-alt
Normal file
9
tests/build_fail/context/Dockerfile-alt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
FROM busybox
|
||||||
|
ARG buildno=1
|
||||||
|
ARG httpd_port=80
|
||||||
|
ARG other_variable=not_set
|
||||||
|
ENV httpd_port ${httpd_port}
|
||||||
|
ENV other_variable ${other_variable}
|
||||||
|
RUN mkdir -p /var/www/html/ && \
|
||||||
|
echo "ALT buildno=$buildno port=$httpd_port `date -Iseconds`" > /var/www/html/index.txt
|
||||||
|
CMD httpd -f -p "$httpd_port" -h /var/www/html
|
25
tests/build_fail/docker-compose.yml
Normal file
25
tests/build_fail/docker-compose.yml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
web1:
|
||||||
|
build: ./context
|
||||||
|
image: my-busybox-httpd
|
||||||
|
ports:
|
||||||
|
- 8080:80
|
||||||
|
web2:
|
||||||
|
build:
|
||||||
|
context: ./context
|
||||||
|
dockerfile: Dockerfile-alt
|
||||||
|
labels:
|
||||||
|
mykey: myval
|
||||||
|
args:
|
||||||
|
buildno: 2
|
||||||
|
httpd_port: 8000
|
||||||
|
image: my-busybox-httpd2
|
||||||
|
ports:
|
||||||
|
- 8000:8000
|
||||||
|
test_build_arg_argument:
|
||||||
|
build:
|
||||||
|
context: ./context
|
||||||
|
dockerfile: Dockerfile-alt
|
||||||
|
image: my-busybox-httpd2
|
||||||
|
command: env
|
Loading…
Reference in New Issue
Block a user