From de38b0350813d53a494e5f7babbe4c96cab72cef Mon Sep 17 00:00:00 2001 From: clawbot Date: Mon, 2 Mar 2026 00:05:52 -0800 Subject: [PATCH] feat: split Dockerfile into dedicated lint and build stages - Add dedicated lint stage using pre-built golangci-lint v2.10.1 image - Move fmt-check and lint from build stage to lint stage for faster feedback - Remove manual golangci-lint binary download (now handled by lint image) - Remove curl from build stage dependencies (no longer needed) - Add COPY --from=lint dependency to force BuildKit to run lint stage - Build stage now runs only tests and compilation closes https://git.eeqj.de/sneak/pixa/issues/20 --- Dockerfile | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 48fd5ca..bd3483a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,38 @@ -# Build stage +# Lint stage — fast feedback on formatting and lint issues +# golangci/golangci-lint:v2.10.1, 2026-03-01 +FROM golangci/golangci-lint@sha256:ea84d14c2fef724411be7dc45e09e6ef721d748315252b02df19a7e3113ee763 AS lint + +# Install CGO dependencies needed for static analysis of vips/libheif code +RUN apt-get update && apt-get install -y --no-install-recommends \ + libvips-dev \ + libheif-dev \ + pkg-config \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make fmt-check +RUN make lint + +# Build stage — tests and compilation # golang:1.25.4-alpine, 2026-02-25 FROM golang:1.25.4-alpine@sha256:d3f0cf7723f3429e3f9ed846243970b20a2de7bae6a5b66fc5914e228d831bbb AS builder ARG VERSION=dev +# Force BuildKit to run the lint stage by creating a stage dependency +COPY --from=lint /src/go.sum /dev/null + # Install build dependencies for CGO image libraries RUN apk add --no-cache \ build-base \ vips-dev \ libheif-dev \ - pkgconfig \ - curl - -# golangci-lint v2.10.1, 2026-02-25 -# SHA-256 checksums per architecture (amd64 / arm64) -RUN set -e; \ - ARCH="$(uname -m)"; \ - if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then \ - GOARCH="arm64"; \ - HASH="6652b42ae02915eb2f9cb2a2e0cac99514c8eded8388d88ae3e06e1a52c00de8"; \ - else \ - GOARCH="amd64"; \ - HASH="dfa775874cf0561b404a02a8f4481fc69b28091da95aa697259820d429b09c99"; \ - fi; \ - curl -sSfL "https://github.com/golangci/golangci-lint/releases/download/v2.10.1/golangci-lint-2.10.1-linux-${GOARCH}.tar.gz" -o /tmp/golangci-lint.tar.gz && \ - echo "${HASH} /tmp/golangci-lint.tar.gz" | sha256sum -c - && \ - tar -xzf /tmp/golangci-lint.tar.gz -C /tmp && \ - mv "/tmp/golangci-lint-2.10.1-linux-${GOARCH}/golangci-lint" /usr/local/bin/ && \ - rm -rf /tmp/golangci-lint* + pkgconfig WORKDIR /src @@ -38,8 +43,8 @@ RUN GOTOOLCHAIN=auto go mod download # Copy source code COPY . . -# Run all checks (fmt-check, lint, test) -RUN make check +# Run tests +RUN make test # Build with CGO enabled RUN CGO_ENABLED=1 GOTOOLCHAIN=auto go build -ldflags "-X main.Version=${VERSION}" -o /pixad ./cmd/pixad