From 91cb6c9bebc00acf6d7970cfb5a7b2ff54833456 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:16:54 +0100 Subject: [PATCH] root: Improve multi arch Docker image build speed (cherry-pick #7355) (#7426) root: Improve multi arch Docker image build speed (#7355) * Improve multi arch Docker image build speed Use only host architecture for GeoIP database update and for Go cross-compilation * Speedup Go multi-arch compilation for other images * Speedup multi-arch ldap image build Co-authored-by: Philipp Kolberg <39984529+PKizzle@users.noreply.github.com> --- Dockerfile | 13 ++++++++++--- ldap.Dockerfile | 11 +++++++++-- proxy.Dockerfile | 11 +++++++++-- radius.Dockerfile | 11 +++++++++-- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index fca6080de..8fc19d534 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,14 @@ COPY ./gen-ts-api /work/web/node_modules/@goauthentik/api RUN npm run build # Stage 3: Build go proxy -FROM docker.io/golang:1.21.3-bookworm AS go-builder +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.3-bookworm AS go-builder + +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + +ARG GOOS=$TARGETOS +ARG GOARCH=$TARGETARCH WORKDIR /go/src/goauthentik.io @@ -57,10 +64,10 @@ ENV CGO_ENABLED=0 RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - go build -o /go/authentik ./cmd/server + GOARM="${TARGETVARIANT#v}" go build -o /go/authentik ./cmd/server # Stage 4: MaxMind GeoIP -FROM ghcr.io/maxmind/geoipupdate:v6.0 as geoip +FROM --platform=${BUILDPLATFORM} ghcr.io/maxmind/geoipupdate:v6.0 as geoip ENV GEOIPUPDATE_EDITION_IDS="GeoLite2-City" ENV GEOIPUPDATE_VERBOSE="true" diff --git a/ldap.Dockerfile b/ldap.Dockerfile index 095867927..780bb43fc 100644 --- a/ldap.Dockerfile +++ b/ldap.Dockerfile @@ -1,5 +1,12 @@ # Stage 1: Build -FROM docker.io/golang:1.21.3-bookworm AS builder +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.3-bookworm AS builder + +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + +ARG GOOS=$TARGETOS +ARG GOARCH=$TARGETARCH WORKDIR /go/src/goauthentik.io @@ -13,7 +20,7 @@ ENV CGO_ENABLED=0 COPY . . RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - go build -o /go/ldap ./cmd/ldap + GOARM="${TARGETVARIANT#v}" go build -o /go/ldap ./cmd/ldap # Stage 2: Run FROM gcr.io/distroless/static-debian11:debug diff --git a/proxy.Dockerfile b/proxy.Dockerfile index 990e8ecd8..9c29ded43 100644 --- a/proxy.Dockerfile +++ b/proxy.Dockerfile @@ -15,7 +15,14 @@ COPY web . RUN npm run build-proxy # Stage 2: Build -FROM docker.io/golang:1.21.3-bookworm AS builder +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.3-bookworm AS builder + +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + +ARG GOOS=$TARGETOS +ARG GOARCH=$TARGETARCH WORKDIR /go/src/goauthentik.io @@ -29,7 +36,7 @@ ENV CGO_ENABLED=0 COPY . . RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - go build -o /go/proxy ./cmd/proxy + GOARM="${TARGETVARIANT#v}" go build -o /go/proxy ./cmd/proxy # Stage 3: Run FROM gcr.io/distroless/static-debian11:debug diff --git a/radius.Dockerfile b/radius.Dockerfile index cc3c9d611..243e1827d 100644 --- a/radius.Dockerfile +++ b/radius.Dockerfile @@ -1,5 +1,12 @@ # Stage 1: Build -FROM docker.io/golang:1.21.3-bookworm AS builder +FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.3-bookworm AS builder + +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + +ARG GOOS=$TARGETOS +ARG GOARCH=$TARGETARCH WORKDIR /go/src/goauthentik.io @@ -13,7 +20,7 @@ ENV CGO_ENABLED=0 COPY . . RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - go build -o /go/radius ./cmd/radius + GOARM="${TARGETVARIANT#v}" go build -o /go/radius ./cmd/radius # Stage 2: Run FROM gcr.io/distroless/static-debian11:debug