From 9c2cf45d5eb72ce76edff239fda0c6af17e423f6 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Thu, 14 Mar 2024 08:55:14 +0000 Subject: [PATCH] chore: add caching to Linux docker run Add cache mount directives to Linux docker container so that reruns are much quicker. --- linux/Dockerfile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/linux/Dockerfile b/linux/Dockerfile index 2de797d..1528347 100644 --- a/linux/Dockerfile +++ b/linux/Dockerfile @@ -3,19 +3,23 @@ # ----------- FROM golang:1.21-alpine3.19 as build -# Go build env -ENV CGO_ENABLED=0 - WORKDIR /app +# Go build env +ENV CGO_ENABLED=0 \ + GOCACHE=/go-cache \ + GOMODCACHE=/gomod-cache + # Install source deps COPY go.mod go.sum ./ -RUN go mod download +RUN --mount=type=cache,target=/gomod-cache \ + go mod download # Copy source & build COPY . . -RUN go build -v -ldflags '-s' -o /bin/ryuk -RUN chmod +x /bin/ryuk +RUN --mount=type=cache,target=/gomod-cache \ + --mount=type=cache,target=/go-cache \ + go build -v -ldflags '-s' -o /bin/ryuk # ----------------- # Distributed Image