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] 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 0000000000..b6780e9359 --- /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 "$@"