From d4d6830ac5ee4b4538c66a4f1af9341d765ba5e7 Mon Sep 17 00:00:00 2001 From: Benjamin Schimke Date: Fri, 28 Jun 2024 08:43:21 +0200 Subject: [PATCH] ci fixup --- Dockerfile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a1ab82c3..6a315477 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,12 +31,17 @@ WORKDIR /workspace # Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy ARG goproxy=https://proxy.golang.org # Run this with docker build --build-arg package=./controlplane/kubeadm or --build-arg package=./bootstrap/kubeadm -ENV GOPROXY=$goproxy +ENV GOPROXY=direct # Copy the Go Modules manifests COPY go.mod go.mod COPY go.sum go.sum +# Cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + # Copy the sources COPY ./ ./ @@ -45,7 +50,10 @@ ARG package=. ARG ARCH ARG ldflags -Run CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \ +# Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \ go build -trimpath -ldflags "${ldflags} -extldflags '-static'" \ -o manager ${package}