From d0c3b50e8f67a57e4ee418b9598db5916f9a5d69 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Wed, 9 Oct 2024 08:59:54 +0100 Subject: [PATCH] chore: add caching to Linux docker run (#123) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add cache mount directives to Linux docker container so that reruns are much quicker. Co-authored-by: Manuel de la Peña --- linux/Dockerfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/linux/Dockerfile b/linux/Dockerfile index e37d649..75b406b 100644 --- a/linux/Dockerfile +++ b/linux/Dockerfile @@ -3,19 +3,22 @@ # ----------- FROM golang:1.23-alpine3.19 AS build +WORKDIR /app + # Go build env ENV CGO_ENABLED=0 -WORKDIR /app - # Install source deps COPY go.mod go.sum ./ -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download # Copy source & build -COPY . . -RUN go build -v -ldflags '-s' -o /bin/ryuk -RUN chmod +x /bin/ryuk +COPY --link . . + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -ldflags '-s' -o /bin/ryuk # ----------------- # Distributed Image