Multi-stage Go build with distroless runtime

Dockerfile
# syntax=docker/dockerfile:1

# Build stage: compile a static binary.
FROM golang:1.24-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/app .

# Runtime stage: distroless keeps the image tiny and shell-free.
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/app /app
USER nonroot:nonroot
EXPOSE 8080
# The binary should implement a -healthcheck flag for this probe.
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD ["/app", "-healthcheck"]
ENTRYPOINT ["/app"]