mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 04:04:45 +00:00
tools: Add support for caching QEMU artefacts
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 <fabiano.fidencio@intel.com> Signed-off-by: Gabriela Cervantes <gabriela.cervantes.tellez@intel.com>
This commit is contained in:
parent
7aed8f8c80
commit
e90891059b
@ -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)"
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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}" \
|
||||
|
Loading…
Reference in New Issue
Block a user