Cache go deps and build cache

This commit is contained in:
Jonny Stoten
2024-06-11 11:22:57 +01:00
parent 14099e3b98
commit db036df9d5

View File

@@ -14,7 +14,7 @@ COPY . .
# --- This block can be replaced by `RUN go mod download` when github.com/docker/attest is public
ENV GOPRIVATE="github.com/docker/attest"
RUN --mount=type=secret,id=GITHUB_TOKEN <<EOT
RUN --mount=type=cache,target=$GOPATH/pkg/mod --mount=type=secret,id=GITHUB_TOKEN <<EOT
set -e
GITHUB_TOKEN=${GITHUB_TOKEN:-$(cat /run/secrets/GITHUB_TOKEN)}
if [ -n "$GITHUB_TOKEN" ]; then
@@ -24,7 +24,8 @@ RUN --mount=type=secret,id=GITHUB_TOKEN <<EOT
go mod download
EOT
# ---
RUN make build
RUN --mount=type=cache,target=$GOPATH/pkg/mod --mount=type=cache,target=/root/.cache/go-build make build
FROM ${BASEIMAGE}