From 2f52f35720c64ecdae3030c86eab0cf9ab2410c8 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Thu, 18 Jul 2024 15:58:16 +0300 Subject: [PATCH] Dockerfile: cache go modules on build --- Dockerfile | 6 ++++-- Dockerfile_generator | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6bbbf81c2..b6bb7b30f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,8 @@ COPY api/nfd/go.mod api/nfd/go.sum /go/node-feature-discovery/api/nfd/ WORKDIR /go/node-feature-discovery -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod/ \ + go mod download # Do actual build COPY . /go/node-feature-discovery @@ -19,7 +20,8 @@ COPY . /go/node-feature-discovery ARG VERSION ARG HOSTMOUNT_PREFIX -RUN make install VERSION=$VERSION HOSTMOUNT_PREFIX=$HOSTMOUNT_PREFIX +RUN --mount=type=cache,target=/go/pkg/mod/ \ + make install VERSION=$VERSION HOSTMOUNT_PREFIX=$HOSTMOUNT_PREFIX # Create full variant of the production image FROM ${BASE_IMAGE_FULL} AS full diff --git a/Dockerfile_generator b/Dockerfile_generator index a41ebbd9a..c558c2d78 100644 --- a/Dockerfile_generator +++ b/Dockerfile_generator @@ -2,7 +2,8 @@ ARG BUILDER_IMAGE FROM ${BUILDER_IMAGE} as builder # Install tools -RUN go install github.com/vektra/mockery/v2@v2.42.0 && \ +RUN --mount=type=cache,target=/go/pkg/mod/ \ + go install github.com/vektra/mockery/v2@v2.42.0 && \ go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0 && \ go install golang.org/x/tools/cmd/goimports@v0.11.0 && \ go install github.com/golang/protobuf/protoc-gen-go@v1.4.3