Skip to content

Commit

Permalink
static-build: Add scripts to build content from src/tools
Browse files Browse the repository at this point in the history
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>
(cherry picked from commit 6ef42db)
  • Loading branch information
fidencio committed Oct 6, 2023
1 parent d503daf commit a5d7ba6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tools/packaging/static-build/tools/Dockerfile
@@ -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}
36 changes: 36 additions & 0 deletions tools/packaging/static-build/tools/build-static-tools.sh
@@ -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 $@
31 changes: 31 additions & 0 deletions tools/packaging/static-build/tools/build.sh
@@ -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}"

0 comments on commit a5d7ba6

Please sign in to comment.