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/rainstats ./cmd/rainstats
RUN mkdir -p /out/data

FROM scratch
WORKDIR /app
USER 65532:65532
COPY --from=build /out/rainstats /rainstats
COPY --from=build --chown=65532:65532 /out/data /data
ENTRYPOINT ["/rainstats"]
