From 0c9d668f32ef40c33d9f7911c4d88786b1628162 Mon Sep 17 00:00:00 2001 From: Paul Laffitte Date: Thu, 8 Feb 2024 11:10:12 +0100 Subject: [PATCH] build(dockerfile): run go build with mount=type=cache --- Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2c9a57d5..31f5ec1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,11 +33,12 @@ ENV LD_FLAGS="\ -X 'github.com/enix/kube-image-keeper/internal/metrics.Revision=${REVISION}' \ -X 'github.com/enix/kube-image-keeper/internal/metrics.BuildDateTime=BUILD_DATE_TIME'" -RUN BUILD_DATE_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S") && \ +RUN --mount=type=cache,target="/root/.cache/go-build" \ + BUILD_DATE_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S") && \ LD_FLAGS=$(/bin/ash -c "set -o pipefail && echo $LD_FLAGS | sed -e \"s/BUILD_DATE_TIME/$BUILD_DATE_TIME/g\"") && \ controller-gen object paths="./..." && \ - go build -a -ldflags="$LD_FLAGS" -o manager cmd/cache/main.go && \ - go build -a -ldflags="$LD_FLAGS" -o registry-proxy cmd/proxy/main.go + go build -ldflags="$LD_FLAGS" -o manager cmd/cache/main.go && \ + go build -ldflags="$LD_FLAGS" -o registry-proxy cmd/proxy/main.go FROM alpine:3.17 AS alpine