From 3c1163fabdb53f653e18bff2ff7f0322334eff64 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:30:15 +0100 Subject: [PATCH] root: Fix cache related image build issues (cherry-pick #7831) (#7932) Fix cache related image build issues Co-authored-by: Philipp Kolberg --- Dockerfile | 14 +++++++++----- ldap.Dockerfile | 6 ++++-- proxy.Dockerfile | 6 ++++-- radius.Dockerfile | 6 ++++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3d0e27c6c..9f919e393 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +# syntax=docker/dockerfile:1 + # Stage 1: Build website FROM --platform=${BUILDPLATFORM} docker.io/node:21 as website-builder @@ -7,7 +9,7 @@ WORKDIR /work/website RUN --mount=type=bind,target=/work/website/package.json,src=./website/package.json \ --mount=type=bind,target=/work/website/package-lock.json,src=./website/package-lock.json \ - --mount=type=cache,target=/root/.npm \ + --mount=type=cache,id=npm-website,sharing=shared,target=/root/.npm \ npm ci --include=dev COPY ./website /work/website/ @@ -25,7 +27,7 @@ WORKDIR /work/web RUN --mount=type=bind,target=/work/web/package.json,src=./web/package.json \ --mount=type=bind,target=/work/web/package-lock.json,src=./web/package-lock.json \ - --mount=type=cache,target=/root/.npm \ + --mount=type=cache,id=npm-web,sharing=shared,target=/root/.npm \ npm ci --include=dev COPY ./web /work/web/ @@ -62,8 +64,8 @@ COPY ./go.sum /go/src/goauthentik.io/go.sum ENV CGO_ENABLED=0 -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ +RUN --mount=type=cache,sharing=locked,target=/go/pkg/mod \ + --mount=type=cache,id=go-build-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/go-build \ GOARM="${TARGETVARIANT#v}" go build -o /go/authentik ./cmd/server # Stage 4: MaxMind GeoIP @@ -89,7 +91,9 @@ ENV VENV_PATH="/ak-root/venv" \ POETRY_VIRTUALENVS_CREATE=false \ PATH="/ak-root/venv/bin:$PATH" -RUN --mount=type=cache,target=/var/cache/apt \ +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache + +RUN --mount=type=cache,id=apt-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apt \ apt-get update && \ # Required for installing pip packages apt-get install -y --no-install-recommends build-essential pkg-config libxmlsec1-dev zlib1g-dev libpq-dev diff --git a/ldap.Dockerfile b/ldap.Dockerfile index 6bb161a97..c07970934 100644 --- a/ldap.Dockerfile +++ b/ldap.Dockerfile @@ -1,3 +1,5 @@ +# syntax=docker/dockerfile:1 + # Stage 1: Build FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.4-bookworm AS builder @@ -18,8 +20,8 @@ RUN --mount=type=bind,target=/go/src/goauthentik.io/go.mod,src=./go.mod \ ENV CGO_ENABLED=0 COPY . . -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ +RUN --mount=type=cache,sharing=locked,target=/go/pkg/mod \ + --mount=type=cache,id=go-build-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/go-build \ GOARM="${TARGETVARIANT#v}" go build -o /go/ldap ./cmd/ldap # Stage 2: Run diff --git a/proxy.Dockerfile b/proxy.Dockerfile index e8bb5a3f8..9e938e7a0 100644 --- a/proxy.Dockerfile +++ b/proxy.Dockerfile @@ -1,3 +1,5 @@ +# syntax=docker/dockerfile:1 + # Stage 1: Build website FROM --platform=${BUILDPLATFORM} docker.io/node:21 as web-builder @@ -34,8 +36,8 @@ RUN --mount=type=bind,target=/go/src/goauthentik.io/go.mod,src=./go.mod \ ENV CGO_ENABLED=0 COPY . . -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ +RUN --mount=type=cache,sharing=locked,target=/go/pkg/mod \ + --mount=type=cache,id=go-build-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/go-build \ GOARM="${TARGETVARIANT#v}" go build -o /go/proxy ./cmd/proxy # Stage 3: Run diff --git a/radius.Dockerfile b/radius.Dockerfile index 7e6b8fd42..8dd619a97 100644 --- a/radius.Dockerfile +++ b/radius.Dockerfile @@ -1,3 +1,5 @@ +# syntax=docker/dockerfile:1 + # Stage 1: Build FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.4-bookworm AS builder @@ -18,8 +20,8 @@ RUN --mount=type=bind,target=/go/src/goauthentik.io/go.mod,src=./go.mod \ ENV CGO_ENABLED=0 COPY . . -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ +RUN --mount=type=cache,sharing=locked,target=/go/pkg/mod \ + --mount=type=cache,id=go-build-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/go-build \ GOARM="${TARGETVARIANT#v}" go build -o /go/radius ./cmd/radius # Stage 2: Run