From 01df3c1d5e82859bba1749965a820a219f162204 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Fri, 18 Sep 2020 21:29:11 -0700 Subject: [PATCH] packaging: Build from source if the clh release binary is missing This patch add fall-back code path that builds cloud-hypervisor static binary from source, when the downloading of cloud-hypervisor binary is failing. This is useful when we experience network issues, and also useful for upgrading clh to non-released version. Together with the changes in the tests repo (https://github.com/kata-containers/tests/pull/2862), the Jenkins config file is also updated with new Execute shell script for the clh CI in the kata-containers repo. Those two changes fix the regression on clh CI here. Please check details in the issue below. Fixes: #781 Fixes: https://github.com/kata-containers/tests/issues/2858 Signed-off-by: Bo Chen --- .../cloud-hypervisor/build-static-clh.sh | 27 ++++++++++++-- .../cloud-hypervisor/docker-build/Dockerfile | 12 ------- .../cloud-hypervisor/docker-build/build.sh | 36 ------------------- 3 files changed, 24 insertions(+), 51 deletions(-) delete mode 100644 tools/packaging/static-build/cloud-hypervisor/docker-build/Dockerfile delete mode 100755 tools/packaging/static-build/cloud-hypervisor/docker-build/build.sh diff --git a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh index 6b029d1349..55db4f173c 100755 --- a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh +++ b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh @@ -18,7 +18,28 @@ cloud_hypervisor_version="${cloud_hypervisor_version:-}" [ -n "$cloud_hypervisor_version" ] || cloud_hypervisor_version=$(get_from_kata_deps "assets.hypervisor.cloud_hypervisor.version" "${kata_version}") [ -n "$cloud_hypervisor_version" ] || die "failed to get cloud_hypervisor version" -info "Download cloud-hypervisor version: ${cloud_hypervisor_version}" -cloud_hypervisor_binary="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/${cloud_hypervisor_version}/cloud-hypervisor-static" +pull_clh_released_binary() { + info "Download cloud-hypervisor version: ${cloud_hypervisor_version}" + cloud_hypervisor_binary="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/${cloud_hypervisor_version}/cloud-hypervisor-static" -curl --fail -L ${cloud_hypervisor_binary} -o cloud-hypervisor + curl --fail -L ${cloud_hypervisor_binary} -o cloud-hypervisor || return 1 +} + +build_clh_from_source() { + info "Build ${cloud_hypervisor_repo} version: ${cloud_hypervisor_version}" + repo_dir=$(basename "${cloud_hypervisor_repo}") + repo_dir="${repo_dir//.git}" + [ -d "${repo_dir}" ] || git clone "${cloud_hypervisor_repo}" + pushd "${repo_dir}" + git fetch || true + git checkout "${cloud_hypervisor_version}" + ./scripts/dev_cli.sh build --release --libc musl + rm -f cloud-hypervisor + cp build/cargo_target/$(uname -m)-unknown-linux-musl/release/cloud-hypervisor . + popd +} + +if ! pull_clh_released_binary; then + info "failed to pull cloud-hypervisor released binary, trying to build from source" + build_clh_from_source +fi diff --git a/tools/packaging/static-build/cloud-hypervisor/docker-build/Dockerfile b/tools/packaging/static-build/cloud-hypervisor/docker-build/Dockerfile deleted file mode 100644 index 78aaa2b386..0000000000 --- a/tools/packaging/static-build/cloud-hypervisor/docker-build/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) 2019 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -FROM ubuntu:18.04 - -RUN apt-get update -RUN apt-get --no-install-recommends install -yq apt-utils ca-certificates build-essential mtools libssl-dev pkg-config curl git -RUN nohup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc -ENV PATH="/root/.cargo/bin:${PATH}" diff --git a/tools/packaging/static-build/cloud-hypervisor/docker-build/build.sh b/tools/packaging/static-build/cloud-hypervisor/docker-build/build.sh deleted file mode 100755 index f7e3e988ab..0000000000 --- a/tools/packaging/static-build/cloud-hypervisor/docker-build/build.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2019 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -set -o errexit -set -o nounset -set -o pipefail - -script_dir=$(dirname $(readlink -f "$0")) -docker_image="cloud-hypervisor-builder" - -DOCKER_CLI="docker" - -if ! command -v docker && command -v podman; then - DOCKER_CLI="podman" -fi - -sudo "${DOCKER_CLI}" build -t "${docker_image}" "${script_dir}" - -if test -t 1; then - USE_TTY="-ti" -else - USE_TTY="" - echo "INFO: not tty build" -fi - -sudo "${DOCKER_CLI}" run \ - --rm \ - -v "$(pwd):/$(pwd)" \ - -w "$(pwd)" \ - --env "CARGO_HOME=$(pwd)" \ - ${USE_TTY} \ - "${docker_image}" \ - cargo build --release