From 5cdab7933f52cd930bf067e306c2884cea53c62c Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Tue, 5 Nov 2024 11:50:31 +0100 Subject: [PATCH] chore: optimize build layers Signed-off-by: Simon Pasquier --- Dockerfile | 7 +++++-- cmd/admission-webhook/Dockerfile | 7 +++++-- cmd/prometheus-config-reloader/Dockerfile | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index a8d6cefb7..977e3cd3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,19 @@ ARG ARCH=amd64 ARG OS=linux ARG GOLANG_BUILDER=1.23 + FROM quay.io/prometheus/golang-builder:${GOLANG_BUILDER}-base AS builder WORKDIR /workspace -# Copy source files COPY . . +# Download Go dependencies to reuse the Go cache in subsequent builds. +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go mod download -x && go mod verify + # Build ARG GOARCH ENV GOARCH=${GOARCH} -RUN make operator +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build make operator FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest diff --git a/cmd/admission-webhook/Dockerfile b/cmd/admission-webhook/Dockerfile index c51474115..d3a037527 100644 --- a/cmd/admission-webhook/Dockerfile +++ b/cmd/admission-webhook/Dockerfile @@ -1,16 +1,19 @@ ARG ARCH=amd64 ARG OS=linux ARG GOLANG_BUILDER=1.23 + FROM quay.io/prometheus/golang-builder:${GOLANG_BUILDER}-base AS builder WORKDIR /workspace -# Copy source files COPY . . +# Download Go dependencies to reuse the Go cache in subsequent builds. +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go mod download -x && go mod verify + # Build ARG GOARCH ENV GOARCH=${GOARCH} -RUN make admission-webhook +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build make admission-webhook FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest diff --git a/cmd/prometheus-config-reloader/Dockerfile b/cmd/prometheus-config-reloader/Dockerfile index 48a79a282..d8cd404b9 100644 --- a/cmd/prometheus-config-reloader/Dockerfile +++ b/cmd/prometheus-config-reloader/Dockerfile @@ -1,16 +1,19 @@ ARG ARCH=amd64 ARG OS=linux ARG GOLANG_BUILDER=1.23 + FROM quay.io/prometheus/golang-builder:${GOLANG_BUILDER}-base AS builder WORKDIR /workspace -# Copy source files COPY . . +# Download Go dependencies to reuse the Go cache in subsequent builds. +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go mod download -x && go mod verify + # Build ARG GOARCH ENV GOARCH=${GOARCH} -RUN make prometheus-config-reloader +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build make prometheus-config-reloader FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest