# Build from the repo root:  docker build -f deploy/Dockerfile -t activity-tracker .
#
# Multi-arch by construction: all the base images are published for arm64, and
# the Pi's CI (.gitea/workflows/ci.yaml) builds natively there. No
# `RUN --mount` cache lines, so it also builds on the Pi's legacy builder.
FROM node:24-alpine AS web
WORKDIR /src/web
COPY web/package.json web/package-lock.json ./
RUN npm ci
COPY web/ ./
# Writes ../internal/web/dist/app, which the Go build embeds.
RUN npm run build

FROM golang:1.27 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
COPY --from=web /src/internal/web/dist/app internal/web/dist/app
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/tracker ./cmd/tracker

FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/tracker /usr/local/bin/tracker
EXPOSE 8080
# distroless has no shell or wget, so the binary probes its own /readyz
# (process up and database reachable).
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD ["/usr/local/bin/tracker", "healthcheck"]
ENTRYPOINT ["/usr/local/bin/tracker"]
CMD ["serve"]
