Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/commands/prepare.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/stack/build/build_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/stack/build/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions src/stack/command_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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