From 37ef1411ceb252e007bf91079bf69e8cf047fdd0 Mon Sep 17 00:00:00 2001 From: Blake Pettersson Date: Fri, 22 Sep 2023 12:48:16 +0200 Subject: [PATCH] build: cache go mod For local development, to remove the step where go modules are downloaded on every `docker build`, first copy only `go.mod` and `go.sum` to the Docker workspace. This step only needs to be performed whenever one of those files changes. Signed-off-by: Blake Pettersson --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0f8e1c61..f9fca9bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,15 +4,14 @@ ARG LD_FLAGS='-s -w -linkmode external -extldflags "-static"' ARG TARGETPLATFORM WORKDIR /app -COPY . . RUN export GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \ export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) -RUN go env +COPY go.* ./ +RUN go env && go mod download -RUN go get -d -v \ - && go install -v +COPY . . RUN CGO_ENABLED=1 go build -ldflags="${LD_FLAGS}" -tags="sqlite_unlock_notify" -o /app/build/policyreporter -v