osbuilder: Skip installing golang for building rootfs

Building rootfs does not depend on golang, delete intalling
golang may save build time.

And there is only rust agent now, the code for golang agent should
be deleted too.

Fixes: #2170

Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
bin 2021-07-01 17:50:22 +08:00
parent 594ff3a5bd
commit b12b21f337
12 changed files with 24 additions and 102 deletions

View File

@ -34,7 +34,6 @@ RUN yum -y update && yum install -y \
vim \ vim \
which which
# This will install the proper packages to build Kata components
@INSTALL_MUSL@ @INSTALL_MUSL@
# This will install the proper golang to build Kata components
@INSTALL_GO@
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -37,7 +37,6 @@ RUN dnf -y update && dnf install -y \
vim \ vim \
which which
# This will install the proper golang to build Kata components # This will install the proper packages to build Kata components
@INSTALL_MUSL@ @INSTALL_MUSL@
@INSTALL_GO@
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -29,7 +29,6 @@ RUN apt-get update && apt-get install -y \
systemd \ systemd \
tar \ tar \
vim vim
# This will install the proper golang to build Kata components # This will install the proper packages to build Kata components
@INSTALL_GO@
@INSTALL_MUSL@ @INSTALL_MUSL@
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -36,6 +36,5 @@ RUN apt-get update && apt-get --no-install-recommends install -y \
vim \ vim \
wget wget
# This will install the proper golang to build Kata components # This will install the proper packages to build Kata components
@INSTALL_GO@
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -37,7 +37,6 @@ RUN dnf -y update && dnf install -y \
vim \ vim \
which which
# This will install the proper golang to build Kata components # This will install the proper packages to build Kata components
@INSTALL_MUSL@ @INSTALL_MUSL@
@INSTALL_GO@
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -9,6 +9,5 @@ FROM ${IMAGE_REGISTRY}/gentoo/stage3-amd64:latest
# This dockerfile needs to provide all the componets need to build a rootfs # This dockerfile needs to provide all the componets need to build a rootfs
# Install any package need to create a rootfs (package manager, extra tools) # Install any package need to create a rootfs (package manager, extra tools)
# This will install the proper golang to build Kata components # This will install the proper rust to build Kata components
@INSTALL_GO@
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -13,9 +13,6 @@ set -o errtrace
script_name="${0##*/}" script_name="${0##*/}"
script_dir="$(dirname $(readlink -f $0))" script_dir="$(dirname $(readlink -f $0))"
AGENT_VERSION=${AGENT_VERSION:-} AGENT_VERSION=${AGENT_VERSION:-}
GO_AGENT_PKG=${GO_AGENT_PKG:-github.com/kata-containers/agent}
RUST_AGENT_PKG=${RUST_AGENT_PKG:-github.com/kata-containers/kata-containers}
RUST_AGENT=${RUST_AGENT:-yes}
RUST_VERSION="null" RUST_VERSION="null"
MUSL_VERSION=${MUSL_VERSION:-"null"} MUSL_VERSION=${MUSL_VERSION:-"null"}
AGENT_BIN=${AGENT_BIN:-kata-agent} AGENT_BIN=${AGENT_BIN:-kata-agent}
@ -23,7 +20,7 @@ AGENT_INIT=${AGENT_INIT:-no}
KERNEL_MODULES_DIR=${KERNEL_MODULES_DIR:-""} KERNEL_MODULES_DIR=${KERNEL_MODULES_DIR:-""}
OSBUILDER_VERSION="unknown" OSBUILDER_VERSION="unknown"
DOCKER_RUNTIME=${DOCKER_RUNTIME:-runc} DOCKER_RUNTIME=${DOCKER_RUNTIME:-runc}
GO_VERSION="null" # this GOPATH is for installing yq from install_yq.sh
export GOPATH=${GOPATH:-${HOME}/go} export GOPATH=${GOPATH:-${HOME}/go}
LIBC=${LIBC:-musl} LIBC=${LIBC:-musl}
@ -113,9 +110,6 @@ DISTRO_REPO Use host repositories to install guest packages.
DOCKER_RUNTIME Docker runtime to use when USE_DOCKER is set. DOCKER_RUNTIME Docker runtime to use when USE_DOCKER is set.
Default value: runc Default value: runc
GO_AGENT_PKG URL of the Git repository hosting the agent package.
Default value: ${GO_AGENT_PKG}
GRACEFUL_EXIT If set, and if the DISTRO configuration specifies a GRACEFUL_EXIT If set, and if the DISTRO configuration specifies a
non-empty BUILD_CAN_FAIL variable, do not return with an non-empty BUILD_CAN_FAIL variable, do not return with an
error code in case any of the build step fails. error code in case any of the build step fails.
@ -134,12 +128,6 @@ KERNEL_MODULES_DIR Path to a directory containing kernel modules to include in
ROOTFS_DIR Path to the directory that is populated with the rootfs. ROOTFS_DIR Path to the directory that is populated with the rootfs.
Default value: <${script_name} path>/rootfs-<DISTRO-name> Default value: <${script_name} path>/rootfs-<DISTRO-name>
RUST_AGENT When set to "no", build kata-agent from go agent instead of kata-rust-agent
Default value: "yes"
RUST_AGENT_PKG URL of the Git repository hosting the agent package.
Default value: ${RUST_AGENT_PKG}
USE_DOCKER If set, build the rootfs inside a container (requires USE_DOCKER If set, build the rootfs inside a container (requires
Docker). Docker).
Default value: <not set> Default value: <not set>
@ -291,17 +279,11 @@ compare_versions()
check_env_variables() check_env_variables()
{ {
# Fetch the first element from GOPATH as working directory # this will be mounted to container for using yq on the host side.
# as go get only works against the first item in the GOPATH
[ -z "$GOPATH" ] && die "GOPATH not set"
GOPATH_LOCAL="${GOPATH%%:*}" GOPATH_LOCAL="${GOPATH%%:*}"
[ "$AGENT_INIT" == "yes" -o "$AGENT_INIT" == "no" ] || die "AGENT_INIT($AGENT_INIT) is invalid (must be yes or no)" [ "$AGENT_INIT" == "yes" -o "$AGENT_INIT" == "no" ] || die "AGENT_INIT($AGENT_INIT) is invalid (must be yes or no)"
if [ -z "${AGENT_SOURCE_BIN}" ]; then
[ "$RUST_AGENT" == "yes" -o "$RUST_AGENT" == "no" ] || die "RUST_AGENT($RUST_AGENT) is invalid (must be yes or no)"
fi
[ -n "${KERNEL_MODULES_DIR}" ] && [ ! -d "${KERNEL_MODULES_DIR}" ] && die "KERNEL_MODULES_DIR defined but is not an existing directory" [ -n "${KERNEL_MODULES_DIR}" ] && [ ! -d "${KERNEL_MODULES_DIR}" ] && die "KERNEL_MODULES_DIR defined but is not an existing directory"
[ -n "${OSBUILDER_VERSION}" ] || die "need osbuilder version" [ -n "${OSBUILDER_VERSION}" ] || die "need osbuilder version"
@ -346,24 +328,18 @@ build_rootfs_distro()
mkdir -p ${ROOTFS_DIR} mkdir -p ${ROOTFS_DIR}
detect_go_version ||
die "Could not detect the required Go version for AGENT_VERSION='${AGENT_VERSION:-master}'."
echo "Required Go version: $GO_VERSION"
# need to detect rustc's version too? # need to detect rustc's version too?
detect_rust_version || detect_rust_version ||
die "Could not detect the required rust version for AGENT_VERSION='${AGENT_VERSION:-master}'." die "Could not detect the required rust version for AGENT_VERSION='${AGENT_VERSION:-main}'."
echo "Required rust version: $RUST_VERSION" echo "Required rust version: $RUST_VERSION"
detect_musl_version || detect_musl_version ||
die "Could not detect the required musl version for AGENT_VERSION='${AGENT_VERSION:-master}'." die "Could not detect the required musl version for AGENT_VERSION='${AGENT_VERSION:-main}'."
echo "Required musl version: $MUSL_VERSION" echo "Required musl version: $MUSL_VERSION"
if [ -z "${USE_DOCKER}" ] && [ -z "${USE_PODMAN}" ]; then if [ -z "${USE_DOCKER}" ] && [ -z "${USE_PODMAN}" ]; then
#Generate an error if the local Go version is too old
info "build directly" info "build directly"
build_rootfs ${ROOTFS_DIR} build_rootfs ${ROOTFS_DIR}
else else
@ -380,7 +356,7 @@ build_rootfs_distro()
REGISTRY_ARG="--build-arg IMAGE_REGISTRY=${IMAGE_REGISTRY}" REGISTRY_ARG="--build-arg IMAGE_REGISTRY=${IMAGE_REGISTRY}"
fi fi
# setup to install go or rust here # setup to install rust here
generate_dockerfile "${distro_config_dir}" generate_dockerfile "${distro_config_dir}"
"$container_engine" build \ "$container_engine" build \
${REGISTRY_ARG} \ ${REGISTRY_ARG} \
@ -396,12 +372,7 @@ build_rootfs_distro()
docker_run_args+=" --runtime ${DOCKER_RUNTIME}" docker_run_args+=" --runtime ${DOCKER_RUNTIME}"
if [ -z "${AGENT_SOURCE_BIN}" ] ; then if [ -z "${AGENT_SOURCE_BIN}" ] ; then
if [ "$RUST_AGENT" == "no" ]; then docker_run_args+=" -v ${GOPATH_LOCAL}:${GOPATH_LOCAL} --env GOPATH=${GOPATH_LOCAL}"
docker_run_args+=" --env GO_AGENT_PKG=${GO_AGENT_PKG}"
else
docker_run_args+=" --env RUST_AGENT_PKG=${RUST_AGENT_PKG}"
fi
docker_run_args+=" --env RUST_AGENT=${RUST_AGENT} -v ${GOPATH_LOCAL}:${GOPATH_LOCAL} --env GOPATH=${GOPATH_LOCAL}"
else else
docker_run_args+=" --env AGENT_SOURCE_BIN=${AGENT_SOURCE_BIN}" docker_run_args+=" --env AGENT_SOURCE_BIN=${AGENT_SOURCE_BIN}"
docker_run_args+=" -v ${AGENT_SOURCE_BIN}:${AGENT_SOURCE_BIN}" docker_run_args+=" -v ${AGENT_SOURCE_BIN}:${AGENT_SOURCE_BIN}"
@ -576,7 +547,6 @@ EOT
test -r "${HOME}/.cargo/env" && source "${HOME}/.cargo/env" test -r "${HOME}/.cargo/env" && source "${HOME}/.cargo/env"
[ "$ARCH" == "aarch64" ] && OLD_PATH=$PATH && export PATH=$PATH:/usr/local/musl/bin [ "$ARCH" == "aarch64" ] && OLD_PATH=$PATH && export PATH=$PATH:/usr/local/musl/bin
agent_pkg="${RUST_AGENT_PKG}"
agent_dir="${script_dir}/../../../src/agent/" agent_dir="${script_dir}/../../../src/agent/"
# For now, rust-agent doesn't support seccomp yet. # For now, rust-agent doesn't support seccomp yet.
SECCOMP="no" SECCOMP="no"

View File

@ -15,7 +15,6 @@ COPY install-packages.sh config.sh /
# RUN commands # RUN commands
RUN chmod +x /install-packages.sh; /install-packages.sh RUN chmod +x /install-packages.sh; /install-packages.sh
# This will install the proper golang to build Kata components # This will install the proper packages to build Kata components
@INSTALL_MUSL@ @INSTALL_MUSL@
@INSTALL_GO@
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -13,5 +13,6 @@ FROM ${IMAGE_REGISTRY}/@distro@:@OS_VERSION@
# RUN commands # RUN commands
# This will install the proper golang to build Kata components # This will install the proper packages to build Kata components
@INSTALL_GO@ @INSTALL_MUSL@
@INSTALL_RUST@

View File

@ -33,7 +33,6 @@ RUN apt-get update && apt-get install -y \
systemd \ systemd \
tar \ tar \
vim vim
# This will install the proper golang to build Kata components # This will install the proper packages to build Kata components
@INSTALL_GO@
@INSTALL_MUSL@ @INSTALL_MUSL@
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -40,6 +40,6 @@ RUN apt-get update && apt-get --no-install-recommends install -y \
tar \ tar \
vim \ vim \
wget wget
# This will install the proper golang to build Kata components
@INSTALL_GO@ # This will install the proper packages to build Kata components
@INSTALL_RUST@ @INSTALL_RUST@

View File

@ -150,6 +150,8 @@ build_rootfs()
else else
DNF="${DNF} --releasever=${OS_VERSION}" DNF="${DNF} --releasever=${OS_VERSION}"
fi fi
info "install packages for rootfs"
$DNF install ${EXTRA_PKGS} ${PACKAGES} $DNF install ${EXTRA_PKGS} ${PACKAGES}
} }
@ -190,14 +192,8 @@ create_summary_file()
local agent="${AGENT_DEST}" local agent="${AGENT_DEST}"
[ "$AGENT_INIT" = yes ] && agent="${init}" [ "$AGENT_INIT" = yes ] && agent="${init}"
local agent_version local -r agentdir="${script_dir}/../../../"
if [ "${RUST_AGENT}" == "no" ]; then local -r agent_version=$(cat ${agentdir}/VERSION)
agent_version=$("$agent" --version|awk '{print $NF}')
else
local -r agentdir="${script_dir}/../../../"
agent_version=$(cat ${agentdir}/VERSION)
fi
cat >"$file"<<-EOT cat >"$file"<<-EOT
--- ---
@ -241,37 +237,20 @@ generate_dockerfile()
local libc=musl local libc=musl
case "$(uname -m)" in case "$(uname -m)" in
"ppc64le") "ppc64le")
goarch=ppc64le
rustarch=powerpc64le rustarch=powerpc64le
muslarch=powerpc64 muslarch=powerpc64
libc=gnu libc=gnu
;; ;;
"aarch64")
goarch=arm64
;;
"s390x") "s390x")
goarch=s390x
libc=gnu libc=gnu
;; ;;
*) *)
goarch=amd64
;; ;;
esac esac
[ -n "${http_proxy:-}" ] && readonly set_proxy="RUN sed -i '$ a proxy="${http_proxy:-}"' /etc/dnf/dnf.conf /etc/yum.conf; true" [ -n "${http_proxy:-}" ] && readonly set_proxy="RUN sed -i '$ a proxy="${http_proxy:-}"' /etc/dnf/dnf.conf /etc/yum.conf; true"
curlOptions=("-OL")
[ -n "${http_proxy:-}" ] && curlOptions+=("-x ${http_proxy:-}")
readonly install_go="
RUN cd /tmp ; curl ${curlOptions[@]} https://storage.googleapis.com/golang/go${GO_VERSION}.linux-${goarch}.tar.gz
RUN tar -C /usr/ -xzf /tmp/go${GO_VERSION}.linux-${goarch}.tar.gz
ENV GOROOT=/usr/go
ENV PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin
"
# Rust agent # Rust agent
# rust installer should set path apropiately, just in case # rust installer should set path apropiately, just in case
# install musl for compiling rust-agent # install musl for compiling rust-agent
@ -327,8 +306,6 @@ RUN . /root/.cargo/env; \
rustup target install ${rustarch}-unknown-linux-${libc} rustup target install ${rustarch}-unknown-linux-${libc}
RUN ln -sf /usr/bin/g++ /bin/musl-g++ RUN ln -sf /usr/bin/g++ /bin/musl-g++
" "
# rust agent still need go to build
# because grpc-sys need go to build
pushd "${dir}" pushd "${dir}"
dockerfile_template="Dockerfile.in" dockerfile_template="Dockerfile.in"
dockerfile_arch_template="Dockerfile-${architecture}.in" dockerfile_arch_template="Dockerfile-${architecture}.in"
@ -342,19 +319,15 @@ RUN ln -sf /usr/bin/g++ /bin/musl-g++
# ppc64le and s390x have no musl target # ppc64le and s390x have no musl target
if [ "${architecture}" == "ppc64le" ] || [ "${architecture}" == "s390x" ]; then if [ "${architecture}" == "ppc64le" ] || [ "${architecture}" == "s390x" ]; then
sed \ sed \
-e "s|@GO_VERSION@|${GO_VERSION}|g" \
-e "s|@OS_VERSION@|${OS_VERSION:-}|g" \ -e "s|@OS_VERSION@|${OS_VERSION:-}|g" \
-e "s|@INSTALL_MUSL@||g" \ -e "s|@INSTALL_MUSL@||g" \
-e "s|@INSTALL_GO@|${install_go//$'\n'/\\n}|g" \
-e "s|@INSTALL_RUST@|${install_rust//$'\n'/\\n}|g" \ -e "s|@INSTALL_RUST@|${install_rust//$'\n'/\\n}|g" \
-e "s|@SET_PROXY@|${set_proxy:-}|g" \ -e "s|@SET_PROXY@|${set_proxy:-}|g" \
"${dockerfile_template}" > Dockerfile "${dockerfile_template}" > Dockerfile
else else
sed \ sed \
-e "s|@GO_VERSION@|${GO_VERSION}|g" \
-e "s|@OS_VERSION@|${OS_VERSION:-}|g" \ -e "s|@OS_VERSION@|${OS_VERSION:-}|g" \
-e "s|@INSTALL_MUSL@|${install_musl//$'\n'/\\n}|g" \ -e "s|@INSTALL_MUSL@|${install_musl//$'\n'/\\n}|g" \
-e "s|@INSTALL_GO@|${install_go//$'\n'/\\n}|g" \
-e "s|@INSTALL_RUST@|${install_rust//$'\n'/\\n}|g" \ -e "s|@INSTALL_RUST@|${install_rust//$'\n'/\\n}|g" \
-e "s|@SET_PROXY@|${set_proxy:-}|g" \ -e "s|@SET_PROXY@|${set_proxy:-}|g" \
"${dockerfile_template}" > Dockerfile "${dockerfile_template}" > Dockerfile
@ -362,20 +335,6 @@ RUN ln -sf /usr/bin/g++ /bin/musl-g++
popd popd
} }
detect_go_version()
{
info "Detecting go version"
typeset yq=$(command -v yq || command -v ${GOPATH}/bin/yq || echo "${GOPATH}/bin/yq")
if [ ! -f "$yq" ]; then
source "$yq_file"
fi
info "Get Go version from ${kata_versions_file}"
GO_VERSION="$(cat "${kata_versions_file}" | $yq r -X - "languages.golang.meta.newest-version")"
[ "$?" == "0" ] && [ "$GO_VERSION" != "null" ]
}
detect_rust_version() detect_rust_version()
{ {
info "Detecting agent rust version" info "Detecting agent rust version"
@ -385,7 +344,7 @@ detect_rust_version()
fi fi
info "Get rust version from ${kata_versions_file}" info "Get rust version from ${kata_versions_file}"
RUST_VERSION="$(cat "${kata_versions_file}" | $yq r -X - "languages.rust.meta.newest-version")" RUST_VERSION="$(cat "${kata_versions_file}" | $yq r -X - "languages.rust.meta.newest-version")"
[ "$?" == "0" ] && [ "$RUST_VERSION" != "null" ] [ "$?" == "0" ] && [ "$RUST_VERSION" != "null" ]
} }