static-build: Add scripts to build content from src/tools

As we'd like to ship the content from src/tools, we need to build them
in the very same way we build the other components, and the first step
is providing scripts that can build those inside a container.

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
Fabiano Fidêncio 2023-09-27 13:54:38 +02:00
parent 4d08ec29bc
commit 6ef42db5ec
3 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,20 @@
# Copyright (c) 2023 Intel
#
# SPDX-License-Identifier: Apache-2.0
FROM alpine:3.18
ARG GO_TOOLCHAIN
ARG RUST_TOOLCHAIN
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
RUN apk --no-cache add \
bash \
curl \
gcc \
git \
libcap-ng-static \
libseccomp-static \
make \
musl-dev \
protoc && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_TOOLCHAIN}

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# Copyright (c) 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o nounset
set -o pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${script_dir}/../../scripts/lib.sh"
init_env() {
source "$HOME/.cargo/env"
export LIBC=musl
export LIBSECCOMP_LINK_TYPE=static
export LIBSECCOMP_LIB_PATH=/usr/lib
extra_rust_flags=" -C link-self-contained=yes"
}
build_tool_from_source() {
set -x
tool=${1}
echo "build ${tool} from source"
init_env
cd src/tools/${tool}
make
}
build_tool_from_source $@

View File

@ -0,0 +1,31 @@
#!/usr/bin/env bash
#
# Copyright (c) 2023 Intel
#
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o nounset
set -o pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly tools_builder="${script_dir}/build-static-tools.sh"
source "${script_dir}/../../scripts/lib.sh"
tool="${1}"
container_image="${VIRTIOFSD_CONTAINER_BUILDER:-$(get_tools_image_name)}"
[ "${CROSS_BUILD}" == "true" ] && container_image="${container_image}-cross-build"
sudo docker pull ${container_image} || \
(sudo docker $BUILDX build $PLATFORM \
--build-arg RUST_TOOLCHAIN="$(get_from_kata_deps "languages.rust.meta.newest-version")" \
-t "${container_image}" "${script_dir}" && \
# No-op unless PUSH_TO_REGISTRY is exported as "yes"
push_to_registry "${container_image}")
sudo docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${repo_root_dir}" \
"${container_image}" \
bash -c "${tools_builder} ${tool}"