From 04d8e67d4a08d9a136bdf30b1cf19a1ec76034fa Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 13 Oct 2025 16:24:11 -0400 Subject: [PATCH] script/build-with-container: add build image variants Allow the user to control the content of the build image with a high-level `--image-variant=` switch. Currently the supported values are `default` (the same maximal image we have been generating) and `packages` a slimmer image that avoids installing certain test-only dependencies. Signed-off-by: John Mulligan --- src/script/build-with-container.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/script/build-with-container.py b/src/script/build-with-container.py index 6c6f82abd8b31..fd233596ddc13 100755 --- a/src/script/build-with-container.py +++ b/src/script/build-with-container.py @@ -237,7 +237,9 @@ def _run(cmd, *args, **kwargs): return subprocess.run(cmd, *args, **kwargs) -def _container_cmd(ctx, args, *, workdir=None, interactive=False): +def _container_cmd( + ctx, args, *, workdir=None, interactive=False, extra_args=None +): rm_container = not ctx.cli.keep_container cmd = [ ctx.container_engine, @@ -277,8 +279,8 @@ def _container_cmd(ctx, args, *, workdir=None, interactive=False): ) cmd.append(f"-eCCACHE_DIR={ccdir}") cmd.append(f"-eCCACHE_BASEDIR={ctx.cli.homedir}") - for extra_arg in ctx.cli.extra or []: - cmd.append(extra_arg) + cmd.extend(extra_args or []) + cmd.extend(ctx.cli.extra or []) if ctx.npm_cache_dir: # use :z so that other builds can use the cache cmd.extend([ @@ -367,6 +369,11 @@ class ImageSource(StrEnum): return ", ".join(s.value for s in cls) +class ImageVariant(StrEnum): + DEFAULT = 'default' # build everything + make check + PACKAGES = 'packages' # test deps. ignored, only for packages + + class Context: """Command context.""" @@ -409,6 +416,8 @@ class Context: branch = _git_current_branch(self).replace("/", "-") except subprocess.CalledProcessError: branch = "UNKNOWN" + if self.cli.image_variant is not ImageVariant.DEFAULT: + suffix = f".{self.cli.image_variant}{suffix}" return f"{branch}.{self.cli.distro}{suffix}" def base_branch(self): @@ -614,6 +623,8 @@ def build_container(ctx): f"--volume={ctx.dnf_cache_dir}:/var/cache/dnf:Z", "--build-arg=CLEAN_DNF=no", ] + if ctx.cli.image_variant is ImageVariant.PACKAGES: + cmd.append("--build-arg=FOR_MAKE_CHECK=false") if ctx.cli.build_args: cmd.extend([f"--build-arg={v}" for v in ctx.cli.build_args]) cmd += ["-f", ctx.cli.containerfile, ctx.cli.containerdir] @@ -726,6 +737,9 @@ def bc_build_tests(ctx): "-c", f"cd {ctx.cli.homedir} && source ./src/script/run-make.sh && build tests", ], + # for compatibility with earlier versions that baked this env var + # into the build images + extra_args=['-eFOR_MAKE_CHECK=1'], ) with ctx.user_command(): _run(cmd, check=True, ctx=ctx) @@ -1078,6 +1092,13 @@ def parse_cli(build_step_names): help="Specify a set of valid image sources. " f"May be a comma separated list of {ImageSource.hint()}", ) + g_image.add_argument( + "--image-variant", + type=ImageVariant, + choices=sorted(v.value for v in ImageVariant), + default=ImageVariant.DEFAULT.value, + help="Specify the variant of the build image desired.", + ) g_image.add_argument( "--base-image", help=( -- 2.39.5