# Lint phase, built alone by script/lint. The linter is invoked directly # rather than through `make lint`, which is itself a docker build and # would recurse into a daemon that does not exist in a build step. The # image is Debian-based and has Go and gcc, so it can check the cgo # SQLite package without extra installs. # golangci/golangci-lint:v2.14.0 (Go 1.27.0), 2026-10-14 FROM golangci/golangci-lint@sha256:ad862ba6b3798cbe0fd9fd7408d498fd74fbd2623a92406b2fd3898faf0bf98f AS lint WORKDIR /src COPY go.mod go.sum ./ RUN go mod download COPY . . RUN golangci-lint run --config .golangci.yml ./... # Test phase, built alone by script/test. -race needs cgo and so a C # compiler, which the Debian Go image ships. -short skips the live RIPE RIS # feed test, so the suite needs no network. The rerun with -v only shows # details: the build fails however it ends, because the first run failed. # golang:1.24-bookworm, 2026-09-21 FROM golang@sha256:1a6d4452c65dea36aac2e2d606b01b4a029ec90cc1ae53890540ce6173ea77ac AS test WORKDIR /src COPY go.mod go.sum ./ RUN go mod download COPY . . RUN go test -short -timeout 90s -race -cover ./... || \ { echo "--- Rerunning with -v for details ---"; \ go test -short -timeout 90s -race -v ./...; exit 1; } # Build stage. Nothing is wanted from the lint and test phases; the copies # are what make BuildKit build them first, so this stage cannot run unless # lint and test passed. # golang:1.24-bookworm, 2026-09-21 FROM golang@sha256:1a6d4452c65dea36aac2e2d606b01b4a029ec90cc1ae53890540ce6173ea77ac AS builder COPY --from=lint /src/go.sum /dev/null COPY --from=test /src/go.sum /dev/null # Install build dependencies (zstd for archive, gcc for CGO/sqlite3) RUN apt-get update && apt-get install -y --no-install-recommends \ zstd \ gcc \ libc6-dev \ && rm -rf /var/lib/apt/lists/* # A tar-stream context keeps the sender's file owners, which git refuses. RUN git config --system --add safe.directory /src WORKDIR /src # Copy everything COPY . . # Vendor dependencies (must be after copying source) RUN go mod download && go mod vendor # Build the binary with CGO enabled (required for sqlite3). The version the # page footer shows is the VERSION build argument when one is given, otherwise # `git describe --tags --always` of the .git in the build context (git comes # with this image): the tag on a tagged commit, tag-N-gHASH after one, the # short commit when no tag is reachable. A context that carries .git and still # yields no version fails the build. The footer links to the full commit. ARG VERSION RUN version="${VERSION:-$(git describe --tags --always || echo unknown)}"; \ if [ -e .git ] && { [ -z "$version" ] || [ "$version" = dev ] || \ [ "$version" = unknown ]; }; then \ echo "no version could be derived although the build context carries .git" >&2; \ exit 1; \ fi; \ CGO_ENABLED=1 GOOS=linux go build -o /routewatch -ldflags "\ -X git.eeqj.de/sneak/routewatch/internal/version.GitRevision=$(git rev-parse --verify HEAD || echo unknown) \ -X git.eeqj.de/sneak/routewatch/internal/version.GitRevisionShort=$version" \ ./cmd/routewatch # Create source archive with vendored dependencies RUN tar --zstd -cf /routewatch-source.tar.zst \ --exclude='.git' \ --exclude='*.tar.zst' \ . # Runtime stage # debian:bookworm-slim, 2026-09-21 FROM debian@sha256:3783cc01769c7b2b1b83a5c5ad96c815348e28ed7da68e2e3687004faa906251 # Install runtime dependencies # - ca-certificates: for HTTPS connections # - curl: for health checks RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ && rm -rf /var/lib/apt/lists/* # Create non-root user RUN useradd -r -u 1000 -m routewatch RUN mkdir -p /var/lib/berlin.sneak.app.routewatch && chown routewatch:routewatch /var/lib/berlin.sneak.app.routewatch RUN mkdir /app WORKDIR /app # Copy binary and source archive from builder COPY --from=builder /routewatch /app/routewatch COPY --from=builder /routewatch-source.tar.zst /app/source/routewatch-source.tar.zst # Set ownership RUN chown -R routewatch:routewatch /app ENV XDG_DATA_HOME=/var/lib # Cap the Go heap at 1.5 GiB so the runtime collects harder before the # container's memory limit is reached. setpriv in the entrypoint preserves this # the way it does XDG_DATA_HOME above. ENV GOMEMLIMIT=1536MiB # Cap glibc's malloc arenas. The SQLite C library allocates and frees millions # of small page-cache chunks from many threads; glibc otherwise creates up to # eight arenas per core (hundreds on a large host) and keeps each arena's freed # chunks resident, so process RSS climbs far above SQLite's live heap and never # comes back down. Two arenas keep that retained memory bounded; database writes # are already serialized, so the lost allocator concurrency costs nothing here. ENV MALLOC_ARENA_MAX=2 # Expose HTTP port EXPOSE 8080 COPY ./entrypoint.sh /entrypoint.sh # Health check using the health endpoint, on the port PORT names HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ CMD curl -sf "http://localhost:${PORT:-8080}/.well-known/healthcheck.json" || exit 1 ENTRYPOINT ["/bin/bash", "/entrypoint.sh" ]