From 429e04f81d596a09a2fe77e16b3c1ebb659ac476 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Thu, 19 Jan 2023 13:00:35 -0700 Subject: [PATCH] Catch docker run exceptions Former-commit-id: 68c7f91052a6b6c14eb4c7f8e8c0f7936441114d --- app/build_npms.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/build_npms.py b/app/build_npms.py index 8091a8a0..6801dd7d 100644 --- a/app/build_npms.py +++ b/app/build_npms.py @@ -23,7 +23,7 @@ from decouple import config import click import importlib.resources from pathlib import Path -from python_on_whales import docker +from python_on_whales import docker, DockerException import yaml from .util import include_exclude_check @@ -84,18 +84,21 @@ def command(ctx, include, exclude): if verbose: print(f"Executing: {build_command}") envs = {"CERC_NPM_AUTH_TOKEN": os.environ["CERC_NPM_AUTH_TOKEN"]} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {}) - build_result = docker.run("cerc/builder-js", - remove=True, - interactive=True, - tty=True, - user=f"{os.getuid()}:{os.getgid()}", - envs=envs, - add_hosts=[("gitea.local", "host-gateway")], - volumes=[(repo_full_path, "/workspace")], - command=build_command - ) - # TODO: check result in build_result.returncode - print(f"Result is: {build_result}") + try: + build_result = docker.run("cerc/builder-js", + remove=True, + interactive=True, + tty=True, + user=f"{os.getuid()}:{os.getgid()}", + envs=envs, + add_hosts=[("gitea.local", "host-gateway")], + volumes=[(repo_full_path, "/workspace")], + command=build_command + ) + # TODO: check result in build_result.returncode + print(f"Result is: {build_result}") + except DockerException as e: + print(f"FATAL error executing build in container:\n {e}") else: print("Skipped")