tools: Add support for caching Cloud Hypervisor artefacts

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 <fabiano.fidencio@intel.com>
Signed-off-by: Gabriela Cervantes <gabriela.cervantes.tellez@intel.com>
This commit is contained in:
Fabiano Fidêncio 2023-03-16 12:36:21 +01:00
parent 08fe49f708
commit 6b1b424fc7

View File

@ -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 "$@"