From 8307718842e22fe091f595cf27813a4fa9dd8166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 25 Jan 2024 11:58:11 +0100 Subject: [PATCH] rootfs: Add AGENT_TARBALL env var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This env var will serve us to pass the agent tarball to the rootfs builder, which will then just unpack the content into the rootfs instead of building the agent again. AGENT_TARBALL and AGENT_SOURCE_BIN should never be used together. Signed-off-by: Fabiano FidĂȘncio --- tools/osbuilder/rootfs-builder/rootfs.sh | 30 +++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index 0a37cf5210..186a4a1802 100755 --- a/tools/osbuilder/rootfs-builder/rootfs.sh +++ b/tools/osbuilder/rootfs-builder/rootfs.sh @@ -125,6 +125,14 @@ AGENT_INIT When set to "yes", use ${AGENT_BIN} as init process in place AGENT_SOURCE_BIN Path to the directory of agent binary. If set, use the binary as agent but not build agent package. + AGENT_SOURCE_BIN and AGENT_TARBALL should never be used toghether. + Default value: + +AGENT_TARBALL Path to the kata-agent.tar.xz tarball to be unpacked inside the + rootfs. + If set, this will take the priority and will be used instead of + building the agent. + AGENT_SOURCE_BIN and AGENT_TARBALL should never be used toghether. Default value: AGENT_VERSION Version of the agent to include in the rootfs. @@ -419,14 +427,22 @@ build_rootfs_distro() engine_run_args+=" --ulimit nofile=262144:262144" engine_run_args+=" --runtime ${DOCKER_RUNTIME}" - if [ -z "${AGENT_SOURCE_BIN}" ] ; then - engine_run_args+=" -v ${GOPATH_LOCAL}:${GOPATH_LOCAL} --env GOPATH=${GOPATH_LOCAL}" - else + if [ -n "${AGENT_SOURCE_BIN}" ] && [ -n "${AGENT_TARBALL}" ]; then + die "AGENT_SOURCE_BIN and AGENT_TARBALL should never be used together!" + fi + + if [ -n "${AGENT_SOURCE_BIN}" ] ; then engine_run_args+=" --env AGENT_SOURCE_BIN=${AGENT_SOURCE_BIN}" engine_run_args+=" -v ${AGENT_SOURCE_BIN}:${AGENT_SOURCE_BIN}" - engine_run_args+=" -v ${GOPATH_LOCAL}:${GOPATH_LOCAL} --env GOPATH=${GOPATH_LOCAL}" fi + if [ -n "${AGENT_TARBALL}" ] ; then + engine_run_args+=" --env AGENT_TARBALL=${AGENT_TARBALL}" + engine_run_args+=" -v $(dirname ${AGENT_TARBALL}):$(dirname ${AGENT_TARBALL})" + fi + + engine_run_args+=" -v ${GOPATH_LOCAL}:${GOPATH_LOCAL} --env GOPATH=${GOPATH_LOCAL}" + engine_run_args+=" $(docker_extra_args $distro)" # Relabel volumes so SELinux allows access (see docker-run(1)) @@ -630,7 +646,7 @@ EOF AGENT_DIR="${ROOTFS_DIR}/usr/bin" AGENT_DEST="${AGENT_DIR}/${AGENT_BIN}" - if [ -z "${AGENT_SOURCE_BIN}" ] ; then + if [ -z "${AGENT_SOURCE_BIN}" ] && [ -z "${AGENT_TARBALL}" ] ; then test -r "${HOME}/.cargo/env" && source "${HOME}/.cargo/env" # rust agent needs ${arch}-unknown-linux-${LIBC} if ! (rustup show | grep -v linux-${LIBC} > /dev/null); then @@ -669,10 +685,12 @@ EOF rm -rf "${libseccomp_install_dir}" "${gperf_install_dir}" fi popd - else + elif [ "${AGENT_SOURCE_BIN}" ]; then mkdir -p ${AGENT_DIR} cp ${AGENT_SOURCE_BIN} ${AGENT_DEST} OK "cp ${AGENT_SOURCE_BIN} ${AGENT_DEST}" + else + tar xvJpf ${AGENT_TARBALL} -C ${ROOTFS_DIR} fi [ -x "${AGENT_DEST}" ] || die "${AGENT_DEST} is not installed in ${ROOTFS_DIR}"