Adds the canonical .gitignore, .dockerignore and .editorconfig; the first two also name this repo's build output, root-anchored so cmd/bsdaily/ stays in. The Dockerfile gains a lint phase on the golangci-lint image already pinned and a test phase on the Debian Go image with sqlite3 and zstd; the build stage copies a file from each, so a plain docker build cannot skip them. script/lint and script/test build their phase uncached and tagged; script/cibuild, script/docker and the CI workflow are the canonical copies. Nothing installs golangci-lint on the host. REPO_POLICIES.md is re-vendored. .golangci.yml and the lint cleanup: #6 Judgement call: .gitignore adds Go build output, per the Go styleguide. Model: opus-5-5
This commit is contained in:
+31
-14
@@ -1,9 +1,9 @@
|
||||
# Lint stage
|
||||
# Lint phase. The linter is invoked directly rather than through `make
|
||||
# lint` or `script/lint`, which are themselves a docker build and would
|
||||
# recurse into a daemon that does not exist in a build step.
|
||||
# golangci/golangci-lint:v2.12.2-alpine
|
||||
FROM golangci/golangci-lint:v2.12.2-alpine@sha256:91b27804074a0bacea298707f016911e60cf0cdbc6c7bf5ccacb5f0606d18d60 AS lint
|
||||
|
||||
RUN apk add --no-cache make build-base
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# Copy go mod files first for better layer caching
|
||||
@@ -13,22 +13,42 @@ RUN go mod download
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Run formatting check and linter
|
||||
RUN make fmt-check
|
||||
RUN make lint
|
||||
RUN golangci-lint run ./...
|
||||
|
||||
# Build stage
|
||||
# Test phase, invoking `go test` directly for the same reason. -race
|
||||
# needs cgo and so a C compiler, which the Debian Go image ships and the
|
||||
# alpine one does not. The tool shells out to sqlite3, zstdmt and
|
||||
# zstdcat, so tests that run it need them installed.
|
||||
# golang:1.26.4-trixie, 2026-10-05
|
||||
FROM golang:1.26.4-trixie@sha256:68b7145ec43d1820b9a56704554b53d1520aa2a15cb5233e374188a31b2a1bce AS test
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends sqlite3 zstd \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN go test -timeout 90s -race -cover ./... || \
|
||||
{ echo "--- Rerunning with -v for details ---"; \
|
||||
go test -timeout 90s -race -v ./...; exit 1; }
|
||||
|
||||
# Build stage. Nothing is wanted from either phase above; the copies
|
||||
# are what make BuildKit build them first, so this stage cannot run
|
||||
# unless lint and test passed. A plain `docker build .` builds only the
|
||||
# last stage and what it depends on, so the runtime stage stays last.
|
||||
# golang:1.26.4-alpine
|
||||
FROM golang:1.26.4-alpine@sha256:3ad57304ad93bbec8548a0437ad9e06a455660655d9af011d58b993f6f615648 AS builder
|
||||
|
||||
# Depend on lint stage passing
|
||||
COPY --from=lint /src/go.sum /dev/null
|
||||
COPY --from=test /src/go.sum /dev/null
|
||||
|
||||
ARG VERSION=dev
|
||||
|
||||
# Install build deps plus the sqlite3 and zstd CLIs the tests/tool shell out to
|
||||
RUN apk add --no-cache make build-base sqlite zstd
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# Copy go mod files first for better layer caching
|
||||
@@ -38,9 +58,6 @@ RUN go mod download
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Run tests
|
||||
RUN make test
|
||||
|
||||
# Build (pure Go, no CGO required since we use modernc.org/sqlite)
|
||||
RUN CGO_ENABLED=0 go build -o /bsdaily ./cmd/bsdaily
|
||||
|
||||
|
||||
Reference in New Issue
Block a user