containers / podman-compose

a script to run docker-compose.yml using podman
GNU General Public License v2.0
5.09k stars 483 forks source link

Immediately exit/crash on build failure #223

Open benjaoming opened 4 years ago

benjaoming commented 4 years ago

Thanks for a great project! I have a docker-compose.yml looking like this:

version: '3'
services:
  # Base of everything
  base:
    build:
      context: ./base
    image: my_base:latest
  application:
    depends_on:
      - base
    build:
      context: ./my_app
    image: my_base:latest

If base fails to build, podman-compose build should exit immediately. But it just keeps building and then fails. Here's an example:

STEP 7: COPY requirements.txt /tmp/application/requirements.txt
--> Using cache c7fe4560bc163f6f2b72ab4e150a45827053ce83f9453374c17ee54131970c05
STEP 8: RUN python3 -m pip install 'pip>=20.1.1<21' 'virtualenv>=20.0.27,<21' --upgrade &&  cd /usr/share/application/git &&     virtualenv --python=python3 venv &&     . venv/bin/activate &&     pip install -r /tmp/application/requirements.txt &&     rm /tmp/application/requirements.txt &&     pip install -r requirements/deploy.txt
ERRO[0000] systemd cgroup flag passed, but systemd support for managing cgroups is not available 
systemd cgroup flag passed, but systemd support for managing cgroups is not available
error running container: error creating container for [/bin/sh -c python3 -m pip install 'pip>=20.1.1<21' 'virtualenv>=20.0.27,<21' --upgrade &&    cd /usr/share/application/git &&     virtualenv --python=python3 venv &&     . venv/bin/activate &&     pip install -r /tmp/application/requirements.txt &&     rm /tmp/application/requirements.txt &&     pip install -r requirements/deploy.txt]: : exit status 1
Error: error building at STEP "RUN python3 -m pip install 'pip>=20.1.1<21' 'virtualenv>=20.0.27,<21' --upgrade &&   cd /usr/share/application/git &&     virtualenv --python=python3 venv &&     . venv/bin/activate &&     pip install -r /tmp/application/requirements.txt &&     rm /tmp/application/requirements.txt &&     pip install -r requirements/deploy.txt": error while running runtime: exit status 1
125
podman build -t application -f ./my_app/Dockerfile ./my_app
STEP 1: FROM my_base:latest
Error: error creating build container: The following failures happened while trying to pull image specified by "my_base:latest" based on search registries in /etc/containers/registries.conf:
* "localhost/my_base:latest": Error initializing source docker://localhost/my_base:latest: error pinging docker registry localhost: Get "https://localhost/v2/": dial tcp [::1]:443: connect: connection refused
* "registry.fedoraproject.org/my_base:latest": Error initializing source docker://registry.fedoraproject.org/my_base:latest: Error reading manifest latest in registry.fedoraproject.org/application: manifest unknown: manifest unknown
* "registry.access.redhat.com/my_base:latest": Error initializing source docker://registry.access.redhat.com/my_base:latest: Error reading manifest latest in registry.access.redhat.com/application: name unknown: Repo not found
* "registry.centos.org/my_base:latest": Error initializing source docker://registry.centos.org/my_base:latest: Error reading manifest latest in registry.centos.org/application: manifest unknown: manifest unknown
* "docker.io/library/my_base:latest": Error initializing source docker://my_base:latest: Error reading manifest latest in docker.io/library/application: errors:
denied: requested access to the resource is denied
unauthorized: authentication required

Version:

podman-composer version  0.1.6dev
podman --version
podman version 2.0.2
dotcs commented 4 years ago

Same for me when attempting to build an image. Has there been some change in podman which is not yet implemented in podman-compose?

x9foo commented 3 years ago

I use the following patch to get a fail-fast exit on a build failure:

diff --git a/podman-compose b/podman-compose
index b3ac14fa..69823aeb 100755
--- a/podman-compose
+++ b/podman-compose
@@ -684,7 +684,7 @@ class Podman:
         cmd = [self.podman_path]+podman_args
         return subprocess.check_output(cmd)

-    def run(self, podman_args, wait=True, sleep=1):
+    def run(self, podman_args, wait=True, sleep=1, exit_on_fail=False):
         podman_args_str = [str(arg) for arg in podman_args]
         print("podman " + " ".join(podman_args_str))
         if self.dry_run:
@@ -693,7 +693,10 @@ class Podman:
         # subprocess.Popen(args, bufsize = 0, executable = None, stdin = None, stdout = None, stderr = None, preexec_fn = None, close_fds = False, shell = False, cwd = None, env = None, universal_newlines = False, startupinfo = None, creationflags = 0)
         p = subprocess.Popen(cmd)
         if wait:
-            print(p.wait())
+            exit_code = p.wait()
+            print(exit_code)
+            if exit_on_fail and exit_code != 0:
+                exit(exit_code)
         if sleep:
             time.sleep(sleep)
         return p
@@ -1079,7 +1082,7 @@ def build_one(compose, args, cnt):
     for build_arg in args_list + args.build_arg:
         build_args.extend(("--build-arg", build_arg,))
     build_args.append(ctx)
-    compose.podman.run(build_args, sleep=0)
+    compose.podman.run(build_args, sleep=0, exit_on_fail=True)

 @cmd_run(podman_compose, 'build', 'build stack images')
 def compose_build(compose, args):

Example output:

...
Lint errors found in the listed files.
STEP 9: FROM docker.io/nginxinc/nginx-unprivileged:1.18.0-alpine
Error: error building at STEP "RUN ./node_modules/@angular/cli/bin/ng lint": error while running runtime: exit status 1
125
$