Skip to content

Commit

Permalink
Add more output logging for multiplatform builds
Browse files Browse the repository at this point in the history
  • Loading branch information
saville committed Nov 10, 2023
1 parent 26b4cc7 commit 03e9686
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions buildrunner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many
exit_explanation = None
try: # pylint: disable=too-many-nested-blocks
with MultiplatformImageBuilder(
log=self.log,
docker_registry=self.global_config.get_docker_registry(),
keep_images=not self.cleanup_images,
temp_dir=self.global_config.get_temp_dir(),
Expand Down
35 changes: 23 additions & 12 deletions buildrunner/docker/multiplatform_image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from multiprocessing import Manager, Process
from platform import machine, system
import shutil
import sys
import tempfile
import uuid
from typing import Dict, List, Optional
Expand Down Expand Up @@ -121,13 +122,15 @@ class MultiplatformImageBuilder: # pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments
def __init__(
self,
log=sys.stdout,
docker_registry: Optional[str] = None,
use_local_registry: bool = True,
keep_images: bool = False,
temp_dir: str = os.getcwd(),
disable_multi_platform: bool = False,
platform_builders: Optional[Dict[str, str]] = None,
):
self._log = log
self._docker_registry = docker_registry
self._mp_registry_info = None
self._use_local_registry = use_local_registry
Expand Down Expand Up @@ -315,7 +318,8 @@ def _build_single_image(

tagged_names = [f"{name}:{tag}" for tag in tags]
builder = self._platform_builders.get(platform) if self._platform_builders else None
logger.debug(f"Building {tagged_names} for {platform} with {builder or 'default'} builder")
logger.debug(f"Building tagged images {tagged_names}")
self._log.write(f"Building image for platform {platform} with {builder or 'default'} builder\n")

if inject and isinstance(inject, dict):
self._build_with_inject(
Expand Down Expand Up @@ -451,20 +455,27 @@ def get_path(file):

if self._disable_multi_platform:
platforms = [self.get_single_platform_to_build(platforms)]
print(f"{line}\n"
f"Note: Disabling multi-platform build, "
"this will only build a single-platform image.\n"
f"image: {sanitized_name} platform:{platforms[0]}\n"
f"{line}")
self._log.write(
f"{line}\n"
f"Note: Disabling multi-platform build, "
"this will only build a single-platform image.\n"
f"image: {sanitized_name} platform:{platforms[0]}\n"
f"{line}\n"
)
else:
print(f"{line}\n"
f"Note: Building multi-platform images can take a long time, please be patient.\n"
"If you are running this locally, you can speed this up by using the "
"'--disable-multi-platform' CLI flag "
"or set the 'disable-multi-platform' flag in the global config file.\n"
f"{line}")
self._log.write(
f"{line}\n"
f"Note: Building multi-platform images can take a long time, please be patient.\n"
"If you are running this locally, you can speed this up by using the "
"'--disable-multi-platform' CLI flag "
"or set the 'disable-multi-platform' flag in the global config file.\n"
f"{line}\n"
)

processes = []
self._log.write(
f'Starting builds for {len(platforms)} platforms in {"parallel" if do_multiprocessing else "sequence"}\n'
)
for platform in platforms:
platform_image_name = f"{base_image_name}-{platform.replace('/', '-')}"
build_single_image_args = (
Expand Down

0 comments on commit 03e9686

Please sign in to comment.