Skip to content

Commit c2cce12

Browse files
authored
Merge pull request kata-containers#8100 from fidencio/topic/kata-deploy-build-agent
kata-deploy: Build kata-agent as we build all the other components
2 parents c430cc3 + 560bbff commit c2cce12

File tree

12 files changed

+154
-4
lines changed

12 files changed

+154
-4
lines changed

.github/workflows/build-kata-static-tarball-amd64.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
strategy:
2828
matrix:
2929
asset:
30+
- agent
31+
- agent-opa
3032
- agent-ctl
3133
- cloud-hypervisor
3234
- cloud-hypervisor-glibc
@@ -59,6 +61,10 @@ jobs:
5961
stage:
6062
- ${{ inputs.stage }}
6163
exclude:
64+
- asset: agent
65+
stage: release
66+
- asset: agent-opa
67+
stage: release
6268
- asset: cloud-hypervisor-glibc
6369
stage: release
6470
steps:

src/agent/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ifeq ($(SECCOMP),yes)
3434
endif
3535

3636
##VAR AGENT_POLICY=yes|no define if agent enables the policy feature
37-
AGENT_POLICY := no
37+
AGENT_POLICY ?= no
3838

3939
# Enable the policy feature of rust build
4040
ifeq ($(AGENT_POLICY),yes)
@@ -62,7 +62,7 @@ endif
6262
TARGET_PATH = target/$(TRIPLE)/$(BUILD_TYPE)/$(TARGET)
6363

6464
##VAR DESTDIR=<path> is a directory prepended to each installed target file
65-
DESTDIR :=
65+
DESTDIR ?=
6666
##VAR BINDIR=<path> is a directory for installing executable programs
6767
BINDIR := /usr/bin
6868

tools/packaging/kata-deploy/local-build/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ serial-targets:
5252
%-tarball-build: $(MK_DIR)/dockerbuild/install_yq.sh
5353
$(call BUILD,$*)
5454

55+
agent-tarball:
56+
${MAKE} $@-build
57+
58+
agent-opa-tarball:
59+
${MAKE} $@-build
60+
5561
agent-ctl-tarball:
5662
${MAKE} $@-build
5763

tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ ARTEFACT_REGISTRY_PASSWORD="${ARTEFACT_REGISTRY_PASSWORD:-}"
8484
TARGET_BRANCH="${TARGET_BRANCH:-}"
8585
BUILDER_REGISTRY="${BUILDER_REGISTRY:-}"
8686
PUSH_TO_REGISTRY="${PUSH_TO_REGISTRY:-"no"}"
87+
AGENT_CONTAINER_BUILDER="${AGENT_CONTAINER_BUILDER:-}"
8788
INITRAMFS_CONTAINER_BUILDER="${INITRAMFS_CONTAINER_BUILDER:-}"
8889
KERNEL_CONTAINER_BUILDER="${KERNEL_CONTAINER_BUILDER:-}"
8990
OVMF_CONTAINER_BUILDER="${OVMF_CONTAINER_BUILDER:-}"
9091
QEMU_CONTAINER_BUILDER="${QEMU_CONTAINER_BUILDER:-}"
9192
SHIM_V2_CONTAINER_BUILDER="${SHIM_V2_CONTAINER_BUILDER:-}"
9293
TDSHIM_CONTAINER_BUILDER="${TDSHIM_CONTAINER_BUILDER:-}"
94+
TOOLS_CONTAINER_BUILDER="${TOOLS_CONTAINER_BUILDER:-}"
9395
VIRTIOFSD_CONTAINER_BUILDER="${VIRTIOFSD_CONTAINER_BUILDER:-}"
9496
MEASURED_ROOTFS="${MEASURED_ROOTFS:-}"
9597
USE_CACHE="${USE_CACHE:-}"
@@ -106,12 +108,14 @@ docker run \
106108
--env TARGET_BRANCH="${TARGET_BRANCH}" \
107109
--env BUILDER_REGISTRY="${BUILDER_REGISTRY}" \
108110
--env PUSH_TO_REGISTRY="${PUSH_TO_REGISTRY}" \
111+
--env AGENT_CONTAINER_BUILDER="${AGENT_CONTAINER_BUILDER}" \
109112
--env INITRAMFS_CONTAINER_BUILDER="${INITRAMFS_CONTAINER_BUILDER}" \
110113
--env KERNEL_CONTAINER_BUILDER="${KERNEL_CONTAINER_BUILDER}" \
111114
--env OVMF_CONTAINER_BUILDER="${OVMF_CONTAINER_BUILDER}" \
112115
--env QEMU_CONTAINER_BUILDER="${QEMU_CONTAINER_BUILDER}" \
113116
--env SHIM_V2_CONTAINER_BUILDER="${SHIM_V2_CONTAINER_BUILDER}" \
114117
--env TDSHIM_CONTAINER_BUILDER="${TDSHIM_CONTAINER_BUILDER}" \
118+
--env TOOLS_CONTAINER_BUILDER="${TOOLS_CONTAINER_BUILDER}" \
115119
--env VIRTIOFSD_CONTAINER_BUILDER="${VIRTIOFSD_CONTAINER_BUILDER}" \
116120
--env MEASURED_ROOTFS="${MEASURED_ROOTFS}" \
117121
--env USE_CACHE="${USE_CACHE}" \

tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ readonly static_build_dir="${repo_root_dir}/tools/packaging/static-build"
2222
readonly version_file="${repo_root_dir}/VERSION"
2323
readonly versions_yaml="${repo_root_dir}/versions.yaml"
2424

25+
readonly agent_builder="${static_build_dir}/agent/build.sh"
2526
readonly clh_builder="${static_build_dir}/cloud-hypervisor/build-static-clh.sh"
2627
readonly firecracker_builder="${static_build_dir}/firecracker/build-static-firecracker.sh"
2728
readonly initramfs_builder="${static_build_dir}/initramfs/build.sh"
@@ -81,6 +82,8 @@ options:
8182
-s : Silent mode (produce output in case of failure only)
8283
--build=<asset> :
8384
all
85+
agent
86+
agent-opa
8487
agent-ctl
8588
cloud-hypervisor
8689
cloud-hypervisor-glibc
@@ -625,6 +628,32 @@ install_ovmf_sev() {
625628
install_ovmf "sev" "edk2-sev.tar.gz"
626629
}
627630

631+
install_agent_helper() {
632+
agent_policy="${1:-no}"
633+
634+
latest_artefact="$(git log -1 --pretty=format:"%h" ${repo_root_dir}/src/agent)"
635+
latest_builder_image="$(get_agent_image_name)"
636+
637+
install_cached_tarball_component \
638+
"${build_target}" \
639+
"${latest_artefact}" \
640+
"${latest_builder_image}" \
641+
"${final_tarball_name}" \
642+
"${final_tarball_path}" \
643+
&& return 0
644+
645+
info "build static agent"
646+
DESTDIR="${destdir}" AGENT_POLICY=${agent_policy} "${agent_builder}"
647+
}
648+
649+
install_agent() {
650+
install_agent_helper
651+
}
652+
653+
install_agent_opa() {
654+
install_agent_helper "yes"
655+
}
656+
628657
install_tools_helper() {
629658
tool=${1}
630659

@@ -720,6 +749,10 @@ handle_build() {
720749
install_virtiofsd
721750
;;
722751

752+
agent) install_agent ;;
753+
754+
agent-opa) install_agent_opa ;;
755+
723756
agent-ctl) install_agent_ctl ;;
724757

725758
cloud-hypervisor) install_clh ;;
@@ -827,6 +860,8 @@ main() {
827860
local build_targets
828861
local silent
829862
build_targets=(
863+
agent
864+
agent-opa
830865
agent-ctl
831866
cloud-hypervisor
832867
firecracker

tools/packaging/release/release-notes.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,22 @@ The majority of the components of the project were built using containers. In o
140140
build reproducibility we publish those container images, and when those are used combined with the version
141141
of the projects listed as part of the "versions.yaml" file, users can get as close to the environment we
142142
used to build the release artefacts.
143+
* agent (on all its different flavours): $(get_agent_image_name)
143144
* Kernel (on all its different flavours): $(get_kernel_image_name)
144145
* OVMF (on all its different flavours): $(get_ovmf_image_name)
145146
* QEMU (on all its different flavurs): $(get_qemu_image_name)
146147
* shim-v2: $(get_shim_v2_image_name)
148+
* tools: $(get_tools_image_name)
147149
* virtiofsd: $(get_virtiofsd_image_name)
148150
149151
The users who want to rebuild the tarballs using exactly the same images can simply use the following environment
150152
variables:
153+
* \`AGENT_CONTAINER_BUILDER\`
151154
* \`KERNEL_CONTAINER_BUILDER\`
152155
* \`OVMF_CONTAINER_BUILDER\`
153156
* \`QEMU_CONTAINER_BUILDER\`
154157
* \`SHIM_V2_CONTAINER_BUILDER\`
158+
* \`TOOLS_CONTAINER_BUILDER\`
155159
* \`VIRTIOFSD_CONTAINER_BUILDER\`
156160
157161
## Kata Linux Containers Kernel

tools/packaging/scripts/lib.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,10 @@ get_tools_image_name() {
226226

227227
echo "${BUILDER_REGISTRY}:tools-$(get_last_modification ${tools_dir})-$(get_last_modification ${libs_dir})-$(get_last_modification ${agent_dir})"
228228
}
229+
230+
get_agent_image_name() {
231+
libs_dir="${repo_root_dir}/src/libs"
232+
agent_dir="${repo_root_dir}/src/agent"
233+
234+
echo "${BUILDER_REGISTRY}:agent-$(get_last_modification ${libs_dir})-$(get_last_modification ${agent_dir})"
235+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2023 Intel
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
FROM alpine:3.18
6+
ARG RUST_TOOLCHAIN
7+
8+
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
9+
RUN apk --no-cache add \
10+
bash \
11+
curl \
12+
gcc \
13+
git \
14+
libcap-ng-static \
15+
libseccomp-static \
16+
make \
17+
musl-dev \
18+
openssl-dev \
19+
openssl-libs-static \
20+
protoc && \
21+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_TOOLCHAIN}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
set -o errexit
8+
set -o nounset
9+
set -o pipefail
10+
11+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
13+
source "${script_dir}/../../scripts/lib.sh"
14+
15+
init_env() {
16+
source "$HOME/.cargo/env"
17+
18+
export LIBC=musl
19+
export LIBSECCOMP_LINK_TYPE=static
20+
export LIBSECCOMP_LIB_PATH=/usr/lib
21+
22+
# This is needed to workaround
23+
# https://github.com/sfackler/rust-openssl/issues/1624
24+
export OPENSSL_NO_VENDOR=Y
25+
}
26+
27+
build_agent_from_source() {
28+
echo "build agent from source"
29+
30+
init_env
31+
32+
cd src/agent
33+
DESTDIR=${DESTDIR} AGENT_POLICY=${AGENT_POLICY} make
34+
DESTDIR=${DESTDIR} AGENT_POLICY=${AGENT_POLICY} make install
35+
}
36+
37+
build_agent_from_source $@
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2023 Intel
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
set -o errexit
8+
set -o nounset
9+
set -o pipefail
10+
11+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
readonly agent_builder="${script_dir}/build-static-agent.sh"
13+
14+
source "${script_dir}/../../scripts/lib.sh"
15+
16+
container_image="${AGENT_CONTAINER_BUILDER:-$(get_agent_image_name)}"
17+
[ "${CROSS_BUILD}" == "true" ] && container_image="${container_image}-cross-build"
18+
19+
sudo docker pull ${container_image} || \
20+
(sudo docker $BUILDX build $PLATFORM \
21+
--build-arg RUST_TOOLCHAIN="$(get_from_kata_deps "languages.rust.meta.newest-version")" \
22+
-t "${container_image}" "${script_dir}" && \
23+
# No-op unless PUSH_TO_REGISTRY is exported as "yes"
24+
push_to_registry "${container_image}")
25+
26+
sudo docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
27+
--env DESTDIR=${DESTDIR} \
28+
--env AGENT_POLICY=${AGENT_POLICY:-no} \
29+
-w "${repo_root_dir}" \
30+
"${container_image}" \
31+
bash -c "${agent_builder}"

0 commit comments

Comments
 (0)