# syntax=docker/dockerfile:1

FROM golang:1.27-alpine AS build
WORKDIR /src

# Dependencies are only the standard library today; the explicit copy keeps
# the module cache layer stable when that changes.
COPY go.mod ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build \
    -trimpath -ldflags="-s -w" \
    -o /out/api ./cmd/api

FROM gcr.io/distroless/static-debian12:nonroot
WORKDIR /app

COPY --from=build /out/api /app/api
# Baked fallback data lives in the image; there is no runtime data fetch.
COPY --from=build /src/testdata/data /app/data

ENV DATA_DIR=/app/data \
    PORT=8080

EXPOSE 8080
USER nonroot:nonroot

ENTRYPOINT ["/app/api"]
