From 603eeadfc404ca64b5fa50e22468b448680d1b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Sun, 19 Jan 2025 15:27:17 +0100 Subject: [PATCH] ci: Cache layers in Docker build --- .github/workflows/release.yml | 2 ++ Dockerfile | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f75286d..07ffd7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,6 +33,8 @@ jobs: with: context: . push: true + cache-from: type=gha + cache-to: type=gha,mode=max platforms: linux/arm64 # Disable provenance to prevent multi-platform index with unused layers like `unknown/unknown` # https://github.com/docker/buildx/issues/1509#issuecomment-1378538197 diff --git a/Dockerfile b/Dockerfile index 5a242c3..d5ac6ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,14 @@ FROM golang:1.23-alpine AS builder WORKDIR /builder-dir +COPY go.mod go.sum ./ +RUN go mod download COPY . ./ ENV CGO_ENABLED=1 RUN apk add --no-cache git build-base sqlite RUN go mod download RUN BUILD_TIME=$(date +"%Y-%m-%dT%H:%M:%S%z") && \ - GIT_COMMIT=$(git describe --always --dirty) && \ + GIT_COMMIT=$(git rev-parse --short HEAD) && \ go build -ldflags="-s -X main.commitSha=$GIT_COMMIT -X main.buildTime=$BUILD_TIME" -o bin cmd/server/main.go FROM alpine:latest @@ -17,4 +19,3 @@ COPY --from=builder /builder-dir/bin bin COPY --from=builder /builder-dir/internal/db/migrations internal/db/migrations EXPOSE 3001 CMD ["./bin/main"] -