forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_components_main.sh
executable file
·261 lines (235 loc) · 9.7 KB
/
cache_components_main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/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"
KERNEL_FLAVOUR="${KERNEL_FLAVOUR:-kernel}" # kernel | kernel-nvidia-gpu | kernel-experimental | kernel-arm-experimental | kernel-dragonball-experimental | kernel-tdx-experimental | kernel-nvidia-gpu-tdx-experimental | kernel-nvidia-gpu-snp
OVMF_FLAVOUR="${OVMF_FLAVOUR:-x86_64}" # x86_64 | tdx
QEMU_FLAVOUR="${QEMU_FLAVOUR:-qemu}" # qemu | qemu-tdx-experimental | qemu-snp-experimental
ROOTFS_IMAGE_TYPE="${ROOTFS_IMAGE_TYPE:-image}" # image | initrd
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}" ""
}
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}" ""
}
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 kernel_modules_tarball_path="${repo_root_dir}/tools/packaging/kata-deploy/local-build/build/kata-static-kernel-sev-modules.tar.xz"
# The ${vendor}-gpu kernels are based on an already existing entry, and does not require
# adding a new entry to the versions.yaml.
#
# With this in mind, let's just make sure we get the version from correct entry in the
# versions.yaml file.
case ${KERNEL_FLAVOUR} in
*"nvidia-gpu"*)
KERNEL_FLAVOUR=${KERNEL_FLAVOUR//"-nvidia-gpu"/}
;;
*)
;;
esac
case ${KERNEL_FLAVOUR} in
"kernel-sev"|"kernel-snp")
# In these cases, like "kernel-foo", it must be set to "kernel.foo" when looking at
# the versions.yaml file
current_kernel_version="$(get_from_kata_deps "assets.${KERNEL_FLAVOUR/-/.}.version")"
;;
*)
current_kernel_version="$(get_from_kata_deps "assets.${KERNEL_FLAVOUR}.version")"
;;
esac
create_cache_asset "${kernel_tarball_name}" "${current_kernel_version}-${current_kernel_kata_config_version}" "${current_kernel_image}"
if [[ "${KERNEL_FLAVOUR}" == "kernel-sev" ]]; then
module_dir="${repo_root_dir}/tools/packaging/kata-deploy/local-build/build/kernel-sev/builddir/kata-linux-${current_kernel_version#v}-${current_kernel_kata_config_version}/lib/modules/${current_kernel_version#v}"
if [ ! -f "${kernel_modules_tarball_path}" ]; then
tar cvfJ "${kernel_modules_tarball_path}" "${module_dir}/kernel/drivers/virt/coco/efi_secret/"
fi
create_cache_asset "kata-static-kernel-sev-modules.tar.xz" "${current_kernel_version}-${current_kernel_kata_config_version}" "${current_kernel_image}"
fi
}
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}" ""
}
cache_ovmf_artifacts() {
local current_ovmf_version="$(get_from_kata_deps "externals.ovmf.${OVMF_FLAVOUR}.version")"
case ${OVMF_FLAVOUR} in
"tdx")
ovmf_tarball_name="kata-static-tdvf.tar.xz"
;;
"x86_64")
ovmf_tarball_name="kata-static-ovmf.tar.xz"
;;
*)
ovmf_tarball_name="kata-static-ovmf-${OVMF_FLAVOUR}.tar.xz"
;;
esac
local current_ovmf_image="$(get_ovmf_image_name)"
create_cache_asset "${ovmf_tarball_name}" "${current_ovmf_version}" "${current_ovmf_image}"
}
cache_qemu_artifacts() {
local qemu_tarball_name="kata-static-${QEMU_FLAVOUR}.tar.xz"
local current_qemu_version=$(get_from_kata_deps "assets.hypervisor.${QEMU_FLAVOUR}.version")
[ -z "${current_qemu_version}" ] && current_qemu_version=$(get_from_kata_deps "assets.hypervisor.${QEMU_FLAVOUR}.tag")
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}"
}
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}" ""
}
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}"
}
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}"
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
-F Firecracker cache
-k Kernel cache
* Export KERNEL_FLAVOUR="kernel | kernel-nvidia-gpu | kernel-experimental | kernel-arm-experimental | kernel-dragonball-experimental | kernel-tdx-experimental | kernel-nvidia-gpu-tdx-experimental | kernel-nvidia-gpu-snp" for a specific build
The default KERNEL_FLAVOUR value is "kernel"
-n Nydus cache
-q QEMU cache
* Export QEMU_FLAVOUR="qemu | qemu-tdx-experimental | qemu-snp-experimental" for a specific build
The default QEMU_FLAVOUR value is "qemu"
-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
-v VirtioFS cache
-h Shows help
EOF
)"
}
main() {
local cloud_hypervisor_component="${cloud_hypervisor_component:-}"
local firecracker_component="${firecracker_component:-}"
local kernel_component="${kernel_component:-}"
local nydus_component="${nydus_component:-}"
local ovmf_component="${ovmf_component:-}"
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 ":cFknoqrsvh:" opt
do
case "$opt" in
c)
cloud_hypervisor_component="1"
;;
F)
firecracker_component="1"
;;
k)
kernel_component="1"
;;
n)
nydus_component="1"
;;
o)
ovmf_component="1"
;;
q)
qemu_component="1"
;;
r)
rootfs_component="1"
;;
s)
shim_v2_component="1"
;;
v)
virtiofsd_component="1"
;;
h)
help
exit 0;
;;
:)
echo "Missing argument for -$OPTARG";
help
exit 1;
;;
esac
done
shift $((OPTIND-1))
[[ -z "${cloud_hypervisor_component}" ]] && \
[[ -z "${firecracker_component}" ]] && \
[[ -z "${kernel_component}" ]] && \
[[ -z "${nydus_component}" ]] && \
[[ -z "${ovmf_component}" ]] && \
[[ -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"
pushd "${WORKSPACE}/artifacts"
echo "Artifacts:"
[ "${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
[ "${ovmf_component}" == "1" ] && cache_ovmf_artifacts
[ "${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
sync
}
main "$@"