forked from cerc-io/stack-orchestrator
Implement stop on error building containers
Former-commit-id: bbbb57ec06
This commit is contained in:
parent
429e04f81d
commit
8f9f23b1c4
@ -21,6 +21,7 @@
|
||||
# TODO: display the available list of containers; allow re-build of either all or specific containers
|
||||
|
||||
import os
|
||||
import sys
|
||||
from decouple import config
|
||||
import subprocess
|
||||
import click
|
||||
@ -45,6 +46,7 @@ def command(ctx, include, exclude):
|
||||
dry_run = ctx.obj.dry_run
|
||||
local_stack = ctx.obj.local_stack
|
||||
stack = ctx.obj.stack
|
||||
continue_on_error = ctx.obj.continue_on_error
|
||||
|
||||
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
|
||||
container_build_dir = Path(__file__).absolute().parent.joinpath("data", "container-build")
|
||||
@ -112,8 +114,15 @@ def command(ctx, include, exclude):
|
||||
if verbose:
|
||||
print(f"Executing: {build_command}")
|
||||
build_result = subprocess.run(build_command, shell=True, env=container_build_env)
|
||||
# TODO: check result in build_result.returncode
|
||||
print(f"Result is: {build_result}")
|
||||
if verbose:
|
||||
print(f"Return code is: {build_result.returncode}")
|
||||
if build_result.returncode != 0:
|
||||
print(f"Error running build for {container}")
|
||||
if not continue_on_error:
|
||||
print("FATAL Error: container build failed and --continue-on-error not set, exiting")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("****** Container Build Error, continuing because --continue-on-error is set")
|
||||
else:
|
||||
print("Skipped")
|
||||
|
||||
|
8
cli.py
8
cli.py
@ -27,13 +27,14 @@ CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
||||
# TODO: this seems kind of weird and heavy on boilerplate -- check it is
|
||||
# the best Python can do for us.
|
||||
class Options(object):
|
||||
def __init__(self, stack, quiet, verbose, dry_run, local_stack, debug):
|
||||
def __init__(self, stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error):
|
||||
self.stack = stack
|
||||
self.quiet = quiet
|
||||
self.verbose = verbose
|
||||
self.dry_run = dry_run
|
||||
self.local_stack = local_stack
|
||||
self.debug = debug
|
||||
self.continue_on_error = continue_on_error
|
||||
|
||||
|
||||
@click.group(context_settings=CONTEXT_SETTINGS)
|
||||
@ -43,11 +44,12 @@ class Options(object):
|
||||
@click.option('--dry-run', is_flag=True, default=False)
|
||||
@click.option('--local-stack', is_flag=True, default=False)
|
||||
@click.option('--debug', is_flag=True, default=False)
|
||||
@click.option('--continue-on-error', is_flag=True, default=False)
|
||||
# See: https://click.palletsprojects.com/en/8.1.x/complex/#building-a-git-clone
|
||||
@click.pass_context
|
||||
def cli(ctx, stack, quiet, verbose, dry_run, local_stack, debug):
|
||||
def cli(ctx, stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error):
|
||||
"""Laconic Stack Orchestrator"""
|
||||
ctx.obj = Options(stack, quiet, verbose, dry_run, local_stack, debug)
|
||||
ctx.obj = Options(stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error)
|
||||
|
||||
|
||||
cli.add_command(setup_repositories.command, "setup-repositories")
|
||||
|
Loading…
Reference in New Issue
Block a user