generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cross-compile for arm64 and mount go cache
Closes #29 Provides is a very efficient way to build multi-arch images: https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
- Loading branch information
Showing
2 changed files
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
ARG GOARCH="amd64" | ||
FROM golang:1.22 AS builder | ||
FROM --platform=$BUILDPLATFORM golang:1.22 AS builder | ||
|
||
WORKDIR /src | ||
|
||
COPY go.mod go.sum . | ||
RUN --mount=type=cache,target=/go/pkg \ | ||
go mod download | ||
|
||
COPY . . | ||
# build | ||
RUN go mod download | ||
RUN CGO_ENABLED=0 go build -o /go/bin/netpol ./cmd | ||
|
||
ARG TARGETOS TARGETARCH | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/go/pkg \ | ||
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ | ||
go build -o /go/bin/netpol ./cmd | ||
|
||
# STEP 2: Build small image | ||
FROM registry.k8s.io/build-image/distroless-iptables:v0.5.2 | ||
COPY --from=builder --chown=root:root /go/bin/netpol /bin/netpol | ||
|
||
CMD ["/bin/netpol"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters