From 827a103cee5291d524a58339910858fbef32aa44 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Mon, 4 Aug 2025 21:59:17 +1000 Subject: [PATCH] fix: Speed up docker build --- .github/workflows/ci.yml | 4 ++++ Dockerfile | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47c06d4..1875f19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,6 +105,10 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + build-args: | + BUILDKIT_INLINE_CACHE=1 + GOCACHE=/root/.cache/go-build + GOMODCACHE=/go/pkg/mod lint: runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index 3a01417..0d48536 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,26 @@ # Build stage FROM golang:1.23-alpine AS builder -# Install git for Go modules (no need for gcc or sqlite-dev anymore) +# Install git for Go modules RUN apk add --no-cache git WORKDIR /app -# Copy go mod files +# Copy go mod files first for better layer caching COPY go.mod go.sum ./ -# Download dependencies +# Download dependencies (this will be cached if go.mod/go.sum don't change) RUN go mod download # Copy source code COPY . . -# Build the application with pure Go (no CGO needed) -RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o passkey-auth . +# Build the application with optimized flags and build cache +# Remove -a flag to avoid rebuilding standard library +# Remove unnecessary static linking flags since CGO is disabled +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o passkey-auth . # Final stage FROM alpine:latest