From c070a46087e1bdaa4d50d186404134d09f1d3fbc 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 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/linux/Dockerfile b/linux/Dockerfile index 217be7e..ab24d96 100644 --- a/linux/Dockerfile +++ b/linux/Dockerfile @@ -3,19 +3,22 @@ # ----------- FROM golang:1.21-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