From dd494798291ddfc76a402ab62695e5566c8b67a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 25 Jan 2024 12:08:36 +0100 Subject: [PATCH] packaging: Don't build the agent if not needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's start relying on the already cached agent to be deployed inside the rootfs. By doing this we save a lot of time in our CI, and we have a better way, for developers, to play with changes in the agent. Fixes: #8915 Signed-off-by: Fabiano FidĂȘncio --- tools/packaging/guest-image/build_image.sh | 3 +++ tools/packaging/kata-deploy/local-build/Makefile | 10 +++++----- .../local-build/kata-deploy-binaries.sh | 14 +++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/packaging/guest-image/build_image.sh b/tools/packaging/guest-image/build_image.sh index 1512849cbc..4367cfaae9 100755 --- a/tools/packaging/guest-image/build_image.sh +++ b/tools/packaging/guest-image/build_image.sh @@ -20,6 +20,7 @@ source "${packaging_root_dir}/scripts/lib.sh" readonly osbuilder_dir="$(cd "${repo_root_dir}/tools/osbuilder" && pwd)" export GOPATH=${GOPATH:-${HOME}/go} +export AGENT_TARBALL=${AGENT_TARBALL:-} ARCH=${ARCH:-$(uname -m)} if [ $(uname -m) == "${ARCH}" ]; then @@ -41,6 +42,7 @@ build_initrd() { OS_VERSION="${os_version}" \ ROOTFS_BUILD_DEST="${builddir}/initrd-image" \ USE_DOCKER=1 \ + AGENT_TARBALL="${AGENT_TARBALL}" \ AGENT_INIT="yes" \ AGENT_POLICY="${AGENT_POLICY:-}" mv "kata-containers-initrd.img" "${install_dir}/${artifact_name}" @@ -60,6 +62,7 @@ build_image() { USE_DOCKER="1" \ IMG_OS_VERSION="${os_version}" \ ROOTFS_BUILD_DEST="${builddir}/rootfs-image" \ + AGENT_TARBALL="${AGENT_TARBALL}" \ AGENT_POLICY="${AGENT_POLICY:-}" mv -f "kata-containers.img" "${install_dir}/${artifact_name}" if [ -e "root_hash.txt" ]; then diff --git a/tools/packaging/kata-deploy/local-build/Makefile b/tools/packaging/kata-deploy/local-build/Makefile index 901500ae3c..289cb06d23 100644 --- a/tools/packaging/kata-deploy/local-build/Makefile +++ b/tools/packaging/kata-deploy/local-build/Makefile @@ -154,19 +154,19 @@ qemu-tdx-experimental-tarball: stratovirt-tarball: ${MAKE} $@-build -rootfs-image-tarball: +rootfs-image-tarball: agent-tarball ${MAKE} $@-build -rootfs-image-tdx-tarball: kernel-tdx-experimental-tarball +rootfs-image-tdx-tarball: agent-opa-tarball kernel-tdx-experimental-tarball ${MAKE} $@-build -rootfs-initrd-mariner-tarball: +rootfs-initrd-mariner-tarball: agent-opa-tarball ${MAKE} $@-build -rootfs-initrd-sev-tarball: kernel-sev-tarball +rootfs-initrd-sev-tarball: agent-opa-tarball kernel-sev-tarball ${MAKE} $@-build -rootfs-initrd-tarball: +rootfs-initrd-tarball: agent-tarball ${MAKE} $@-build runk-tarball: diff --git a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh index ef0883eefd..1b209d5752 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -156,6 +156,16 @@ install_cached_tarball_component() { mv "${component_tarball_name}" "${component_tarball_path}" } +get_agent_tarball_path() { + agent_local_build_dir="${repo_root_dir}/tools/packaging/kata-deploy/local-build/build" + agent_tarball_name="kata-static-agent.tar.xz" + if [ "${AGENT_POLICY:-no}" = "yes" ]; then + agent_tarball_name="kata-static-agent-opa.tar.xz" + fi + + echo "${agent_local_build_dir}/${agent_tarball_name}" +} + #Install guest image install_image() { local variant="${1:-}" @@ -195,7 +205,8 @@ install_image() { os_name="$(get_from_kata_deps "assets.image.architecture.${ARCH}.name")" os_version="$(get_from_kata_deps "assets.image.architecture.${ARCH}.version")" fi - + + export AGENT_TARBALL=$(get_agent_tarball_path) "${rootfs_builder}" --osname="${os_name}" --osversion="${os_version}" --imagetype=image --prefix="${prefix}" --destdir="${destdir}" --image_initrd_suffix="${variant}" } @@ -247,6 +258,7 @@ install_initrd() { os_version="$(get_from_kata_deps "assets.initrd.architecture.${ARCH}.version")" fi + export AGENT_TARBALL=$(get_agent_tarball_path) "${rootfs_builder}" --osname="${os_name}" --osversion="${os_version}" --imagetype=initrd --prefix="${prefix}" --destdir="${destdir}" --image_initrd_suffix="${variant}" }