kata-deploy: enable cross build for kata deploy script

kata-deploy-binaries-in-docker.sh is the entry to build kata components.
set some environment to facilitate the following cross build work.

Fixes: #6557
Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
This commit is contained in:
Jianyong Wu 2023-07-24 16:06:22 +08:00 committed by Fabiano Fidêncio
parent 2fc5f0e2e0
commit e2c31fce23
2 changed files with 33 additions and 7 deletions

View File

@ -19,6 +19,29 @@ gid=$(id -g ${USER})
http_proxy="${http_proxy:-}" http_proxy="${http_proxy:-}"
https_proxy="${https_proxy:-}" https_proxy="${https_proxy:-}"
ARCH=${ARCH:-$(uname -m)}
CROSS_BUILD=
BUILDX=""
PLATFORM=""
TARGET_ARCH=${TARGET_ARCH:-$(uname -m)}
[ "$(uname -m)" != "${TARGET_ARCH}" ] && CROSS_BUILD=true
[ "${TARGET_ARCH}" == "aarch64" ] && TARGET_ARCH=arm64
# used for cross build
TARGET_OS=${TARGET_OS:-linux}
TARGET_ARCH=${TARGET_ARCH:-$ARCH}
[ "${CROSS_BUILD}" == "true" ] && BUILDX="buildx" && PLATFORM="--platform=${TARGET_OS}/${TARGET_ARCH}"
if [ "${CROSS_BUILD}" == "true" ]; then
# check if the current docker support docker buildx
docker buildx ls > /dev/null 2>&1 || true
[ $? != 0 ] && echo "no docker buildx support, please upgrad your docker" && exit 1
# check if docker buildx support target_arch, if not install it
r=$(docker buildx ls | grep "${TARGET_ARCH}" || true)
[ -z "$r" ] && sudo docker run --privileged --rm tonistiigi/binfmt --install ${TARGET_ARCH}
fi
if [ "${script_dir}" != "${PWD}" ]; then if [ "${script_dir}" != "${PWD}" ]; then
ln -sf "${script_dir}/build" "${PWD}/build" ln -sf "${script_dir}/build" "${PWD}/build"
fi fi
@ -66,6 +89,9 @@ docker run \
--env VIRTIOFSD_CONTAINER_BUILDER="${VIRTIOFSD_CONTAINER_BUILDER:-}" \ --env VIRTIOFSD_CONTAINER_BUILDER="${VIRTIOFSD_CONTAINER_BUILDER:-}" \
--env MEASURED_ROOTFS="${MEASURED_ROOTFS:-}" \ --env MEASURED_ROOTFS="${MEASURED_ROOTFS:-}" \
--env USE_CACHE="${USE_CACHE:-}" \ --env USE_CACHE="${USE_CACHE:-}" \
--env CROSS_BUILD="${CROSS_BUILD}" \
--env TARGET_ARCH="${TARGET_ARCH}" \
--env ARCH="${ARCH}" \
--rm \ --rm \
-w ${script_dir} \ -w ${script_dir} \
build-kata-deploy "${kata_deploy_create}" $@ build-kata-deploy "${kata_deploy_create}" $@

View File

@ -38,7 +38,7 @@ readonly rootfs_builder="${repo_root_dir}/tools/packaging/guest-image/build_imag
readonly jenkins_url="http://jenkins.katacontainers.io" readonly jenkins_url="http://jenkins.katacontainers.io"
readonly cached_artifacts_path="lastSuccessfulBuild/artifact/artifacts" readonly cached_artifacts_path="lastSuccessfulBuild/artifact/artifacts"
ARCH=$(uname -m) ARCH=${ARCH:-$(uname -m)}
MEASURED_ROOTFS=${MEASURED_ROOTFS:-no} MEASURED_ROOTFS=${MEASURED_ROOTFS:-no}
USE_CACHE="${USE_CACHE:-"yes"}" USE_CACHE="${USE_CACHE:-"yes"}"
@ -150,7 +150,7 @@ install_image() {
image_type+="-${variant}" image_type+="-${variant}"
fi fi
local jenkins="${jenkins_url}/job/kata-containers-main-rootfs-${image_type}-$(uname -m)/${cached_artifacts_path}" local jenkins="${jenkins_url}/job/kata-containers-main-rootfs-${image_type}-${ARCH}/${cached_artifacts_path}"
local component="rootfs-${image_type}" local component="rootfs-${image_type}"
local osbuilder_last_commit="$(get_last_modification "${repo_root_dir}/tools/osbuilder")" local osbuilder_last_commit="$(get_last_modification "${repo_root_dir}/tools/osbuilder")"
@ -197,7 +197,7 @@ install_initrd() {
initrd_type+="-${variant}" initrd_type+="-${variant}"
fi fi
local jenkins="${jenkins_url}/job/kata-containers-main-rootfs-${initrd_type}-$(uname -m)/${cached_artifacts_path}" local jenkins="${jenkins_url}/job/kata-containers-main-rootfs-${initrd_type}-${ARCH}/${cached_artifacts_path}"
local component="rootfs-${initrd_type}" local component="rootfs-${initrd_type}"
local osbuilder_last_commit="$(get_last_modification "${repo_root_dir}/tools/osbuilder")" local osbuilder_last_commit="$(get_last_modification "${repo_root_dir}/tools/osbuilder")"
@ -247,7 +247,7 @@ install_cached_kernel_tarball_component() {
install_cached_tarball_component \ install_cached_tarball_component \
"${kernel_name}" \ "${kernel_name}" \
"${jenkins_url}/job/kata-containers-main-${kernel_name}-$(uname -m)/${cached_artifacts_path}" \ "${jenkins_url}/job/kata-containers-main-${kernel_name}-${ARCH}/${cached_artifacts_path}" \
"${kernel_version}-${kernel_kata_config_version}-$(get_last_modification $(dirname $kernel_builder))" \ "${kernel_version}-${kernel_kata_config_version}-$(get_last_modification $(dirname $kernel_builder))" \
"$(get_kernel_image_name)" \ "$(get_kernel_image_name)" \
"${final_tarball_name}" \ "${final_tarball_name}" \
@ -384,7 +384,7 @@ install_qemu_helper() {
install_cached_tarball_component \ install_cached_tarball_component \
"${qemu_name}" \ "${qemu_name}" \
"${jenkins_url}/job/kata-containers-main-${qemu_name}-$(uname -m)/${cached_artifacts_path}" \ "${jenkins_url}/job/kata-containers-main-${qemu_name}-${ARCH}/${cached_artifacts_path}" \
"${qemu_version}-$(calc_qemu_files_sha256sum)" \ "${qemu_version}-$(calc_qemu_files_sha256sum)" \
"$(get_qemu_image_name)" \ "$(get_qemu_image_name)" \
"${final_tarball_name}" \ "${final_tarball_name}" \
@ -495,7 +495,7 @@ install_clh_glibc() {
install_virtiofsd() { install_virtiofsd() {
install_cached_tarball_component \ install_cached_tarball_component \
"virtiofsd" \ "virtiofsd" \
"${jenkins_url}/job/kata-containers-main-virtiofsd-$(uname -m)/${cached_artifacts_path}" \ "${jenkins_url}/job/kata-containers-main-virtiofsd-${ARCH}/${cached_artifacts_path}" \
"$(get_from_kata_deps "externals.virtiofsd.version")-$(get_from_kata_deps "externals.virtiofsd.toolchain")" \ "$(get_from_kata_deps "externals.virtiofsd.version")-$(get_from_kata_deps "externals.virtiofsd.toolchain")" \
"$(get_virtiofsd_image_name)" \ "$(get_virtiofsd_image_name)" \
"${final_tarball_name}" \ "${final_tarball_name}" \
@ -542,7 +542,7 @@ install_shimv2() {
install_cached_tarball_component \ install_cached_tarball_component \
"shim-v2" \ "shim-v2" \
"${jenkins_url}/job/kata-containers-main-shim-v2-$(uname -m)/${cached_artifacts_path}" \ "${jenkins_url}/job/kata-containers-main-shim-v2-${ARCH}/${cached_artifacts_path}" \
"${shim_v2_version}" \ "${shim_v2_version}" \
"$(get_shim_v2_image_name)" \ "$(get_shim_v2_image_name)" \
"${final_tarball_name}" \ "${final_tarball_name}" \