Skip to content

Commit 2505ef8

Browse files
committed
Add custom guest-components build support
- Add gc_builder stage to Dockerfile.podvm_binaries.ubuntu that compiles attestation-agent and api-server-rest from a configurable guest-components Git repo/ref when AA_FEATURES or GUEST_COMPONENTS_REF are set. - Extend Makefile with AA_FEATURES, GUEST_COMPONENTS_REPO, and GUEST_COMPONENTS_REF variables to pass custom build parameters. - Add /run tmpfs mount (80% RAM) to fstab for container image layers.
1 parent a17cdf3 commit 2505ef8

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/cloud-api-adaptor/podvm-mkosi/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ PODVM_CONTAINER_NAME ?= $(REGISTRY)/podvm-docker-image-$(DISTRO_ARCH)
1515
VERIFY_PROVENANCE ?= no
1616
MKOSI_VERSION ?= v22
1717

18+
# Set to a comma-separated list of cargo features to build attestation-agent
19+
# from source instead of pulling the pre-built OCI artifact.
20+
# Example: AA_FEATURES=bin,ttrpc,kbs,coco_as,rust-crypto,tdx-attester,nvidia-attester
21+
AA_FEATURES ?=
22+
23+
# Git repo + ref for guest-components. When GUEST_COMPONENTS_REF is non-empty,
24+
# api-server-rest is also built from source alongside attestation-agent.
25+
GUEST_COMPONENTS_REPO ?= https://github.com/confidential-containers/guest-components.git
26+
1827
_SHA := $(shell git rev-parse --short HEAD)
1928
_SHA_DIRTY := $(shell [ -n "$$(git status --porcelain 2>/dev/null)" ] && printf -- '-dirty')
2029
IMAGE_VERSION ?= $(_SHA)$(_SHA_DIRTY)
@@ -78,6 +87,8 @@ endif
7887
--build-arg PAUSE_BIN=$(PAUSE_BIN) \
7988
--build-arg IMAGE_NAME=mkosi-podvm-binaries \
8089
--build-arg VERIFY_PROVENANCE=$(VERIFY_PROVENANCE) \
90+
$(if $(AA_FEATURES),--build-arg AA_FEATURES=$(AA_FEATURES),) \
91+
$(if $(GUEST_COMPONENTS_REF),--build-arg GUEST_COMPONENTS_REF=$(GUEST_COMPONENTS_REF) --build-arg GUEST_COMPONENTS_REPO=$(GUEST_COMPONENTS_REPO),) \
8192
$(if $(AUTHFILE),--build-arg AUTHFILE=$(AUTHFILE),) \
8293
$(if $(DEFAULT_AGENT_POLICY_FILE),--build-arg DEFAULT_AGENT_POLICY_FILE=$(DEFAULT_AGENT_POLICY_FILE),) \
8394
$(if $(filter $(PUSH),true),,-o type=local,dest="./resources/binaries-tree") \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmpfs /run tmpfs rw,nosuid,nodev,size=80% 0 0

src/cloud-api-adaptor/podvm/Dockerfile.podvm_binaries.ubuntu

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,47 @@
55
#
66
# Build binaries for mkosi podvm image
77
#
8+
9+
# Optional: build guest-components binaries from source.
10+
# When AA_FEATURES is non-empty, attestation-agent is compiled with the given
11+
# cargo features (e.g. tdx + nvidia) instead of using the upstream pre-built binary.
12+
# When GUEST_COMPONENTS_REF is non-empty, api-server-rest is also compiled from
13+
# the same checkout so both binaries stay in sync.
14+
FROM rust:1.90-bookworm AS gc_builder
15+
ARG AA_FEATURES=""
16+
ARG GUEST_COMPONENTS_REF=""
17+
ARG GUEST_COMPONENTS_REPO="https://github.com/confidential-containers/guest-components.git"
18+
ARG DEBIAN_FRONTEND=noninteractive
19+
RUN set -e; \
20+
if [ -n "${GUEST_COMPONENTS_REF}" ]; then \
21+
apt-get update && \
22+
apt-get install -y --no-install-recommends \
23+
protobuf-compiler pkg-config clang libssl-dev libtss2-dev && \
24+
apt-get clean && rm -rf /var/lib/apt/lists/* && \
25+
mkdir -p /build/gc && cd /build/gc && \
26+
git init && \
27+
git remote add origin "${GUEST_COMPONENTS_REPO}" && \
28+
git fetch --depth=1 origin "${GUEST_COMPONENTS_REF}" && \
29+
git reset --hard FETCH_HEAD; \
30+
fi
31+
RUN set -e; \
32+
if [ -n "${AA_FEATURES}" ] && [ -n "${GUEST_COMPONENTS_REF}" ]; then \
33+
cd /build/gc/attestation-agent/attestation-agent && \
34+
cargo build --release --no-default-features \
35+
--features "${AA_FEATURES}" --bin ttrpc-aa && \
36+
cp /build/gc/target/release/ttrpc-aa /aa-binary; \
37+
else \
38+
touch /aa-binary; \
39+
fi
40+
RUN set -e; \
41+
if [ -n "${GUEST_COMPONENTS_REF}" ]; then \
42+
cd /build/gc/api-server-rest && \
43+
cargo build --release && \
44+
cp /build/gc/target/release/api-server-rest /api-server-rest-binary; \
45+
else \
46+
touch /api-server-rest-binary; \
47+
fi
48+
849
FROM ubuntu:24.04 AS builder
950

1051
ARG ARCH="x86_64"
@@ -107,5 +148,16 @@ RUN ./hack/cross-build-extras.sh
107148

108149
RUN LIBC=gnu make binaries
109150

151+
ARG AA_FEATURES=""
152+
ARG GUEST_COMPONENTS_REF=""
153+
COPY --from=gc_builder /aa-binary /tmp/aa-binary
154+
COPY --from=gc_builder /api-server-rest-binary /tmp/api-server-rest-binary
155+
RUN if [ -n "${AA_FEATURES}" ]; then \
156+
install -m0755 /tmp/aa-binary /src/cloud-api-adaptor/podvm/files/usr/local/bin/attestation-agent; \
157+
fi
158+
RUN if [ -n "${GUEST_COMPONENTS_REF}" ]; then \
159+
install -m0755 /tmp/api-server-rest-binary /src/cloud-api-adaptor/podvm/files/usr/local/bin/api-server-rest; \
160+
fi
161+
110162
FROM scratch
111163
COPY --from=podvm_binaries_builder /src/cloud-api-adaptor/podvm/files /

0 commit comments

Comments
 (0)