Skip to content

eBPF-based security platform

testing: Build VM bundle in container

Martynas Pumputis7d0996493eec
diff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.md
index 7eaf8e2e..75a1f8c2 100644
--- a/.agents/skills/testing/SKILL.md
+++ b/.agents/skills/testing/SKILL.md
@@ -87,12 +87,16 @@ parser of input from outside the host gets a target in `testing/fuzz/`.
artifact directory, needs gigabytes of disk and takes long, and a
checkout or rebase that touches the script triggers it. Compare the
times before starting and tell the user when a rebuild is due.
-- The bundle is built in the checkout from the working tree, so
- uncommitted changes are tested. Edit nothing and run no other build in
- that checkout until it is built.
-- The bundle compiles its BPF fixtures with the clang `shirudo-build`
- was built for, `SHIRUDO_CLANG_PATH`, `/usr/bin/clang` unless set. It
- must be clang 23; an older one stops at a release store with
+- The bundle builds in the build container (`testing/container/`) from
+ a copy of the files git sees in the checkout, tracked and untracked but
+ not ignored, so uncommitted changes are tested; edit nothing until the
+ copy is made. The first build makes the image, with network access,
+ and the static target dependencies, which takes minutes; say so.
+- With `BUILD_CONTAINER=0` the bundle builds in the checkout itself: edit
+ nothing and run no other build there until it is built. It then
+ compiles its BPF fixtures with the clang `shirudo-build` was built
+ for, `SHIRUDO_CLANG_PATH`, `/usr/bin/clang` unless set. It must be
+ clang 23; an older one stops at a release store with
`Cannot select: ... AtomicStore`. Make does not rebuild the helper
when only that variable changes: remove
`tools/shirudo-build/compile.o` first.
@@ -109,11 +113,13 @@ Alacritty, gives everything it starts its `snap.<name>` AppArmor label
signals only from unconfined processes and from `swtpm`: Ctrl-C, the
runner's cleanup and `vm-stop` then leave `swtpm` running. Run the goal
as a transient user service, which runs unconfined. It starts with the
-environment and limits of the user manager, not the shell's: pass on the
-`PATH` and `LD_LIBRARY_PATH` a host with an older OpenSSL or clang than
-the tree needs, and check that `systemctl --user show -p
-DefaultLimitMEMLOCK` reads `infinity`, the unlimited `ulimit -l` a VM
-goal needs.
+environment and limits of the user manager, not the shell's. The
+families build the host tier on the host, and so does the bundle with
+`BUILD_CONTAINER=0`; pass on the `PATH` and `LD_LIBRARY_PATH` a host
+with an older OpenSSL or clang than the tree needs for that. `end2end`
+builds nothing on the host and needs neither. Check that `systemctl
+--user show -p DefaultLimitMEMLOCK` reads `infinity`, the unlimited
+`ulimit -l` a VM goal needs.
```sh
systemd-run --user --pipe --same-dir --wait --collect \
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 884ec74b..94662537 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -8,6 +8,10 @@ updates:
directory: "/Documentation"
schedule:
interval: "weekly"
+ - package-ecosystem: "docker"
+ directory: "/testing/container"
+ schedule:
+ interval: "weekly"
- package-ecosystem: "pip"
directory: "/Documentation"
schedule:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 36c82f89..c43a9ceb 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -97,7 +97,7 @@ jobs:
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: build/test-vm/cache
- key: test-vm-images-${{ hashFiles('testing/vm/runtime-packages', 'testing/vm/operator-packages', 'testing/vm/prepare-runtime.sh', 'testing/vm/build-bundle.sh', 'testing/vm/arch.sh', '.github/scripts/install-clang.sh') }}
+ key: test-vm-images-${{ hashFiles('testing/vm/runtime-packages', 'testing/vm/operator-packages', 'testing/vm/prepare-runtime.sh', 'testing/vm/build-bundle.sh', 'testing/vm/arch.sh', '.github/scripts/install-clang.sh', '.github/scripts/install-static-libcrypto-deps.sh', 'testing/container/Containerfile', 'testing/container/packages', 'Makefile.target-deps') }}
- name: Prepare the test environment
id: setup
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 60c6eb2d..3d8c6599 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -96,9 +96,9 @@ signed config image.
``--dry-run`` plan
* - ``t1007-test-vm-cli``
- Test VM scripts: kernel selection, host dependencies, arm64
- boot settings, the bundle stamp, serve mode, node mode only for a
- core or edge node of the end-to-end tier, the operator VM's role and
- its signing key
+ boot settings, the bundle stamp, the build container, serve mode,
+ node mode only for a core or edge node of the end-to-end tier, the
+ operator VM's role and its signing key
* - ``t1008-kernel-ami-config``
- The slim kernel configuration for NitroTPM CRB, EC2, EFI and SSM
* - ``t1009-upatch-isa``
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index dbe8527e..9b1c2ff1 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -29,8 +29,10 @@ Before you begin
missing skips. The runner of the ``CI suite`` workflow has them all.
- For the tests that boot a VM: a readable and writable ``/dev/kvm``,
a locked-memory limit (``ulimit -l``) of ``unlimited``, which the
- shirudo binaries the runner calls require, an x86-64 or arm64 host and what ``make target`` needs,
- since the bundle a VM boots holds the static target binary. On Ubuntu,
+ shirudo binaries the runner calls require, an x86-64 or arm64 host,
+ and podman or Docker, in which the bundle a VM boots builds; with
+ ``BUILD_CONTAINER=0`` it builds on the host instead, which then needs
+ what ``make target`` needs. On Ubuntu,
``.github/scripts/tests.sh setup`` installs ``cloud-image-utils``,
``dracut-core``, ``file``, ``isc-dhcp-client``, ``libguestfs-tools``,
``qemu-system-x86``, ``qemu-utils``, ``swtpm``, ``swtpm-tools`` and
@@ -417,6 +419,28 @@ signs with. Build it alone with:
$ make -C testing bundle
+The host prepares the VM images and keeps the stamp. The rest, the build
+and everything it signs, :src:`testing/vm/build-bundle-payload.sh` does
+in the build container: Ubuntu 26.04, the release the VMs run, with its
+OpenSSL 3.5, the static archives its ``libcrypto.a`` names, which
+:src:`.github/scripts/install-static-libcrypto-deps.sh` installs as it
+does in CI, and clang 23, so that it needs nothing of the host's
+toolchain and what it puts into a guest links against the guest's
+libraries. The image builds from :src:`testing/container/Containerfile` on
+first use, with network access, and is tagged ``shirudo-build:<hash>``
+by its inputs; :src:`testing/container/run.sh` builds it and runs a
+command in it. The container builds from a copy of the files git sees in
+the checkout, tracked and untracked but not ignored, so uncommitted
+changes are in the bundle and the host's own build is left alone. It
+keeps the static target dependencies it builds under
+``build/test-vm/cache/target-deps/``, one directory per image and
+:src:`Makefile.target-deps`.
+
+``BUILD_CONTAINER=0`` builds the bundle in the checkout with the host's
+toolchain, the way the host tier always builds: OpenSSL 3.5 and clang 23,
+found through ``PATH`` and ``LD_LIBRARY_PATH`` as
+:doc:`/contribute/code/developer-guide` shows. ``CONTAINER`` names another
+engine than the first of ``podman`` and ``docker`` on ``PATH``.
The bundle script runs Make builds with one job per available CPU reported
by ``nproc``. The eighty status-many fixture pairs build in parallel batches, with one
worker per available CPU reported by ``nproc``. Each worker builds a load
diff --git a/testing/Makefile b/testing/Makefile
index 63c30d13..0e6f8748 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -147,10 +147,22 @@ TEST_VM_BUNDLE_SOURCES := $(sort $(wildcard \
$(ROOT)/upatches/kernel-obs/*.c $(ROOT)/upatches/kernel-obs/*.h $(ROOT)/upatches/kernel-obs/*.list \
$(ROOT)/upatches/kernel-obs/*.py $(ROOT)/upatches/kernel-obs/Beefile \
$(ROOT)/upatches/kernel-obs/decoders/*))
+# The host's util/version_id.c is no input: every build of the host's
+# writes it, and the bundle's build writes its own.
+TEST_VM_BUNDLE_SOURCES := $(filter-out $(ROOT)/util/version_id.c,$(TEST_VM_BUNDLE_SOURCES))
# The kernel build replaces versioned package files; depend on its stable stamp.
TEST_VM_BUNDLE_ARTIFACTS := $(VM_KERNEL_STAMP)
+# The bundle builds in the build container unless BUILD_CONTAINER=0, so it
+# depends on the image's inputs rather than on the host's configuration.
+BUILD_CONTAINER ?= 1
+TEST_VM_BUILD_ENV := $(if $(filter 0,$(BUILD_CONTAINER)),$(ROOT)/config.mk, \
+ $(ROOT)/testing/container/Containerfile $(ROOT)/testing/container/packages \
+ $(ROOT)/testing/container/run.sh $(ROOT)/.github/scripts/install-clang.sh \
+ $(ROOT)/.github/scripts/install-static-libcrypto-deps.sh \
+ $(ROOT)/testing/vm/list-source.sh)
TEST_VM_BUNDLE_INPUTS := $(sort \
- $(ROOT)/Makefile $(ROOT)/Makefile.config $(ROOT)/Makefile.shirudo $(ROOT)/Makefile.version $(ROOT)/config.mk \
+ $(ROOT)/Makefile $(ROOT)/Makefile.config $(ROOT)/Makefile.shirudo $(ROOT)/Makefile.version \
+ $(TEST_VM_BUILD_ENV) \
$(ROOT)/Makefile.target-deps \
$(ROOT)/testing/Makefile $(ROOT)/packaging/Makefile \
$(ROOT)/vendor/libbpf/Makefile $(ROOT)/vendor/libbpf/COMMIT \
@@ -170,6 +182,7 @@ test-vm-bundle: $(VM_KERNEL_DEP) $(TEST_VM_BUNDLE_STAMP)
$(TEST_VM_BUNDLE_STAMP): $(TEST_VM_BUNDLE_INPUTS)
$(Q)mkdir -p $(dir $(BUILD_LOCK))
$(Q)TEST_VM_MODE="$(TEST_VM_MODE)" TEST_VM_INITRD="$(TEST_VM_INITRD)" \
+ BUILD_CONTAINER="$(BUILD_CONTAINER)" \
TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \
TEST_VM_WORK_DIR="$(abspath $(TEST_VM_WORK_DIR))" \
TEST_VM_HOST_PRIVATE_DIR="$(abspath $(TEST_VM_HOST_PRIVATE_DIR))" \
diff --git a/testing/container/Containerfile b/testing/container/Containerfile
new file mode 100644
index 00000000..d5733819
--- /dev/null
+++ b/testing/container/Containerfile
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# The build environment of the test VM bundle: Ubuntu 26.04, the release
+# the test VMs run, with its OpenSSL 3.5 and clang 23 from install-clang.sh,
+# so that the bundle builds alike on every host and what it carries into a
+# guest links against the libraries the guest has. The static archives that
+# libcrypto.a names come from install-static-libcrypto-deps.sh, as in CI, for
+# the static shirudo-quote-check.
+
+FROM docker.io/library/ubuntu:26.04@sha256:6a06111c3b0a8600feadb270aec771dc239bf407b25625f93f44ab00e11f4d3c
+
+COPY packages install-clang.sh install-static-libcrypto-deps.sh /tmp/shirudo-build/
+RUN export DEBIAN_FRONTEND=noninteractive && \
+ apt-get update && \
+ apt-get install -y --no-install-recommends \
+ $(cat /tmp/shirudo-build/packages) && \
+ sh /tmp/shirudo-build/install-static-libcrypto-deps.sh && \
+ sh /tmp/shirudo-build/install-clang.sh && \
+ rm -rf /var/lib/apt/lists/* /tmp/shirudo-build
diff --git a/testing/container/packages b/testing/container/packages
new file mode 100644
index 00000000..895690e8
--- /dev/null
+++ b/testing/container/packages
@@ -0,0 +1,30 @@
+autoconf
+autoconf-archive
+automake
+build-essential
+ca-certificates
+cryptsetup-bin
+curl
+dpkg-dev
+e2fsprogs
+file
+git
+gpg
+libcurl4-openssl-dev
+libelf-dev
+libltdl-dev
+libluajit-5.1-dev
+libssl-dev
+libtool
+libtpms-dev
+libtss2-dev
+libzstd-dev
+llvm
+openssl
+perl
+pkg-config
+python3
+rsync
+swtpm
+xz-utils
+zlib1g-dev
diff --git a/testing/container/run.sh b/testing/container/run.sh
new file mode 100755
index 00000000..486a7954
--- /dev/null
+++ b/testing/container/run.sh
@@ -0,0 +1,101 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# testing/container/run.sh [-v <dir>]... [-e <name>]... -- <command>...
+# testing/container/run.sh --image
+# -- run a command in the build image, built from the Containerfile beside
+# this script unless it exists. The checkout is mounted read-only at its own
+# path and each <dir> writable at its own; each named variable of the
+# environment is passed on, and the command runs as the caller, in the
+# caller's directory. --image prints the image's name.
+
+set -euo pipefail
+
+here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+root=$(cd "$here/../.." && pwd)
+inputs=("$here/Containerfile" "$here/packages"
+ "$root/.github/scripts/install-clang.sh"
+ "$root/.github/scripts/install-static-libcrypto-deps.sh")
+image="shirudo-build:$(cat "${inputs[@]}" | sha256sum | cut -c1-16)"
+
+die()
+{
+ printf 'testing/container/run.sh: %s\n' "$*" >&2
+ exit 1
+}
+
+if [[ "${1:-}" == --image ]]; then
+ printf '%s\n' "$image"
+ exit 0
+fi
+
+engine=${CONTAINER:-$(command -v podman || command -v docker || true)}
+[[ -n "$engine" ]] ||
+ die "podman or docker is required; BUILD_CONTAINER=0 builds on the host"
+
+args=(--rm --init -v "$root:$root:ro" -w "$PWD" -e HOME=/tmp)
+# Under sudo, git trusts a repository that SUDO_UID owns; in here it cannot
+# tell, and a mounted cache that another user restored, such as the source
+# trees of the target dependencies in CI, would be refused.
+args+=(-e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=safe.directory
+ -e "GIT_CONFIG_VALUE_0=*")
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ -v)
+ [[ $# -ge 2 && "$2" == /* ]] || die "-v takes an absolute directory"
+ args+=(-v "$2:$2")
+ shift 2
+ ;;
+ -e)
+ [[ $# -ge 2 ]] || die "-e takes the name of a variable"
+ args+=(-e "$2")
+ shift 2
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ die "usage: $0 [-v <dir>]... [-e <name>]... -- <command>..."
+ ;;
+ esac
+done
+[[ $# -gt 0 ]] || die "no command to run"
+
+# Rootless podman maps the caller to root in the container unless told to
+# keep the caller's IDs, and cannot raise the memory lock limit shirudo
+# needs beyond the caller's.
+if [[ "$(basename "$engine")" == podman* &&
+ "$("$engine" info --format '{{.Host.Security.Rootless}}' 2>/dev/null)" == true ]]; then
+ args+=(--userns=keep-id)
+else
+ args+=(--user "$(id -u):$(id -g)" --ulimit memlock=-1:-1)
+fi
+
+if ! "$engine" image inspect "$image" >/dev/null 2>&1; then
+ # One lock per user: under fs.protected_regular, nobody but its owner,
+ # root included, can open for writing a file someone else made in /tmp.
+ exec 9>"${TMPDIR:-/tmp}/shirudo-build-image-$(id -u).lock"
+ flock 9
+ if ! "$engine" image inspect "$image" >/dev/null 2>&1; then
+ ctx=$(mktemp -d)
+ trap 'rm -rf "$ctx"' EXIT
+ cp "${inputs[@]}" "$ctx/"
+ printf '[build-image] building %s\n' "$image" >&2
+ # Registries and mirrors answer 5xx now and then, and a retry
+ # starts from the layers already built.
+ for attempt in 1 2 3; do
+ "$engine" build -q -t "$image" -f "$ctx/Containerfile" "$ctx" \
+ >/dev/null && break
+ [[ "$attempt" -lt 3 ]] || die "could not build $image"
+ printf '[build-image] build failed; retrying in %ss\n' \
+ $((attempt * 15)) >&2
+ sleep $((attempt * 15))
+ done
+ rm -rf "$ctx"
+ trap - EXIT
+ fi
+ exec 9>&-
+fi
+exec "$engine" run "${args[@]}" "$image" "$@"
diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.sh
index 63d9c92d..bc05974a 100755
--- a/testing/functional/build/t1007-test-vm-cli.sh
+++ b/testing/functional/build/t1007-test-vm-cli.sh
@@ -475,12 +475,48 @@ test_expect_success 'test-vm imports the host-built payload' '
grep -q "TEST_VM_BUNDLE_STAMP" ../testing/Makefile &&
grep -q "TEST_VM_BUNDLE_INPUTS" ../testing/Makefile &&
grep -q "bundle_is_current" vm/build-bundle.sh &&
+ grep -Fq "touch -d \"@\$STAMP_TIME\" \"\$STAMP_FILE\"" vm/build-bundle.sh &&
+ make -s -C .. -f testing/Makefile \
+ --eval "bundle-inputs: ; @echo \$(TEST_VM_BUNDLE_INPUTS)" \
+ bundle-inputs >"$WORK/bundle-inputs.out" &&
+ grep -q "/util/upatch\.c" "$WORK/bundle-inputs.out" &&
+ ! grep -q "/util/version_id\.c" "$WORK/bundle-inputs.out" &&
grep -q "flock 9" ../testing/Makefile &&
grep -q "bundle_dir.lock" ../testing/Makefile &&
! grep -Fq "rm -rf \"\$\$bundle_dir.lock\"" ../testing/Makefile &&
grep -Fq "\$\$bundle_dir" ../testing/Makefile
'
+test_expect_success 'the bundle builds in the build container unless BUILD_CONTAINER=0' '
+ image=$(../testing/container/run.sh --image) &&
+ expr "$image" : "shirudo-build:[0-9a-f]\{16\}$" >/dev/null &&
+ ! CONTAINER=/bin/false ../testing/container/run.sh -v relative -- true \
+ >"$WORK/container-v.out" 2>&1 &&
+ grep -q -- "-v takes an absolute directory" "$WORK/container-v.out" &&
+ ! CONTAINER=/bin/false ../testing/container/run.sh \
+ >"$WORK/container-none.out" 2>&1 &&
+ grep -q "no command to run" "$WORK/container-none.out" &&
+ make -n -C .. -f testing/Makefile test-vm-bundle \
+ TEST_VM_WORK_DIR="$WORK/container-bundle" \
+ >"$WORK/container-make.out" 2>&1 &&
+ grep -q "BUILD_CONTAINER=\"1\"" "$WORK/container-make.out" &&
+ grep -q "testing/container/Containerfile" "$WORK/container-make.out" &&
+ ! grep -q "/config\.mk" "$WORK/container-make.out" &&
+ make -n -C .. -f testing/Makefile test-vm-bundle BUILD_CONTAINER=0 \
+ TEST_VM_WORK_DIR="$WORK/host-bundle" >"$WORK/host-make.out" 2>&1 &&
+ grep -q "BUILD_CONTAINER=\"0\"" "$WORK/host-make.out" &&
+ grep -q "/config\.mk" "$WORK/host-make.out" &&
+ grep -q "build-bundle-payload.sh\" --from-copy" vm/build-bundle.sh &&
+ grep -q "list-source.sh" vm/build-bundle.sh vm/run.sh &&
+ ! grep -q "ls-files" vm/build-bundle-payload.sh vm/guest.sh &&
+ if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
+ vm/list-source.sh "$WORK/source-files" &&
+ tr "\\0" "\\n" <"$WORK/source-files" >"$WORK/source-list" &&
+ grep -qx "testing/vm/list-source.sh" "$WORK/source-list" &&
+ ! grep -q "^build/" "$WORK/source-list"
+ fi
+'
+
test_expect_success 'test-vm summary records failed test names' '
grep -q "print_test_summary" vm/run.sh &&
grep -q "exit \"\$FINAL_STATUS\"" vm/run.sh &&
diff --git a/testing/vm/build-bundle-payload.sh b/testing/vm/build-bundle-payload.sh
index 7dd0f67a..a2f8a138 100755
--- a/testing/vm/build-bundle-payload.sh
+++ b/testing/vm/build-bundle-payload.sh
@@ -2,10 +2,12 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
#
-# testing/vm/build-bundle-payload.sh <bundle> <fixture-work> -- build and
-# sign what the test VM bundle carries into a guest: the target binary and
-# the test helpers, the upatch fixtures with keys made for them, and the
-# runtime and config images. build-bundle.sh runs it in the checkout.
+# testing/vm/build-bundle-payload.sh [--from-copy <files>] <bundle> <fixture-work>
+# -- build and sign what the test VM bundle carries into a guest: the target
+# binary and the test helpers, the upatch fixtures with keys made for them,
+# and the runtime and config images. build-bundle.sh runs it in the build
+# container with --from-copy, which builds from a copy of the files that
+# list-source.sh listed, or with BUILD_CONTAINER=0 in the checkout itself.
set -euo pipefail
@@ -33,8 +35,18 @@ require_command()
die "missing build command: $command_name (install with: $(test_vm_install_cmd "$(test_vm_pkg "$deb_package" "$rpm_package")"))"
}
+if [[ "${1:-}" == --from-copy ]]; then
+ [[ $# -ge 2 && -s "$2" ]] || die "--from-copy takes the list of files to copy"
+ files="$2"
+ shift 2
+ require_command rsync rsync
+ src="$(mktemp -d "${TMPDIR:-/tmp}/shirudo-bundle-src.XXXXXX")"
+ rsync -a --from0 --files-from="$files" --ignore-missing-args \
+ "$REPO_ROOT"/ "$src"/
+ exec "$src/testing/vm/build-bundle-payload.sh" "$@"
+fi
[[ $# -eq 2 && -d "$1" && -d "$2" ]] ||
- die "usage: $0 <bundle> <fixture-work>"
+ die "usage: $0 [--from-copy <files>] <bundle> <fixture-work>"
TMP_DIR="$1"
FIXTURE_WORK="$2"
diff --git a/testing/vm/build-bundle.sh b/testing/vm/build-bundle.sh
index 8de654b5..9f46840a 100755
--- a/testing/vm/build-bundle.sh
+++ b/testing/vm/build-bundle.sh
@@ -5,7 +5,7 @@
# Build the host-side payload imported by testing/vm/run.sh. The bundle is
# shared by all VMs, while TPM state and the test workspace remain per-VM.
# The host prepares the VM images; build-bundle-payload.sh builds and signs
-# the rest.
+# the rest, in the build container unless BUILD_CONTAINER=0.
set -euo pipefail
@@ -32,6 +32,7 @@ OPERATOR_KEYS_DIR="${HOST_PRIVATE_DIR}/operator-keys"
RUNTIME_PREP_VERSION=4
TEST_VM_MODE=${TEST_VM_MODE:-verity}
RUNTIME_DISK_SIZE="${TEST_VM_RUNTIME_DISK_SIZE:-8G}"
+BUILD_CONTAINER="${BUILD_CONTAINER:-1}"
log()
{
@@ -299,6 +300,36 @@ bundle_is_current()
return 0
}
+# The container builds from a copy of the checkout, so that it shares no
+# objects with the host's build, and keeps the static target dependencies it
+# builds for its image and Makefile.target-deps. A file it reads from the
+# host goes into the fixture work first, where the container sees it.
+build_payload_in_container()
+{
+ local container="$REPO_ROOT/testing/container/run.sh" deps name
+ local -a pass=(-e TARGET_DEPS_DIR -e TEST_VM_ARCH)
+
+ deps="$WORK_DIR/cache/target-deps/$({
+ "$container" --image
+ cat "$REPO_ROOT/Makefile.target-deps"
+ } | sha256sum | cut -c1-16)"
+ mkdir -p "$deps"
+ install -d -m 0700 "$FIXTURE_WORK/inputs"
+ "$REPO_ROOT/testing/vm/list-source.sh" "$FIXTURE_WORK/inputs/source-files"
+ for name in BPF_VMLINUX_BTF TEST_VM_PACKAGE_CERT \
+ TEST_VM_BUILTIN_SIGNING_KEY TEST_VM_BUILTIN_SIGNING_CERT; do
+ [[ -n "${!name:-}" ]] || continue
+ install -m 0600 "${!name}" "$FIXTURE_WORK/inputs/$name"
+ export "$name=$FIXTURE_WORK/inputs/$name"
+ pass+=(-e "$name")
+ done
+ log "building the payload in $("$container" --image)"
+ TARGET_DEPS_DIR="$deps" "$container" -v "$TMP_DIR" -v "$FIXTURE_WORK" \
+ -v "$deps" "${pass[@]}" -- \
+ "$REPO_ROOT/testing/vm/build-bundle-payload.sh" --from-copy \
+ "$FIXTURE_WORK/inputs/source-files" "$TMP_DIR" "$FIXTURE_WORK"
+}
+
command -v flock >/dev/null 2>&1 ||
die "flock is required; install it with: $(test_vm_install_cmd util-linux)"
@@ -308,6 +339,9 @@ validate_package_cert
mkdir -p "$(dirname "$BUNDLE_DIR")"
exec 9>"$LOCK_FILE"
flock 9
+# The stamp takes the time before the build reads its inputs, so that one
+# changed while it runs is newer and the next VM goal builds again.
+STAMP_TIME="$(date +%s.%N)"
validate_host_private_dir
resolve_rootfs
@@ -331,7 +365,11 @@ cleanup()
rm -rf -- "$TMP_DIR" "$FIXTURE_WORK"
}
trap cleanup EXIT
-"$REPO_ROOT/testing/vm/build-bundle-payload.sh" "$TMP_DIR" "$FIXTURE_WORK"
+if [[ "$BUILD_CONTAINER" == 0 ]]; then
+ "$REPO_ROOT/testing/vm/build-bundle-payload.sh" "$TMP_DIR" "$FIXTURE_WORK"
+else
+ build_payload_in_container
+fi
printf '%s\n' "$TEST_VM_MODE" >"$TMP_DIR/test-mode"
printf 'shirudo-test-vm-bundle-v1\n' >"$TMP_DIR/format"
@@ -348,6 +386,6 @@ chmod 0600 "$OPERATOR_KEYS_DIR/keys/signing_key.pem"
rm -rf -- "$BUNDLE_DIR"
mv -- "$TMP_DIR" "$BUNDLE_DIR"
-touch "$STAMP_FILE"
+touch -d "@$STAMP_TIME" "$STAMP_FILE"
trap - EXIT
log "ready: $BUNDLE_DIR"