Skip to content

Commit

Permalink
peerpod-ctrl: use cross-compile to build faster
Browse files Browse the repository at this point in the history
Use the host platform ($BUILDPLATFORM) and cross-compile the manager
binary to speed up the build.

Fixes confidential-containers#1601
Signed-off-by: Wainer dos Santos Moschetta <[email protected]>
  • Loading branch information
wainersm committed Nov 24, 2023
1 parent 1f2f9cb commit 4ecff82
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions peerpod-ctrl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Build the manager binary
FROM --platform=$TARGETPLATFORM quay.io/confidential-containers/golang-fedora:1.20.8-38 as builder
ARG BUILDER_BASE=quay.io/confidential-containers/golang-fedora:1.20.8-38
ARG BASE=registry.fedoraproject.org/fedora:38

# This dockerfile uses Go cross-compilation to build the binary,
# we build on the host platform ($BUILDPLATFORM) and then copy the
# binary into the container image of the target platform ($TARGETPLATFORM)
# that was specified with --platform. For more details see:
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
FROM --platform=$BUILDPLATFORM $BUILDER_BASE as builder
ARG TARGETOS
ARG TARGETARCH
ARG CGO_ENABLED=1
Expand Down Expand Up @@ -28,7 +36,7 @@ COPY controllers/ controllers/
RUN CC=gcc CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build ${GOFLAGS} -a -o manager main.go

# Target Image
FROM --platform=$TARGETPLATFORM registry.fedoraproject.org/fedora:38
FROM --platform=$TARGETPLATFORM $BASE
ARG CGO_ENABLED=1

RUN if [ "$CGO_ENABLED" = 1 ] ; then dnf install -y libvirt-libs openssh-clients && dnf clean all; fi
Expand Down

0 comments on commit 4ecff82

Please sign in to comment.