From 62c865c45d8128c90bc8ea17ec3061941146b21f Mon Sep 17 00:00:00 2001 From: ChengyuZhu6 Date: Mon, 11 Sep 2023 18:34:23 +0800 Subject: [PATCH] ci: install nydus snapshotter nydus-snapshotter / nydusd are required for the CoCo effort. Signed-off-by: ChengyuZhu6 --- .ci/install_nydus_snapshotter.sh | 84 ++++++++++++++++++++++++++++++++ .ci/lib.sh | 12 +++++ .ci/setup.sh | 5 ++ 3 files changed, 101 insertions(+) create mode 100755 .ci/install_nydus_snapshotter.sh diff --git a/.ci/install_nydus_snapshotter.sh b/.ci/install_nydus_snapshotter.sh new file mode 100755 index 000000000..d82b1a527 --- /dev/null +++ b/.ci/install_nydus_snapshotter.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Copyright (c) 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +set -o errexit +set -o nounset +set -o pipefail +set -o errtrace + +cidir=$(dirname "$0") +source "${cidir}/lib.sh" + +target_dir="/usr/local/" + +nydus_snapshotter_repo=$(get_version "externals.nydus-snapshotter.url") +nydus_snapshotter_version=$(get_version "externals.nydus-snapshotter.version") +nydus_snapshotter_repo_dir="${GOPATH}/src/github.com/containerd/nydus-snapshotter" +nydus_snapshotter_binary_target_dir="${target_dir}/bin" +nydus_snapshotter_config_target_dir="${target_dir}/share/nydus-snapshotter" + +nydus_repo=${nydus_repo:-"https://github.com/dragonflyoss/image-service"} +nydus_version=${nydus_version:-"v2.2.3"} + +arch="$(uname -m)" + +clone_nydus_snapshotter_repo() { + add_repo_to_git_safe_directory "${nydus_snapshotter_repo_dir}" + + if [ ! -d "${nydus_snapshotter_repo_dir}" ]; then + mkdir -p "${nydus_snapshotter_repo_dir}" + git clone ${nydus_snapshotter_repo} "${nydus_snapshotter_repo_dir}" || true + pushd "${nydus_snapshotter_repo_dir}" + git checkout "${nydus_snapshotter_version}" + popd + fi +} + +build_nydus_snapshotter() { + pushd "${nydus_snapshotter_repo_dir}" + if [ "${arch}" = "s390x" ]; then + export GOARCH=${arch} + fi + make + + install -D -m 755 "bin/containerd-nydus-grpc" "${nydus_snapshotter_binary_target_dir}/containerd-nydus-grpc" + install -D -m 755 "bin/nydus-overlayfs" "${nydus_snapshotter_binary_target_dir}/nydus-overlayfs" + if [ ! -f "${target_dir}/bin/nydus-overlayfs" ]; then + echo " ${target_dir}/bin/nydus-overlayfs exists, now we will replace it." + sudo cp "${nydus_snapshotter_binary_target_dir}/nydus-overlayfs" "${target_dir}/bin/nydus-overlayfs" + fi + rm -rf "${nydus_snapshotter_repo_dir}/bin" + popd >/dev/null +} + +download_nydus_snapshotter_config() { + tmp_dir=$(mktemp -d -t install-nydus-snapshotter-config-tmp.XXXXXXXXXX) + curl -L https://raw.githubusercontent.com/containerd/nydus-snapshotter/${nydus_snapshotter_version}/misc/snapshotter/config-coco-guest-pulling.toml -o "${tmp_dir}/config-coco-guest-pulling.toml" + curl -L https://raw.githubusercontent.com/containerd/nydus-snapshotter/${nydus_snapshotter_version}/misc/snapshotter/config-coco-host-sharing.toml -o "${tmp_dir}/config-coco-host-sharing.toml" + sudo install -D -m 644 "${tmp_dir}/config-coco-guest-pulling.toml" "${nydus_snapshotter_config_target_dir}/config-coco-guest-pulling.toml" + sudo install -D -m 644 "${tmp_dir}/config-coco-host-sharing.toml" "${nydus_snapshotter_config_target_dir}/config-coco-host-sharing.toml" + +} + +download_nydus_from_tarball() { + if [ "${arch}" = "s390x" ]; then + echo "Skip to download nydus for ${arch}, it doesn't work for ${arch} now." + return + fi + local goarch="$(${cidir}/kata-arch.sh --golang)" + local tarball_url="${nydus_repo}/releases/download/${nydus_version}/nydus-static-${nydus_version}-linux-${goarch}.tgz" + echo "Download tarball from ${tarball_url}" + tmp_dir=$(mktemp -d -t install-nydus-tmp.XXXXXXXXXX) + curl -Ls "$tarball_url" | sudo tar xfz - -C ${tmp_dir} --strip-components=1 + sudo install -D -m 755 "${tmp_dir}/nydus-image" "${target_dir}/bin/" +} + +download_nydus_from_tarball +clone_nydus_snapshotter_repo +build_nydus_snapshotter +download_nydus_snapshotter_config +echo "install nydus-snapshotter successful" diff --git a/.ci/lib.sh b/.ci/lib.sh index 6de2dee64..9505aba8f 100755 --- a/.ci/lib.sh +++ b/.ci/lib.sh @@ -391,6 +391,15 @@ cleanup_network_interface() { [ "$CNI" != "" ] && info "$CNI doesn't clean up" } +cleanup_nydus_snapshotter_dependencies() { + if [ -f "/usr/local/bin/nydus-overlayfs" ]; then + rm -f "/usr/local/bin/nydus-overlayfs" + fi + if [ -f "/usr/local/bin/nydus-image" ]; then + rm -f "/usr/local/bin/nydus-image" + fi +} + gen_clean_arch() { # For metrics CI we are removing unnecessary steps like # removing packages, removing CRI-O, etc mainly because @@ -412,6 +421,9 @@ gen_clean_arch() { fi fi + info "remove nydus snapshotter dependencies" + cleanup_nydus_snapshotter_dependencies + info "remove containers started by ctr" clean_env_ctr diff --git a/.ci/setup.sh b/.ci/setup.sh index 71cb314db..bef8fb041 100755 --- a/.ci/setup.sh +++ b/.ci/setup.sh @@ -135,6 +135,11 @@ install_extra_tools() { fi fi + if [ "${IMAGE_OFFLOAD_TO_GUEST}" == "yes" ]; then + info "Install nydus-snapshotter" + bash -f "${cidir}/install_nydus_snapshotter.sh" + fi + echo "Install CNI plugins" bash -f "${cidir}/install_cni_plugins.sh" }