Catch docker run exceptions

This commit is contained in:
David Boreham 2023-01-19 13:00:35 -07:00
parent 3b5efc8f0f
commit 68c7f91052

View File

@ -23,7 +23,7 @@ from decouple import config
import click import click
import importlib.resources import importlib.resources
from pathlib import Path from pathlib import Path
from python_on_whales import docker from python_on_whales import docker, DockerException
import yaml import yaml
from .util import include_exclude_check from .util import include_exclude_check
@ -84,18 +84,21 @@ def command(ctx, include, exclude):
if verbose: if verbose:
print(f"Executing: {build_command}") print(f"Executing: {build_command}")
envs = {"CERC_NPM_AUTH_TOKEN": os.environ["CERC_NPM_AUTH_TOKEN"]} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {}) 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", try:
remove=True, build_result = docker.run("cerc/builder-js",
interactive=True, remove=True,
tty=True, interactive=True,
user=f"{os.getuid()}:{os.getgid()}", tty=True,
envs=envs, user=f"{os.getuid()}:{os.getgid()}",
add_hosts=[("gitea.local", "host-gateway")], envs=envs,
volumes=[(repo_full_path, "/workspace")], add_hosts=[("gitea.local", "host-gateway")],
command=build_command volumes=[(repo_full_path, "/workspace")],
) command=build_command
# TODO: check result in build_result.returncode )
print(f"Result is: {build_result}") # 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: else:
print("Skipped") print("Skipped")