From 2fdafca4eb75c90f2e72a6cd41c779de7756a4ef Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Mon, 24 Apr 2023 09:02:04 +0200 Subject: [PATCH] outposts: use buildkit cache for dependencies and intermediate build artifacts Signed-off-by: Marc 'risson' Schmitt --- ldap.Dockerfile | 12 ++++++++++-- proxy.Dockerfile | 23 ++++++++++++++++++----- radius.Dockerfile | 12 ++++++++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/ldap.Dockerfile b/ldap.Dockerfile index 2e8d59928..c5bfdf84b 100644 --- a/ldap.Dockerfile +++ b/ldap.Dockerfile @@ -3,9 +3,17 @@ FROM docker.io/golang:1.21.1-bookworm AS builder WORKDIR /go/src/goauthentik.io -COPY . . +COPY go.mod . +COPY go.sum . +COPY gen-go-api . +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + ENV CGO_ENABLED=0 -RUN go build -o /go/ldap ./cmd/ldap +COPY . . +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + 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 55cd9cac4..d4fe1d6e1 100644 --- a/proxy.Dockerfile +++ b/proxy.Dockerfile @@ -1,21 +1,34 @@ # Stage 1: Build website FROM --platform=${BUILDPLATFORM} docker.io/node:20.5 as web-builder -COPY ./web /static/ - ENV NODE_ENV=production WORKDIR /static -RUN npm ci --include=dev && npm run build-proxy + +COPY web/package.json . +COPY web/package-lock.json . +RUN --mount=type=cache,target=/static/.npm \ + npm set cache /static/.npm && \ + npm ci --include=dev + +COPY web . +RUN npm run build-proxy # Stage 2: Build FROM docker.io/golang:1.21.1-bookworm AS builder WORKDIR /go/src/goauthentik.io -COPY . . +COPY go.mod . +COPY go.sum . +COPY gen-go-api . +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download ENV CGO_ENABLED=0 -RUN go build -o /go/proxy ./cmd/proxy +COPY . . +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + 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 1fe56688d..a9eafd9d8 100644 --- a/radius.Dockerfile +++ b/radius.Dockerfile @@ -3,9 +3,17 @@ FROM docker.io/golang:1.21.1-bookworm AS builder WORKDIR /go/src/goauthentik.io -COPY . . +COPY go.mod . +COPY go.sum . +COPY gen-go-api . +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + ENV CGO_ENABLED=0 -RUN go build -o /go/radius ./cmd/radius +COPY . . +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -o /go/radius ./cmd/radius # Stage 2: Run FROM gcr.io/distroless/static-debian11:debug