From 08fe49f708e54a2a0e0cc5b90616bfaeb99a1156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 12:09:34 +0100 Subject: [PATCH 01/18] versions: Adjust kernel names to match kata-deploy build targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's adjust the kernel names in versions.yaml so those can match the names used as part of the kata-deploy local build scripts. Right now this doesn't bring any benefit nor drawback, but it'll make our life easier later on in this same series. Depends-on: github.com/kata-containers/tests#5534 Signed-off-by: Fabiano Fidêncio --- .../packaging/kata-deploy/local-build/kata-deploy-binaries.sh | 2 +- tools/packaging/kernel/build-kernel.sh | 4 ++-- versions.yaml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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 ded375cb6..79cf5a141 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -108,7 +108,7 @@ install_kernel() { #Install dragonball experimental kernel asset install_dragonball_experimental_kernel() { info "build dragonball experimental kernel" - export kernel_version="$(yq r $versions_yaml assets.dragonball-kernel-experimental.version)" + export kernel_version="$(yq r $versions_yaml assets.kernel-dragonball-experimental.version)" info "kernel version ${kernel_version}" DESTDIR="${destdir}" PREFIX="${prefix}" "${kernel_builder}" -e -t dragonball -v ${kernel_version} } diff --git a/tools/packaging/kernel/build-kernel.sh b/tools/packaging/kernel/build-kernel.sh index 014e08359..af7e36e6b 100755 --- a/tools/packaging/kernel/build-kernel.sh +++ b/tools/packaging/kernel/build-kernel.sh @@ -556,7 +556,7 @@ main() { case "${arch_target}" in "aarch64") build_type="arm-experimental" - kernel_version=$(get_from_kata_deps "assets.arm-kernel-experimental.version") + kernel_version=$(get_from_kata_deps "assets.kernel-arm-experimental.version") ;; *) info "No arch-specific experimental kernel supported, using experimental one instead" @@ -564,7 +564,7 @@ main() { ;; esac elif [[ ${build_type} == "dragonball-experimental" ]]; then - kernel_version=$(get_from_kata_deps "assets.dragonball-kernel-experimental.version") + kernel_version=$(get_from_kata_deps "assets.kernel-dragonball-experimental.version") elif [[ "${conf_guest}" != "" ]]; then #If specifying a tag for kernel_version, must be formatted version-like to avoid unintended parsing issues kernel_version=$(get_from_kata_deps "assets.kernel.${conf_guest}.version" 2>/dev/null || true) diff --git a/versions.yaml b/versions.yaml index b68bf8fbd..817ff1202 100644 --- a/versions.yaml +++ b/versions.yaml @@ -177,12 +177,12 @@ assets: url: "https://cdn.kernel.org/pub/linux/kernel/v5.x/" tag: "v5.13.10" - arm-kernel-experimental: + kernel-arm-experimental: description: "Linux kernel with cpu/mem hotplug support on arm64" url: "https://cdn.kernel.org/pub/linux/kernel/v5.x/" version: "v5.15.7" - dragonball-kernel-experimental: + kernel-dragonball-experimental: description: "Linux kernel with Dragonball VMM optimizations like upcall" url: "https://cdn.kernel.org/pub/linux/kernel/v5.x/" version: "v5.10.25" From 6b1b424fc733fd34496c322de2bb1d6acb0ce820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 12:36:21 +0100 Subject: [PATCH 02/18] tools: Add support for caching Cloud Hypervisor artefacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's add support for caching Cloud Hypervisor artefacts that are generated using the kata-deploy local-build scripts. Right now those are not used, but we'll switch to using them very soon as part of upcoming changes of how we build the components we test in our CI. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../static-build/cache_components_main.sh | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 tools/packaging/static-build/cache_components_main.sh diff --git a/tools/packaging/static-build/cache_components_main.sh b/tools/packaging/static-build/cache_components_main.sh new file mode 100755 index 000000000..b6780e935 --- /dev/null +++ b/tools/packaging/static-build/cache_components_main.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# Copyright (c) 2022 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +set -o errexit +set -o nounset +set -o pipefail + +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${script_dir}/../scripts/lib.sh" + +cache_clh_artifacts() { + local clh_tarball_name="kata-static-cloud-hypervisor.tar.xz" + local current_clh_version="$(get_from_kata_deps "assets.hypervisor.cloud_hypervisor.version")" + create_cache_asset "${clh_tarball_name}" "${current_clh_version}" "" +} + +create_cache_asset() { + local component_name="${1}" + local component_version="${2}" + local component_image="${3}" + + sudo cp "${repo_root_dir}/tools/packaging/kata-deploy/local-build/build/${component_name}" . + sudo chown -R "${USER}:${USER}" . + sha256sum "${component_name}" > "sha256sum-${component_name}" + cat "sha256sum-${component_name}" + echo "${component_version}" > "latest" + cat "latest" + echo "${component_image}" > "latest_image" + cat "latest_image" +} + +help() { +echo "$(cat << EOF +Usage: $0 "[options]" + Description: + Builds the cache of several kata components. + Options: + -c Cloud hypervisor cache + -h Shows help +EOF +)" +} + +main() { + local cloud_hypervisor_component="${cloud_hypervisor_component:-}" + local OPTIND + while getopts ":ch:" opt + do + case "$opt" in + c) + cloud_hypervisor_component="1" + ;; + h) + help + exit 0; + ;; + :) + echo "Missing argument for -$OPTARG"; + help + exit 1; + ;; + esac + done + shift $((OPTIND-1)) + + [[ -z "${cloud_hypervisor_component}" ]] && \ + help && die "Must choose at least one option" + + mkdir -p "${WORKSPACE}/artifacts" + pushd "${WORKSPACE}/artifacts" + echo "Artifacts:" + + [ "${cloud_hypervisor_component}" == "1" ] && cache_clh_artifacts + + ls -la "${WORKSPACE}/artifacts/" + popd + sync +} + +main "$@" From 762f9f4c3edf44d18e8f979afc2e46cf72b29b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 12:39:38 +0100 Subject: [PATCH 03/18] tools: Add support for caching Firecracker artefacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's add support for caching Firecracker artefacts that are generated using the kata-deploy local-build scripts. Right now those are not used, but we'll switch to using them very soon as part of upcoming changes of how we build the components we test in our CI. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../static-build/cache_components_main.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/packaging/static-build/cache_components_main.sh b/tools/packaging/static-build/cache_components_main.sh index b6780e935..4ba3d16e0 100755 --- a/tools/packaging/static-build/cache_components_main.sh +++ b/tools/packaging/static-build/cache_components_main.sh @@ -18,6 +18,12 @@ cache_clh_artifacts() { create_cache_asset "${clh_tarball_name}" "${current_clh_version}" "" } +cache_firecracker_artifacts() { + local fc_tarball_name="kata-static-firecracker.tar.xz" + local current_fc_version="$(get_from_kata_deps "assets.hypervisor.firecracker.version")" + create_cache_asset "${fc_tarball_name}" "${current_fc_version}" "" +} + create_cache_asset() { local component_name="${1}" local component_version="${2}" @@ -40,6 +46,7 @@ Usage: $0 "[options]" Builds the cache of several kata components. Options: -c Cloud hypervisor cache + -F Firecracker cache -h Shows help EOF )" @@ -47,13 +54,17 @@ EOF main() { local cloud_hypervisor_component="${cloud_hypervisor_component:-}" + local firecracker_component="${firecracker_component:-}" local OPTIND - while getopts ":ch:" opt + while getopts ":cFh:" opt do case "$opt" in c) cloud_hypervisor_component="1" ;; + F) + firecracker_component="1" + ;; h) help exit 0; @@ -68,6 +79,7 @@ main() { shift $((OPTIND-1)) [[ -z "${cloud_hypervisor_component}" ]] && \ + [[ -z "${firecracker_component}" ]] && \ help && die "Must choose at least one option" mkdir -p "${WORKSPACE}/artifacts" @@ -75,6 +87,7 @@ main() { echo "Artifacts:" [ "${cloud_hypervisor_component}" == "1" ] && cache_clh_artifacts + [ "${firecracker_component}" == "1" ] && cache_firecracker_artifacts ls -la "${WORKSPACE}/artifacts/" popd From cb4cbe29580f9e44b7f70ca9f5c7ceadb448dc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 12:43:21 +0100 Subject: [PATCH 04/18] tools: Add support for caching Kernel artefacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's add support for caching Kernel artefacts that are generated using the kata-deploy local-build scripts. Right now those are not used, but we'll switch to using them very soon as part of upcoming changes of how we build the components we test in our CI. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- tools/packaging/kernel/kata_config_version | 2 +- tools/packaging/scripts/lib.sh | 5 +++++ .../static-build/cache_components_main.sh | 21 ++++++++++++++++++- tools/packaging/static-build/kernel/build.sh | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/packaging/kernel/kata_config_version b/tools/packaging/kernel/kata_config_version index 398050c62..257e56326 100644 --- a/tools/packaging/kernel/kata_config_version +++ b/tools/packaging/kernel/kata_config_version @@ -1 +1 @@ -101 +102 diff --git a/tools/packaging/scripts/lib.sh b/tools/packaging/scripts/lib.sh index 10c535172..deece4ede 100644 --- a/tools/packaging/scripts/lib.sh +++ b/tools/packaging/scripts/lib.sh @@ -129,3 +129,8 @@ push_to_registry() { fi fi } + +get_kernel_image_name() { + kernel_script_dir="${repo_root_dir}/tools/packaging/static-build/kernel" + echo "${BUILDER_REGISTRY}:kernel-$(get_last_modification ${kernel_script_dir})-$(uname -m)" +} diff --git a/tools/packaging/static-build/cache_components_main.sh b/tools/packaging/static-build/cache_components_main.sh index 4ba3d16e0..3f620887c 100755 --- a/tools/packaging/static-build/cache_components_main.sh +++ b/tools/packaging/static-build/cache_components_main.sh @@ -12,6 +12,8 @@ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${script_dir}/../scripts/lib.sh" +KERNEL_FLAVOUR="${KERNEL_FLAVOUR:-kernel}" # kernel | kernel-experimental | kernel-arm-experimetnal | kernel-dragonball-experimental + cache_clh_artifacts() { local clh_tarball_name="kata-static-cloud-hypervisor.tar.xz" local current_clh_version="$(get_from_kata_deps "assets.hypervisor.cloud_hypervisor.version")" @@ -24,6 +26,14 @@ cache_firecracker_artifacts() { create_cache_asset "${fc_tarball_name}" "${current_fc_version}" "" } +cache_kernel_artifacts() { + local kernel_tarball_name="kata-static-${KERNEL_FLAVOUR}.tar.xz" + local current_kernel_image="$(get_kernel_image_name)" + local current_kernel_kata_config_version="$(cat ${repo_root_dir}/tools/packaging/kernel/kata_config_version)" + local current_kernel_version="$(get_from_kata_deps "assets.${KERNEL_FLAVOUR}.version")-${current_kernel_kata_config_version}" + create_cache_asset "${kernel_tarball_name}" "${current_kernel_version}" "${current_kernel_image}" +} + create_cache_asset() { local component_name="${1}" local component_version="${2}" @@ -47,6 +57,9 @@ Usage: $0 "[options]" Options: -c Cloud hypervisor cache -F Firecracker cache + -k Kernel cache + * Export KERNEL_FLAVOUR="kernel|kernek-experimental|kernel-arm-experimental|kernel-dragonball-experimental" for a specific build + The default KERNEL_FLAVOUR value is "kernel" -h Shows help EOF )" @@ -55,8 +68,9 @@ EOF main() { local cloud_hypervisor_component="${cloud_hypervisor_component:-}" local firecracker_component="${firecracker_component:-}" + local kernel_component="${kernel_component:-}" local OPTIND - while getopts ":cFh:" opt + while getopts ":cFkh:" opt do case "$opt" in c) @@ -65,6 +79,9 @@ main() { F) firecracker_component="1" ;; + k) + kernel_component="1" + ;; h) help exit 0; @@ -80,6 +97,7 @@ main() { [[ -z "${cloud_hypervisor_component}" ]] && \ [[ -z "${firecracker_component}" ]] && \ + [[ -z "${kernel_component}" ]] && \ help && die "Must choose at least one option" mkdir -p "${WORKSPACE}/artifacts" @@ -88,6 +106,7 @@ main() { [ "${cloud_hypervisor_component}" == "1" ] && cache_clh_artifacts [ "${firecracker_component}" == "1" ] && cache_firecracker_artifacts + [ "${kernel_component}" == "1" ] && cache_kernel_artifacts ls -la "${WORKSPACE}/artifacts/" popd diff --git a/tools/packaging/static-build/kernel/build.sh b/tools/packaging/static-build/kernel/build.sh index f85ba4ec1..d9f6ccd90 100755 --- a/tools/packaging/static-build/kernel/build.sh +++ b/tools/packaging/static-build/kernel/build.sh @@ -16,7 +16,7 @@ readonly kernel_builder="${repo_root_dir}/tools/packaging/kernel/build-kernel.sh DESTDIR=${DESTDIR:-${PWD}} PREFIX=${PREFIX:-/opt/kata} -container_image="${KERNEL_CONTAINER_BUILDER:-${BUILDER_REGISTRY}:kernel-$(get_last_modification ${script_dir})-$(uname -m)}" +container_image="${KERNEL_CONTAINER_BUILDER:-$(get_kernel_image_name)}" sudo docker pull ${container_image} || \ (sudo docker build -t "${container_image}" "${script_dir}" && \ From 7aed8f8c80c3268a7073a8ca5ac6d8377ed4889f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 12:45:20 +0100 Subject: [PATCH 05/18] tools: Add support for caching Nydus artefacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's add support for caching Nydus artefacts that are generated using the kata-deploy local-build scripts. Right now those are not used, but we'll switch to using them very soon as part of upcoming changes of how we build the components we test in our CI. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../static-build/cache_components_main.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/packaging/static-build/cache_components_main.sh b/tools/packaging/static-build/cache_components_main.sh index 3f620887c..84ca73a0b 100755 --- a/tools/packaging/static-build/cache_components_main.sh +++ b/tools/packaging/static-build/cache_components_main.sh @@ -34,6 +34,12 @@ cache_kernel_artifacts() { create_cache_asset "${kernel_tarball_name}" "${current_kernel_version}" "${current_kernel_image}" } +cache_nydus_artifacts() { + local nydus_tarball_name="kata-static-nydus.tar.xz" + local current_nydus_version="$(get_from_kata_deps "externals.nydus.version")" + create_cache_asset "${nydus_tarball_name}" "${current_nydus_version}" "" +} + create_cache_asset() { local component_name="${1}" local component_version="${2}" @@ -60,6 +66,7 @@ Usage: $0 "[options]" -k Kernel cache * Export KERNEL_FLAVOUR="kernel|kernek-experimental|kernel-arm-experimental|kernel-dragonball-experimental" for a specific build The default KERNEL_FLAVOUR value is "kernel" + -n Nydus cache -h Shows help EOF )" @@ -69,8 +76,9 @@ main() { local cloud_hypervisor_component="${cloud_hypervisor_component:-}" local firecracker_component="${firecracker_component:-}" local kernel_component="${kernel_component:-}" + local nydus_component="${nydus_component:-}" local OPTIND - while getopts ":cFkh:" opt + while getopts ":cFknh:" opt do case "$opt" in c) @@ -82,6 +90,9 @@ main() { k) kernel_component="1" ;; + n) + nydus_component="1" + ;; h) help exit 0; @@ -98,6 +109,7 @@ main() { [[ -z "${cloud_hypervisor_component}" ]] && \ [[ -z "${firecracker_component}" ]] && \ [[ -z "${kernel_component}" ]] && \ + [[ -z "${nydus_component}" ]] && \ help && die "Must choose at least one option" mkdir -p "${WORKSPACE}/artifacts" @@ -107,6 +119,7 @@ main() { [ "${cloud_hypervisor_component}" == "1" ] && cache_clh_artifacts [ "${firecracker_component}" == "1" ] && cache_firecracker_artifacts [ "${kernel_component}" == "1" ] && cache_kernel_artifacts + [ "${nydus_component}" == "1" ] && cache_nydus_artifacts ls -la "${WORKSPACE}/artifacts/" popd From e90891059b035fa3dc7aa0887e4db1779cc6be65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 12:59:40 +0100 Subject: [PATCH 06/18] tools: Add support for caching QEMU artefacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's add support for caching QEMU artefacts that are generated using the kata-deploy local-build scripts. Right now those are not used, but we'll switch to using them very soon as part of upcoming changes of how we build the components we test in our CI. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- tools/packaging/scripts/lib.sh | 41 +++++++++++++++++++ .../static-build/cache_components_main.sh | 17 +++++++- .../static-build/qemu/build-base-qemu.sh | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/tools/packaging/scripts/lib.sh b/tools/packaging/scripts/lib.sh index deece4ede..6f006c1f9 100644 --- a/tools/packaging/scripts/lib.sh +++ b/tools/packaging/scripts/lib.sh @@ -134,3 +134,44 @@ get_kernel_image_name() { kernel_script_dir="${repo_root_dir}/tools/packaging/static-build/kernel" echo "${BUILDER_REGISTRY}:kernel-$(get_last_modification ${kernel_script_dir})-$(uname -m)" } + +sha256sum_from_files() { + local files_in=${@:-} + local files="" + local shasum="" + + # Process the input files: + # - discard the files/directories that don't exist. + # - find the files if it is a directory + for f in $files_in; do + if [ -d "$f" ]; then + files+=" $(find $f -type f)" + elif [ -f "$f" ]; then + files+=" $f" + fi + done + # Return in case there is none input files. + [ -n "$files" ] || return 0 + + # Alphabetically sorting the files. + files="$(echo $files | tr ' ' '\n' | LC_ALL=C sort -u)" + # Concate the files and calculate a hash. + shasum="$(cat $files | sha256sum -b)" || true + if [ -n "$shasum" ];then + # Return only the SHA field. + echo $(awk '{ print $1 }' <<< $shasum) + fi +} + +calc_qemu_files_sha256sum() { + local files="${repo_root_dir}/tools/packaging/qemu \ + ${repo_root_dir}/tools/packaging/static-build/qemu.blacklist \ + ${repo_root_dir}/tools/packaging/static-build/scripts" + + sha256sum_from_files "$files" +} + +get_qemu_image_name() { + qemu_script_dir="${repo_root_dir}/tools/packaging/static-build/qemu" + echo "${BUILDER_REGISTRY}:qemu-$(get_last_modification ${qemu_script_dir})-$(uname -m)" +} diff --git a/tools/packaging/static-build/cache_components_main.sh b/tools/packaging/static-build/cache_components_main.sh index 84ca73a0b..0136d1db0 100755 --- a/tools/packaging/static-build/cache_components_main.sh +++ b/tools/packaging/static-build/cache_components_main.sh @@ -40,6 +40,14 @@ cache_nydus_artifacts() { create_cache_asset "${nydus_tarball_name}" "${current_nydus_version}" "" } +cache_qemu_artifacts() { + local qemu_tarball_name="kata-static-qemu.tar.xz" + local current_qemu_version=$(get_from_kata_deps "assets.hypervisor.qemu.version") + local qemu_sha=$(calc_qemu_files_sha256sum) + local current_qemu_image="$(get_qemu_image_name)" + create_cache_asset "${qemu_tarball_name}" "${current_qemu_version}-${qemu_sha}" "${current_qemu_image}" +} + create_cache_asset() { local component_name="${1}" local component_version="${2}" @@ -67,6 +75,7 @@ Usage: $0 "[options]" * Export KERNEL_FLAVOUR="kernel|kernek-experimental|kernel-arm-experimental|kernel-dragonball-experimental" for a specific build The default KERNEL_FLAVOUR value is "kernel" -n Nydus cache + -q QEMU cache -h Shows help EOF )" @@ -77,8 +86,9 @@ main() { local firecracker_component="${firecracker_component:-}" local kernel_component="${kernel_component:-}" local nydus_component="${nydus_component:-}" + local qemu_component="${qemu_component:-}" local OPTIND - while getopts ":cFknh:" opt + while getopts ":cFknqh:" opt do case "$opt" in c) @@ -93,6 +103,9 @@ main() { n) nydus_component="1" ;; + q) + qemu_component="1" + ;; h) help exit 0; @@ -110,6 +123,7 @@ main() { [[ -z "${firecracker_component}" ]] && \ [[ -z "${kernel_component}" ]] && \ [[ -z "${nydus_component}" ]] && \ + [[ -z "${qemu_component}" ]] && \ help && die "Must choose at least one option" mkdir -p "${WORKSPACE}/artifacts" @@ -120,6 +134,7 @@ main() { [ "${firecracker_component}" == "1" ] && cache_firecracker_artifacts [ "${kernel_component}" == "1" ] && cache_kernel_artifacts [ "${nydus_component}" == "1" ] && cache_nydus_artifacts + [ "${qemu_component}" == "1" ] && cache_qemu_artifacts ls -la "${WORKSPACE}/artifacts/" popd diff --git a/tools/packaging/static-build/qemu/build-base-qemu.sh b/tools/packaging/static-build/qemu/build-base-qemu.sh index 55ab71d35..9767e5d54 100755 --- a/tools/packaging/static-build/qemu/build-base-qemu.sh +++ b/tools/packaging/static-build/qemu/build-base-qemu.sh @@ -38,7 +38,7 @@ CACHE_TIMEOUT=$(date +"%Y-%m-%d") [ -n "${build_suffix}" ] && HYPERVISOR_NAME="kata-qemu-${build_suffix}" || HYPERVISOR_NAME="kata-qemu" [ -n "${build_suffix}" ] && PKGVERSION="kata-static-${build_suffix}" || PKGVERSION="kata-static" -container_image="${QEMU_CONTAINER_BUILDER:-${BUILDER_REGISTRY}:qemu-$(get_last_modification ${script_dir})-$(uname -m)}" +container_image="${QEMU_CONTAINER_BUILDER:-$(get_qemu_image_name)}" sudo docker pull ${container_image} || (sudo "${container_engine}" build \ --build-arg CACHE_TIMEOUT="${CACHE_TIMEOUT}" \ From 7898db5f79024c485655d375ba70d00ec837d34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:05:15 +0100 Subject: [PATCH 07/18] tools: Add support for caching RootFS artefacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's add support for caching RootFS artefacts that are generated using the kata-deploy local-build scripts. Right now those are not used, but we'll switch to using them very soon as part of upcoming changes of how we build the components we test in our CI. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../static-build/cache_components_main.sh | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/packaging/static-build/cache_components_main.sh b/tools/packaging/static-build/cache_components_main.sh index 0136d1db0..c5d49f773 100755 --- a/tools/packaging/static-build/cache_components_main.sh +++ b/tools/packaging/static-build/cache_components_main.sh @@ -13,6 +13,7 @@ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${script_dir}/../scripts/lib.sh" KERNEL_FLAVOUR="${KERNEL_FLAVOUR:-kernel}" # kernel | kernel-experimental | kernel-arm-experimetnal | kernel-dragonball-experimental +ROOTFS_IMAGE_TYPE="${ROOTFS_IMAGE_TYPE:-image}" # image | initrd cache_clh_artifacts() { local clh_tarball_name="kata-static-cloud-hypervisor.tar.xz" @@ -48,6 +49,19 @@ cache_qemu_artifacts() { create_cache_asset "${qemu_tarball_name}" "${current_qemu_version}-${qemu_sha}" "${current_qemu_image}" } +cache_rootfs_artifacts() { + local osbuilder_last_commit="$(get_last_modification "${repo_root_dir}/tools/osbuilder")" + local guest_image_last_commit="$(get_last_modification "${repo_root_dir}/tools/packaging/guest-image")" + local agent_last_commit="$(get_last_modification "${repo_root_dir}/src/agent")" + local libs_last_commit="$(get_last_modification "${repo_root_dir}/src/libs")" + local gperf_version="$(get_from_kata_deps "externals.gperf.version")" + local libseccomp_version="$(get_from_kata_deps "externals.libseccomp.version")" + local rust_version="$(get_from_kata_deps "languages.rust.meta.newest-version")" + local rootfs_tarball_name="kata-static-rootfs-${ROOTFS_IMAGE_TYPE}.tar.xz" + local current_rootfs_version="${osbuilder_last_commit}-${guest_image_last_commit}-${agent_last_commit}-${libs_last_commit}-${gperf_version}-${libseccomp_version}-${rust_version}-${ROOTFS_IMAGE_TYPE}" + create_cache_asset "${rootfs_tarball_name}" "${current_rootfs_version}" "" +} + create_cache_asset() { local component_name="${1}" local component_version="${2}" @@ -76,6 +90,9 @@ Usage: $0 "[options]" The default KERNEL_FLAVOUR value is "kernel" -n Nydus cache -q QEMU cache + -r RootFS cache + * Export ROOTFS_IMAGE_TYPE="image|initrd" for one of those two types + The default ROOTFS_IMAGE_TYPE value is "image" -h Shows help EOF )" @@ -87,8 +104,9 @@ main() { local kernel_component="${kernel_component:-}" local nydus_component="${nydus_component:-}" local qemu_component="${qemu_component:-}" + local rootfs_component="${rootfs_component:-}" local OPTIND - while getopts ":cFknqh:" opt + while getopts ":cFknqrh:" opt do case "$opt" in c) @@ -106,6 +124,9 @@ main() { q) qemu_component="1" ;; + r) + rootfs_component="1" + ;; h) help exit 0; @@ -124,6 +145,7 @@ main() { [[ -z "${kernel_component}" ]] && \ [[ -z "${nydus_component}" ]] && \ [[ -z "${qemu_component}" ]] && \ + [[ -z "${rootfs_component}" ]] && \ help && die "Must choose at least one option" mkdir -p "${WORKSPACE}/artifacts" @@ -135,6 +157,7 @@ main() { [ "${kernel_component}" == "1" ] && cache_kernel_artifacts [ "${nydus_component}" == "1" ] && cache_nydus_artifacts [ "${qemu_component}" == "1" ] && cache_qemu_artifacts + [ "${rootfs_component}" == "1" ] && cache_rootfs_artifacts ls -la "${WORKSPACE}/artifacts/" popd From a34272cf20420f630839b357433022d53c8ebc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:14:16 +0100 Subject: [PATCH 08/18] tools: Add support for caching shim v2 artefacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's add support for caching shim v2 artefacts that are generated using the kata-deploy local-build scripts. Right now those are not used, but we'll switch to using them very soon as part of upcoming changes of how we build the components we test in our CI. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- tools/packaging/scripts/lib.sh | 5 +++++ .../static-build/cache_components_main.sh | 21 ++++++++++++++++++- tools/packaging/static-build/shim-v2/build.sh | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/packaging/scripts/lib.sh b/tools/packaging/scripts/lib.sh index 6f006c1f9..61776bcbf 100644 --- a/tools/packaging/scripts/lib.sh +++ b/tools/packaging/scripts/lib.sh @@ -175,3 +175,8 @@ get_qemu_image_name() { qemu_script_dir="${repo_root_dir}/tools/packaging/static-build/qemu" echo "${BUILDER_REGISTRY}:qemu-$(get_last_modification ${qemu_script_dir})-$(uname -m)" } + +get_shim_v2_image_name() { + shim_v2_script_dir="${repo_root_dir}/tools/packaging/static-build/shim-v2" + echo "${BUILDER_REGISTRY}:shim-v2-go-$(get_from_kata_deps "languages.golang.meta.newest-version")-rust-$(get_from_kata_deps "languages.rust.meta.newest-version")-$(get_last_modification ${shim_v2_script_dir})-$(uname -m)" +} diff --git a/tools/packaging/static-build/cache_components_main.sh b/tools/packaging/static-build/cache_components_main.sh index c5d49f773..ef9cf6b9c 100755 --- a/tools/packaging/static-build/cache_components_main.sh +++ b/tools/packaging/static-build/cache_components_main.sh @@ -62,6 +62,18 @@ cache_rootfs_artifacts() { create_cache_asset "${rootfs_tarball_name}" "${current_rootfs_version}" "" } +cache_shim_v2_artifacts() { + local shim_v2_tarball_name="kata-static-shim-v2.tar.xz" + local shim_v2_last_commit="$(get_last_modification "${repo_root_dir}/src/runtime")" + local protocols_last_commit="$(get_last_modification "${repo_root_dir}/src/libs/protocols")" + local runtime_rs_last_commit="$(get_last_modification "${repo_root_dir}/src/runtime-rs")" + local golang_version="$(get_from_kata_deps "languages.golang.meta.newest-version")" + local rust_version="$(get_from_kata_deps "languages.rust.meta.newest-version")" + local current_shim_v2_version="${shim_v2_last_commit}-${protocols_last_commit}-${runtime_rs_last_commit}-${golang_version}-${rust_version}" + local current_shim_v2_image="$(get_shim_v2_image_name)" + create_cache_asset "${shim_v2_tarball_name}" "${current_shim_v2_version}" "${current_shim_v2_image}" +} + create_cache_asset() { local component_name="${1}" local component_version="${2}" @@ -93,6 +105,7 @@ Usage: $0 "[options]" -r RootFS cache * Export ROOTFS_IMAGE_TYPE="image|initrd" for one of those two types The default ROOTFS_IMAGE_TYPE value is "image" + -s Shim v2 cache -h Shows help EOF )" @@ -105,8 +118,9 @@ main() { local nydus_component="${nydus_component:-}" local qemu_component="${qemu_component:-}" local rootfs_component="${rootfs_component:-}" + local shim_v2_component="${shim_v2_component:-}" local OPTIND - while getopts ":cFknqrh:" opt + while getopts ":cFknqrsh:" opt do case "$opt" in c) @@ -127,6 +141,9 @@ main() { r) rootfs_component="1" ;; + s) + shim_v2_component="1" + ;; h) help exit 0; @@ -146,6 +163,7 @@ main() { [[ -z "${nydus_component}" ]] && \ [[ -z "${qemu_component}" ]] && \ [[ -z "${rootfs_component}" ]] && \ + [[ -z "${shim_v2_component}" ]] && \ help && die "Must choose at least one option" mkdir -p "${WORKSPACE}/artifacts" @@ -158,6 +176,7 @@ main() { [ "${nydus_component}" == "1" ] && cache_nydus_artifacts [ "${qemu_component}" == "1" ] && cache_qemu_artifacts [ "${rootfs_component}" == "1" ] && cache_rootfs_artifacts + [ "${shim_v2_component}" == "1" ] && cache_shim_v2_artifacts ls -la "${WORKSPACE}/artifacts/" popd diff --git a/tools/packaging/static-build/shim-v2/build.sh b/tools/packaging/static-build/shim-v2/build.sh index 35ebabcab..d948ae1e8 100755 --- a/tools/packaging/static-build/shim-v2/build.sh +++ b/tools/packaging/static-build/shim-v2/build.sh @@ -19,7 +19,7 @@ RUST_VERSION=${RUST_VERSION} DESTDIR=${DESTDIR:-${PWD}} PREFIX=${PREFIX:-/opt/kata} -container_image="${SHIM_V2_CONTAINER_BUILDER:-${BUILDER_REGISTRY}:shim-v2-go-${GO_VERSION}-rust-${RUST_VERSION}-$(get_last_modification ${script_dir})-$(uname -m)}" +container_image="${SHIM_V2_CONTAINER_BUILDER:-$(get_shim_v2_image_name)}" sudo docker pull ${container_image} || \ (sudo docker build \ From 194d5dc8a6e92a56077dff8684d8b9b49a95b83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:17:19 +0100 Subject: [PATCH 09/18] tools: Add support for caching VirtioFS artefacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's add support for caching VirtioFS artefacts that are generated using the kata-deploy local-build scripts. Right now those are not used, but we'll switch to using them very soon as part of upcoming changes of how we build the components we test in our CI. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- tools/packaging/scripts/lib.sh | 21 +++++++++++++++++++ .../static-build/cache_components_main.sh | 16 +++++++++++++- .../packaging/static-build/virtiofsd/build.sh | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/packaging/scripts/lib.sh b/tools/packaging/scripts/lib.sh index 61776bcbf..c42534108 100644 --- a/tools/packaging/scripts/lib.sh +++ b/tools/packaging/scripts/lib.sh @@ -180,3 +180,24 @@ get_shim_v2_image_name() { shim_v2_script_dir="${repo_root_dir}/tools/packaging/static-build/shim-v2" echo "${BUILDER_REGISTRY}:shim-v2-go-$(get_from_kata_deps "languages.golang.meta.newest-version")-rust-$(get_from_kata_deps "languages.rust.meta.newest-version")-$(get_last_modification ${shim_v2_script_dir})-$(uname -m)" } + +get_virtiofsd_image_name() { + ARCH=$(uname -m) + case ${ARCH} in + "aarch64") + libc="musl" + ;; + "ppc64le") + libc="gnu" + ;; + "s390x") + libc="gnu" + ;; + "x86_64") + libc="musl" + ;; + esac + + virtiofsd_script_dir="${repo_root_dir}/tools/packaging/static-build/virtiofsd" + echo "${BUILDER_REGISTRY}:virtiofsd-$(get_from_kata_deps "externals.virtiofsd.toolchain")-${libc}-$(get_last_modification ${virtiofsd_script_dir})-$(uname -m)" +} diff --git a/tools/packaging/static-build/cache_components_main.sh b/tools/packaging/static-build/cache_components_main.sh index ef9cf6b9c..e447ab4bf 100755 --- a/tools/packaging/static-build/cache_components_main.sh +++ b/tools/packaging/static-build/cache_components_main.sh @@ -74,6 +74,13 @@ cache_shim_v2_artifacts() { create_cache_asset "${shim_v2_tarball_name}" "${current_shim_v2_version}" "${current_shim_v2_image}" } +cache_virtiofsd_artifacts() { + local virtiofsd_tarball_name="kata-static-virtiofsd.tar.xz" + local current_virtiofsd_version="$(get_from_kata_deps "externals.virtiofsd.version")-$(get_from_kata_deps "externals.virtiofsd.toolchain")" + local current_virtiofsd_image="$(get_virtiofsd_image_name)" + create_cache_asset "${virtiofsd_tarball_name}" "${current_virtiofsd_version}" "${current_virtiofsd_image}" +} + create_cache_asset() { local component_name="${1}" local component_version="${2}" @@ -106,6 +113,7 @@ Usage: $0 "[options]" * Export ROOTFS_IMAGE_TYPE="image|initrd" for one of those two types The default ROOTFS_IMAGE_TYPE value is "image" -s Shim v2 cache + -v VirtioFS cache -h Shows help EOF )" @@ -119,8 +127,9 @@ main() { local qemu_component="${qemu_component:-}" local rootfs_component="${rootfs_component:-}" local shim_v2_component="${shim_v2_component:-}" + local virtiofsd_component="${virtiofsd_component:-}" local OPTIND - while getopts ":cFknqrsh:" opt + while getopts ":cFknqrsvh:" opt do case "$opt" in c) @@ -144,6 +153,9 @@ main() { s) shim_v2_component="1" ;; + v) + virtiofsd_component="1" + ;; h) help exit 0; @@ -164,6 +176,7 @@ main() { [[ -z "${qemu_component}" ]] && \ [[ -z "${rootfs_component}" ]] && \ [[ -z "${shim_v2_component}" ]] && \ + [[ -z "${virtiofsd_component}" ]] && \ help && die "Must choose at least one option" mkdir -p "${WORKSPACE}/artifacts" @@ -177,6 +190,7 @@ main() { [ "${qemu_component}" == "1" ] && cache_qemu_artifacts [ "${rootfs_component}" == "1" ] && cache_rootfs_artifacts [ "${shim_v2_component}" == "1" ] && cache_shim_v2_artifacts + [ "${virtiofsd_component}" == "1" ] && cache_virtiofsd_artifacts ls -la "${WORKSPACE}/artifacts/" popd diff --git a/tools/packaging/static-build/virtiofsd/build.sh b/tools/packaging/static-build/virtiofsd/build.sh index 68b335821..6eb5ad51b 100755 --- a/tools/packaging/static-build/virtiofsd/build.sh +++ b/tools/packaging/static-build/virtiofsd/build.sh @@ -48,7 +48,7 @@ case ${ARCH} in ;; esac -container_image="${VIRTIOFSD_CONTAINER_BUILDER:-${BUILDER_REGISTRY}:virtiofsd-${virtiofsd_toolchain}-${libc}-$(get_last_modification ${script_dir})-$(uname -m)}" +container_image="${VIRTIOFSD_CONTAINER_BUILDER:-$(get_virtiofsd_image_name)}" sudo docker pull ${container_image} || \ (sudo docker build \ From 8a40f6f23498bcfec6c0a2ebd4f7a1e47f2e1023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:32:38 +0100 Subject: [PATCH 10/18] local-build: Use cached Cloud Hypervisor when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've added the support for caching components, let's use them whenever those are available. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../local-build/dockerbuild/Dockerfile | 1 + .../local-build/kata-deploy-binaries.sh | 54 +++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/tools/packaging/kata-deploy/local-build/dockerbuild/Dockerfile b/tools/packaging/kata-deploy/local-build/dockerbuild/Dockerfile index 2ff5f5ae8..1338f482a 100644 --- a/tools/packaging/kata-deploy/local-build/dockerbuild/Dockerfile +++ b/tools/packaging/kata-deploy/local-build/dockerbuild/Dockerfile @@ -43,6 +43,7 @@ RUN apt-get update && \ git \ make \ unzip \ + wget \ xz-utils && \ apt-get clean && rm -rf /var/lib/apt/lists 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 79cf5a141..8b4361097 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -32,6 +32,9 @@ readonly nydus_builder="${static_build_dir}/nydus/build.sh" readonly rootfs_builder="${repo_root_dir}/tools/packaging/guest-image/build_image.sh" +readonly jenkins_url="http://jenkins.katacontainers.io" +readonly cached_artifacts_path="lastSuccessfulBuild/artifact/artifacts" + ARCH=$(uname -m) workdir="${WORKDIR:-$PWD}" @@ -87,6 +90,34 @@ EOF exit "${return_code}" } + +cleanup_and_fail() { + rm -f "${component_tarball_path}" + return 1 +} + +install_cached_tarball_component() { + local component="${1}" + local jenkins_build_url="${2}" + local current_version="${3}" + local current_image_version="${4}" + local component_tarball_name="${5}" + local component_tarball_path="${6}" + + local cached_version=$(curl -sfL "${jenkins_build_url}/latest" | awk '{print $1}') || cached_version="none" + local cached_image_version=$(curl -sfL "${jenkins_build_url}/latest_image" | awk '{print $1}') || cached_image_version="none" + + [ "${cached_image_version}" != "${current_image_version}" ] && return 1 + [ "${cached_version}" != "${current_version}" ] && return 1 + + info "Using cached tarball of ${component}" + echo "Downloading tarball from: ${jenkins_build_url}/${component_tarball_name}" + wget "${jenkins_build_url}/${component_tarball_name}" || return cleanup_and_fail + wget "${jenkins_build_url}/sha256sum-${component_tarball_name}" || return cleanup_and_fail + sha256sum -c "sha256sum-${component_tarball_name}" || return cleanup_and_fail + mv "${component_tarball_name}" "${component_tarball_path}" +} + #Install guest image install_image() { info "Create image" @@ -142,6 +173,15 @@ install_firecracker() { # Install static cloud-hypervisor asset install_clh() { + install_cached_tarball_component \ + "cloud-hypervisor" \ + "${jenkins_url}/job/kata-containers-main-clh-$(uname -m)/${cached_artifacts_path}" \ + "$(get_from_kata_deps "assets.hypervisor.cloud_hypervisor.version")" \ + "" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + if [[ "${ARCH}" == "x86_64" ]]; then export features="tdx" fi @@ -192,6 +232,11 @@ handle_build() { info "DESTDIR ${destdir}" local build_target build_target="$1" + + export final_tarball_path="${workdir}/kata-static-${build_target}.tar.xz" + export final_tarball_name="$(basename ${final_tarball_path})" + rm -f ${final_tarball_name} + case "${build_target}" in all) install_clh @@ -232,12 +277,11 @@ handle_build() { ;; esac - tarball_name="${workdir}/kata-static-${build_target}.tar.xz" - ( + if [ ! -f "${final_tarball_path}" ]; then cd "${destdir}" - sudo tar cvfJ "${tarball_name}" "." - ) - tar tvf "${tarball_name}" + sudo tar cvfJ "${final_tarball_path}" "." + fi + tar tvf "${final_tarball_path}" } silent_mode_error_trap() { From 04fb52f6c9ab88802971c66301aee2b20224f212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:37:07 +0100 Subject: [PATCH 11/18] local-build: Use cached Firecracker when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've added the support for caching components, let's use them whenever those are available. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../kata-deploy/local-build/kata-deploy-binaries.sh | 9 +++++++++ 1 file changed, 9 insertions(+) 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 8b4361097..700a550d8 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -163,6 +163,15 @@ install_qemu() { # Install static firecracker asset install_firecracker() { + install_cached_tarball_component \ + "firecracker" \ + "${jenkins_url}/job/kata-containers-main-firecracker-$(uname -m)/${cached_artifacts_path}" \ + "$(get_from_kata_deps "assets.hypervisor.firecracker.version")" \ + "" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + info "build static firecracker" "${firecracker_builder}" info "Install static firecracker" From 64832ab65b353ab9f7ce07f2950b0e3ad368438d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:42:15 +0100 Subject: [PATCH 12/18] local-build: Use cached Kernel when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've added the support for caching components, let's use them whenever those are available. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../local-build/kata-deploy-binaries.sh | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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 700a550d8..647fd2b68 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -133,6 +133,17 @@ install_initrd() { #Install kernel asset install_kernel() { export kernel_version="$(yq r $versions_yaml assets.kernel.version)" + local kernel_kata_config_version="$(cat ${repo_root_dir}/tools/packaging/kernel/kata_config_version)" + + install_cached_tarball_component \ + "kernel" \ + "${jenkins_url}/job/kata-containers-main-kernel-$(uname -m)/${cached_artifacts_path}" \ + "${kernel_version}-${kernel_kata_config_version}" \ + "$(get_kernel_image_name)" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + DESTDIR="${destdir}" PREFIX="${prefix}" "${kernel_builder}" -f -v "${kernel_version}" } @@ -140,6 +151,17 @@ install_kernel() { install_dragonball_experimental_kernel() { info "build dragonball experimental kernel" export kernel_version="$(yq r $versions_yaml assets.kernel-dragonball-experimental.version)" + local kernel_kata_config_version="$(cat ${repo_root_dir}/tools/packaging/kernel/kata_config_version)" + + install_cached_tarball_component \ + "kernel-dragonball-experimental" \ + "${jenkins_url}/job/kata-containers-main-kernel-dragonball-experimental-$(uname -m)/${cached_artifacts_path}" \ + "${kernel_version}-${kernel_kata_config_version}" \ + "$(get_kernel_image_name)" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + info "kernel version ${kernel_version}" DESTDIR="${destdir}" PREFIX="${prefix}" "${kernel_builder}" -e -t dragonball -v ${kernel_version} } @@ -148,6 +170,17 @@ install_dragonball_experimental_kernel() { install_experimental_kernel() { info "build experimental kernel" export kernel_version="$(yq r $versions_yaml assets.kernel-experimental.tag)" + local kernel_kata_config_version="$(cat ${repo_root_dir}/tools/packaging/kernel/kata_config_version)" + + install_cached_tarball_component \ + "kernel-experimental" \ + "${jenkins_url}/job/kata-containers-main-kernel-experimental-$(uname -m)/${cached_artifacts_path}" \ + "${kernel_version}-${kernel_kata_config_version}" \ + "$(get_kernel_image_name)" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + info "Kernel version ${kernel_version}" DESTDIR="${destdir}" PREFIX="${prefix}" "${kernel_builder}" -f -b experimental -v ${kernel_version} } From 1e1c843b8b65dc463a6b57e16501a79b7ea6177c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:45:37 +0100 Subject: [PATCH 13/18] local-build: Use cached Nydus when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've added the support for caching components, let's use them whenever those are available. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../kata-deploy/local-build/kata-deploy-binaries.sh | 9 +++++++++ 1 file changed, 9 insertions(+) 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 647fd2b68..ccf419e6f 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -246,6 +246,15 @@ install_virtiofsd() { # Install static nydus asset install_nydus() { + install_cached_tarball_component \ + "nydus" \ + "${jenkins_url}/job/kata-containers-main-nydus-$(uname -m)/${cached_artifacts_path}" \ + "$(get_from_kata_deps "externals.nydus.version")" \ + "" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + info "build static nydus" "${nydus_builder}" info "Install static nydus" From 09ce4ab893b2dc33772fef7b8e8702000bbf0747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:48:22 +0100 Subject: [PATCH 14/18] local-build: Use cached QEMU when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've added the support for caching components, let's use them whenever those are available. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../kata-deploy/local-build/kata-deploy-binaries.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 ccf419e6f..45b29afb6 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -187,9 +187,19 @@ install_experimental_kernel() { # Install static qemu asset install_qemu() { - info "build static qemu" export qemu_repo="$(yq r $versions_yaml assets.hypervisor.qemu.url)" export qemu_version="$(yq r $versions_yaml assets.hypervisor.qemu.version)" + + install_cached_tarball_component \ + "QEMU" \ + "${jenkins_url}/job/kata-containers-main-qemu-$(uname -m)/${cached_artifacts_path}" \ + "${qemu_version}-$(calc_qemu_files_sha256sum)" \ + "$(get_qemu_image_name)" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + + info "build static qemu" "${qemu_builder}" tar xvf "${builddir}/kata-static-qemu.tar.gz" -C "${destdir}" } From 1b8c5474dab15246914b5ad631d1ce5aaf515eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:54:32 +0100 Subject: [PATCH 15/18] local-build: Use cached RootFS when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've added the support for caching components, let's use them whenever those are available. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../local-build/kata-deploy-binaries.sh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) 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 45b29afb6..9074b76d2 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -120,12 +120,52 @@ install_cached_tarball_component() { #Install guest image install_image() { + local jenkins="${jenkins_url}/job/kata-containers-main-rootfs-image-$(uname -m)/${cached_artifacts_path}" + local component="rootfs-image" + + local osbuilder_last_commit="$(get_last_modification "${repo_root_dir}/tools/osbuilder")" + local guest_image_last_commit="$(get_last_modification "${repo_root_dir}/tools/packaging/guest-image")" + local agent_last_commit="$(get_last_modification "${repo_root_dir}/src/agent")" + local libs_last_commit="$(get_last_modification "${repo_root_dir}/src/libs")" + local gperf_version="$(get_from_kata_deps "externals.gperf.version")" + local libseccomp_version="$(get_from_kata_deps "externals.libseccomp.version")" + local rust_version="$(get_from_kata_deps "languages.rust.meta.newest-version")" + + install_cached_tarball_component \ + "${component}" \ + "${jenkins}" \ + "${osbuilder_last_commit}-${guest_image_last_commit}-${agent_last_commit}-${libs_last_commit}-${gperf_version}-${libseccomp_version}-${rust_version}-image" \ + "" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + info "Create image" "${rootfs_builder}" --imagetype=image --prefix="${prefix}" --destdir="${destdir}" } #Install guest initrd install_initrd() { + local jenkins="${jenkins_url}/job/kata-containers-main-rootfs-initrd-$(uname -m)/${cached_artifacts_path}" + local component="rootfs-initrd" + + local osbuilder_last_commit="$(get_last_modification "${repo_root_dir}/tools/osbuilder")" + local guest_image_last_commit="$(get_last_modification "${repo_root_dir}/tools/packaging/guest-image")" + local agent_last_commit="$(get_last_modification "${repo_root_dir}/src/agent")" + local libs_last_commit="$(get_last_modification "${repo_root_dir}/src/libs")" + local gperf_version="$(get_from_kata_deps "externals.gperf.version")" + local libseccomp_version="$(get_from_kata_deps "externals.libseccomp.version")" + local rust_version="$(get_from_kata_deps "languages.rust.meta.newest-version")" + + install_cached_tarball_component \ + "${component}" \ + "${jenkins}" \ + "${osbuilder_last_commit}-${guest_image_last_commit}-${agent_last_commit}-${libs_last_commit}-${gperf_version}-${libseccomp_version}-${rust_version}-initrd" \ + "" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + info "Create initrd" "${rootfs_builder}" --imagetype=initrd --prefix="${prefix}" --destdir="${destdir}" } From 3b99004897749014e86d5d88a67820c2b0499494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 13:59:34 +0100 Subject: [PATCH 16/18] local-build: Use cached shim v2 when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've added the support for caching components, let's use them whenever those are available. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../local-build/kata-deploy-binaries.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 9074b76d2..545a6763a 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -316,8 +316,22 @@ install_nydus() { #Install all components that are not assets install_shimv2() { - GO_VERSION="$(yq r ${versions_yaml} languages.golang.meta.newest-version)" - RUST_VERSION="$(yq r ${versions_yaml} languages.rust.meta.newest-version)" + local shim_v2_last_commit="$(get_last_modification "${repo_root_dir}/src/runtime")" + local runtime_rs_last_commit="$(get_last_modification "${repo_root_dir}/src/runtime-rs")" + local protocols_last_commit="$(get_last_modification "${repo_root_dir}/src/libs/protocols")" + local GO_VERSION="$(get_from_kata_deps "languages.golang.meta.newest-version")" + local RUST_VERSION="$(get_from_kata_deps "languages.rust.meta.newest-version")" + local shim_v2_version="${shim_v2_last_commit}-${protocols_last_commit}-${runtime_rs_last_commit}-${GO_VERSION}-${RUST_VERSION}" + + install_cached_tarball_component \ + "shim-v2" \ + "${jenkins_url}/job/kata-containers-main-shim-v2-$(uname -m)/${cached_artifacts_path}" \ + "${shim_v2_version}" \ + "$(get_shim_v2_image_name)" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + export GO_VERSION export RUST_VERSION DESTDIR="${destdir}" PREFIX="${prefix}" "${shimv2_builder}" From 82a04dbce179fe9b4f767cb889fe730e3130a03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 16 Mar 2023 14:02:03 +0100 Subject: [PATCH 17/18] local-build: Use cached VirtioFS when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we've added the support for caching components, let's use them whenever those are available. Fixes: #6480 Signed-off-by: Fabiano Fidêncio Signed-off-by: Gabriela Cervantes --- .../kata-deploy/local-build/kata-deploy-binaries.sh | 9 +++++++++ 1 file changed, 9 insertions(+) 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 545a6763a..0d5ef611c 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh @@ -287,6 +287,15 @@ install_clh() { # Install static virtiofsd asset install_virtiofsd() { + install_cached_tarball_component \ + "virtiofsd" \ + "${jenkins_url}/job/kata-containers-main-virtiofsd-$(uname -m)/${cached_artifacts_path}" \ + "$(get_from_kata_deps "externals.virtiofsd.version")-$(get_from_kata_deps "externals.virtiofsd.toolchain")" \ + "$(get_virtiofsd_image_name)" \ + "${final_tarball_name}" \ + "${final_tarball_path}" \ + && return 0 + info "build static virtiofsd" "${virtiofsd_builder}" info "Install static virtiofsd" From fbf891fdfff5c83780a5ca61adad4423e850117a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Fri, 17 Mar 2023 10:41:04 +0100 Subject: [PATCH 18/18] packaging: Adapt `get_last_modification()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function is returning "" when called from the script used to cache the artefacts and one difference noted between this version and the already working one from the CCv0 is that we make sure to `pushd ${repo_root_dir}` in the CCv0 version. Let's give it a try here and see if it solves the issue. Signed-off-by: Fabiano Fidêncio --- tools/packaging/scripts/lib.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/packaging/scripts/lib.sh b/tools/packaging/scripts/lib.sh index c42534108..aa101b870 100644 --- a/tools/packaging/scripts/lib.sh +++ b/tools/packaging/scripts/lib.sh @@ -106,6 +106,7 @@ get_kata_hash() { get_last_modification() { local file="${1}" + pushd ${repo_root_dir} &> /dev/null # This is a workaround needed for when running this code on Jenkins git config --global --add safe.directory ${repo_root_dir} &> /dev/null @@ -113,6 +114,7 @@ get_last_modification() { [ $(git status --porcelain | grep "${file#${repo_root_dir}/}" | wc -l) -gt 0 ] && dirty="-dirty" echo "$(git log -1 --pretty=format:"%H" ${file})${dirty}" + popd &> /dev/null } # $1 - The tag to be pushed to the registry