diff --git a/docs/commands/prepare.md b/docs/commands/prepare.md index 5510704..1dbb26b 100644 --- a/docs/commands/prepare.md +++ b/docs/commands/prepare.md @@ -29,6 +29,7 @@ stack prepare [OPTIONS] | `--publish-images` | FLAG | Publish the built images | False | | `--image-registry` | TEXT | Specify the remote image registry | From config | | `--target-arch` | TEXT | Specify a target architecture (with --dont-pull-images) | - | +| `--quiet-build` | FLAG | Suppress container build and pull output, keeping the progress summary | False | ## Build Policies @@ -103,8 +104,15 @@ stack prepare --stack my-stack --target-arch arm64 --dont-pull-images # Prepare with SSH for private repos stack prepare --stack my-stack --git-ssh --include-repos private-repo + +# Prepare without the docker build/pull log, keeping the progress summary +stack prepare --stack my-stack --quiet-build ``` +Note that `--quiet-build` differs from the global `--quiet`: `--quiet` also raises +the log level, which hides the per-container progress lines, whereas +`--quiet-build` suppresses only the output of the underlying docker commands. + ## See Also - [stack build](build.md) - Build stack components diff --git a/src/stack/build/build_containers.py b/src/stack/build/build_containers.py index 701a359..de9db6e 100644 --- a/src/stack/build/build_containers.py +++ b/src/stack/build/build_containers.py @@ -193,7 +193,7 @@ def process_container(build_context: BuildContext) -> bool: build_envs["PATH"] = os.environ["PATH"] log_debug(f"Executing: {build_command} with environment: {build_envs}") - build_result = run_shell_command(build_command, env=build_envs, quiet=opts.o.quiet) + build_result = run_shell_command(build_command, env=build_envs, quiet=opts.o.quiet or opts.o.quiet_build) log_debug(f"Build command return code is: {build_result}") if build_result != 0: @@ -228,7 +228,7 @@ def prepare_wrapper_base_container(wrapper, build_context: BuildContext) -> bool if exists_remotely: pull_tag = f"{registry}/{hash_tag}" if registry else hash_tag log_info(f"Base container {pull_tag} exists remotely.") - run_shell_command(f"docker pull {pull_tag}", quiet=opts.o.quiet) + run_shell_command(f"docker pull {pull_tag}", quiet=opts.o.quiet or opts.o.quiet_build) if registry: docker.image.tag(pull_tag, hash_tag) docker.image.tag(hash_tag, stack_tag) @@ -498,11 +498,12 @@ def build_containers(parent_stack, # noqa: C901 if container_needs_pulled: # Pull the remote image if image_registry_to_pull_this_container: - run_shell_command(f"docker pull {image_registry_to_pull_this_container}/{container_tag}", quiet=opts.o.quiet) + run_shell_command(f"docker pull {image_registry_to_pull_this_container}/{container_tag}", + quiet=opts.o.quiet or opts.o.quiet_build) # Tag the local copy to point at it. docker.image.tag(f"{image_registry_to_pull_this_container}/{container_tag}", container_tag) else: - run_shell_command(f"docker pull {container_tag}", quiet=opts.o.quiet) + run_shell_command(f"docker pull {container_tag}", quiet=opts.o.quiet or opts.o.quiet_build) # Tag the local copy to point at it. docker.image.tag(container_tag, stack_local_tag) container_was_pulled = True diff --git a/src/stack/build/prepare.py b/src/stack/build/prepare.py index 6addb79..f7acb81 100644 --- a/src/stack/build/prepare.py +++ b/src/stack/build/prepare.py @@ -18,6 +18,7 @@ from stack.build.build_containers import BUILD_POLICIES, build_containers from stack.config.util import get_config_setting from stack.deploy.stack import resolve_stack +from stack.opts import opts from stack.repos.repo_util import clone_all_repos_for_stack from stack.util import error_exit @@ -43,6 +44,8 @@ default=get_config_setting("image-registry"), ) @click.option("--target-arch", help="Specify a target architecture (only for use with --dont-pull-images)") +@click.option("--quiet-build", is_flag=True, default=False, + help="Suppress container build and pull output, keeping the progress summary") @click.pass_context def command( ctx, @@ -59,12 +62,17 @@ def command( publish_images, image_registry, target_arch, + quiet_build, ): """build or download stack containers""" if build_policy not in PREPARE_POLICIES: error_exit(f"{build_policy} is not one of {PREPARE_POLICIES}") + # Consumed deep in the build path (docker build/pull), so carry it on the shared + # options object rather than threading it through every intervening signature. + opts.o.quiet_build = quiet_build + stack = resolve_stack(stack) cloned_or_pulled_repos = clone_all_repos_for_stack(stack, include_repos, exclude_repos, git_pull, git_ssh) diff --git a/src/stack/command_types.py b/src/stack/command_types.py index 93ef78c..9ce3fef 100644 --- a/src/stack/command_types.py +++ b/src/stack/command_types.py @@ -25,5 +25,9 @@ class CommandOptions: dry_run: bool = False debug: bool = False quiet: bool = False + # Set by `stack prepare --quiet-build`. Suppresses subcommand (docker build/pull) + # output only, unlike `quiet`, which also raises the log level and so hides the + # progress narration. + quiet_build: bool = False log_timestamps: bool = False log_elapsed: bool = False