From 0c5ded4bd78bfea9481c76fa69a742ccca33e0e3 Mon Sep 17 00:00:00 2001 From: Carlos Venegas Date: Tue, 29 Jun 2021 15:25:46 +0000 Subject: [PATCH] kata-deploy: build kata only with docker in host Add script to build kata using docker. Allow build kata-deploy binaries using docker. kata-deploy-binaries-in-docker.sh is a wrapper of kata-deploy-binaries.sh it will call kata-deploy-binaries.sh in a container with all the dependencies installed. Signed-off-by: Carlos Venegas --- ci/install_yq.sh | 13 +++-- .../local-build/dockerbuild/Dockerfile | 54 +++++++++++++++++++ .../kata-deploy-binaries-in-docker.sh | 44 +++++++++++++++ 3 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 tools/packaging/kata-deploy/local-build/dockerbuild/Dockerfile create mode 100755 tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh diff --git a/ci/install_yq.sh b/ci/install_yq.sh index b2923a6d2e..56ad7d6691 100755 --- a/ci/install_yq.sh +++ b/ci/install_yq.sh @@ -15,12 +15,18 @@ die() { # Install the yq yaml query package from the mikefarah github repo # Install via binary download, as we may not have golang installed at this point function install_yq() { - GOPATH=${GOPATH:-${HOME}/go} - local yq_path="${GOPATH}/bin/yq" local yq_pkg="github.com/mikefarah/yq" local yq_version=3.4.1 + INSTALL_IN_GOPATH=${INSTALL_IN_GOPATH:-true} - [ -x "${GOPATH}/bin/yq" ] && [ "`${GOPATH}/bin/yq --version`"X == "yq version ${yq_version}"X ] && return + if [ "${INSTALL_IN_GOPATH}" == "true" ];then + GOPATH=${GOPATH:-${HOME}/go} + mkdir -p "${GOPATH}/bin" + local yq_path="${GOPATH}/bin/yq" + else + yq_path="/usr/local/bin/yq" + fi + [ -x "${yq_path}" ] && [ "`${yq_path} --version`"X == "yq version ${yq_version}"X ] && return read -r -a sysInfo <<< "$(uname -sm)" @@ -51,7 +57,6 @@ function install_yq() { ;; esac - mkdir -p "${GOPATH}/bin" # Check curl if ! command -v "curl" >/dev/null; then diff --git a/tools/packaging/kata-deploy/local-build/dockerbuild/Dockerfile b/tools/packaging/kata-deploy/local-build/dockerbuild/Dockerfile new file mode 100644 index 0000000000..8f927ddebd --- /dev/null +++ b/tools/packaging/kata-deploy/local-build/dockerbuild/Dockerfile @@ -0,0 +1,54 @@ +# Copyright (c) 2021 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +FROM ubuntu +ENV DEBIAN_FRONTEND=noninteractive +ENV INSTALL_IN_GOPATH=false + +ADD install_yq.sh /usr/bin/install_yq.sh + + +RUN apt-get update +RUN apt-get install -y curl +RUN apt-get install -y sudo + +# Install yq +RUN install_yq.sh + +# Install docker-cli +RUN sudo apt-get -y install \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg \ + lsb-release +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg +RUN echo \ + "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null +RUN apt-get update +RUN apt-get install docker-ce-cli -y + +ARG IMG_USER=kata-builder +ARG UID=1000 +ARG GID=1000 +RUN if [ ${IMG_USER} != "root" ]; then groupadd --gid=${GID} ${IMG_USER};fi +RUN if [ ${IMG_USER} != "root" ]; then adduser ${IMG_USER} --uid=${UID} --gid=${GID};fi +RUN sh -c "echo '${IMG_USER} ALL=NOPASSWD: ALL' >> /etc/sudoers" + +# kernel deps +RUN apt install -y flex +RUN apt install -y bison +RUN apt install -y libelf-dev +RUN apt install -y bc +RUN apt install -y iptables +RUN apt install -y build-essential +RUN apt install -y git + + +# kata deps +RUN apt install -y golang + +ENV USER ${IMG_USER} +USER ${UID}:${GID} diff --git a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh new file mode 100755 index 0000000000..589760615c --- /dev/null +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# Copyright (c) 2018-2021 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +set -o errexit +set -o nounset +set -o pipefail +set -o errtrace + +script_dir=$(dirname "$(readlink -f "$0")") +kata_dir=$(realpath "${script_dir}/../../../../") +kata_deploy_create="${script_dir}/kata-deploy-binaries.sh" +uid=$(id -u ${USER}) +gid=$(id -g ${USER}) + +TTY_OPT="-i" +NO_TTY="${NO_TTY:-false}" +[ -t 1 ] && [ "${NO_TTY}" == "false" ] && TTY_OPT="-it" + +if [ "${script_dir}" != "${PWD}" ]; then + ln -sf "${script_dir}/build" "${PWD}/build" +fi + +install_yq_script_path="${script_dir}/../../../../ci/install_yq.sh" + +cp "${install_yq_script_path}" "${script_dir}/dockerbuild/install_yq.sh" + +docker build -q -t build-kata-deploy \ + --build-arg IMG_USER="${USER}" \ + --build-arg UID=${uid} \ + --build-arg GID=${gid} \ + "${script_dir}/dockerbuild/" + +docker run ${TTY_OPT} \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --user ${uid}:${gid} \ + --env USER=${USER} -v "${kata_dir}:${kata_dir}" \ + --rm \ + -w ${script_dir} \ + build-kata-deploy "${kata_deploy_create}" $@ +