Refactor, support build-webapp
All checks were successful
Lint Checks / Run linter (pull_request) Successful in 39s
Webapp Test / Run webapp test suite (pull_request) Successful in 3m21s
Deploy Test / Run deploy test suite (pull_request) Successful in 4m52s
K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 6m15s
Smoke Test / Run basic test suite (pull_request) Successful in 3m3s

This commit is contained in:
David Boreham 2024-02-23 12:17:53 -07:00
parent 5690303181
commit a389285fb1
3 changed files with 34 additions and 19 deletions

View File

@ -62,7 +62,7 @@ def make_container_build_env(dev_root_path: str,
return container_build_env
def process_container(build_context: BuildContext):
def process_container(build_context: BuildContext) -> bool:
if not opts.o.quiet:
print(f"Building: {build_context.container}")
@ -108,17 +108,12 @@ def process_container(build_context: BuildContext):
if opts.o.verbose:
print(f"Return code is: {build_result.returncode}")
if build_result.returncode != 0:
print(f"Error running build for {build_context.container}")
if not opts.o.continue_on_error:
print("FATAL Error: container build failed and --continue-on-error not set, exiting")
sys.exit(1)
return False
else:
print("****** Container Build Error, continuing because --continue-on-error is set")
else:
if build_context.publish_images:
publish_image(default_container_tag, build_context.image_registry)
return True
else:
print("Skipped")
return True
@click.command()
@ -187,11 +182,19 @@ def command(ctx, include, exclude, force_rebuild, extra_build_args, publish_imag
container,
container_build_dir,
container_build_env,
dev_root_path,
publish_images,
image_registry
dev_root_path
)
process_container(build_context)
result = process_container(build_context)
if result:
if publish_images:
publish_image(container, image_registry)
else:
print(f"Error running build for {build_context.container}")
if not opts.o.continue_on_error:
error_exit("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:
if opts.o.verbose:
print(f"Excluding: {container}")

View File

@ -26,5 +26,4 @@ class BuildContext:
container_build_dir: Path
container_build_env: Mapping[str,str]
dev_root_path: str
publish_images: bool
image_registry: str

View File

@ -26,6 +26,7 @@ import click
from pathlib import Path
from stack_orchestrator.build import build_containers
from stack_orchestrator.deploy.webapp.util import determine_base_container
from stack_orchestrator.build.build_types import BuildContext
@click.command()
@ -65,8 +66,14 @@ def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, t
container_build_env = build_containers.make_container_build_env(dev_root_path, container_build_dir, debug,
force_rebuild, extra_build_args)
build_containers.process_container(None, base_container, container_build_dir, container_build_env, dev_root_path, quiet,
verbose, dry_run, continue_on_error)
build_context_1 = BuildContext(
stack,
base_container,
container_build_dir,
container_build_env,
dev_root_path,
)
build_containers.process_container(build_context_1)
# Now build the target webapp. We use the same build script, but with a different Dockerfile and work dir.
container_build_env["CERC_WEBAPP_BUILD_RUNNING"] = "true"
@ -80,5 +87,11 @@ def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, t
else:
container_build_env["CERC_CONTAINER_BUILD_TAG"] = tag
build_containers.process_container(None, base_container, container_build_dir, container_build_env, dev_root_path, quiet,
verbose, dry_run, continue_on_error)
build_context_2 = BuildContext(
stack,
base_container,
container_build_dir,
container_build_env,
dev_root_path,
)
build_containers.process_container(build_context_2)