]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
script/build-with-container: add build image variants
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 13 Oct 2025 20:24:11 +0000 (16:24 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 14 Oct 2025 20:28:22 +0000 (16:28 -0400)
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 <jmulligan@redhat.com>
src/script/build-with-container.py

index 6c6f82abd8b315caa556e8f29a3f33e82a76aa72..fd233596ddc13cca020648a5da388433d102d991 100755 (executable)
@@ -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=(