# Build context is services/alertstore.

FROM node:24-bookworm-slim AS web
WORKDIR /web
COPY web/package.json web/package-lock.json ./
RUN npm ci
COPY web/ ./
RUN npm run build

FROM golang:1.25 AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o alertstore ./cmd/alertstore

FROM debian:bookworm-slim
RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates tzdata \
    && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /app/alertstore /app/alertstore
COPY config.yaml /app/config.yaml
# Flattened into /app/web rather than /app/web/dist: the environment's ConfigMap
# replaces /app/web/runtime-config.js, so the build output has to land on that
# path. runtime-config.js ships here as a placeholder.
COPY --from=web /web/dist/ /app/web/
COPY migrations/ /app/migrations/
EXPOSE 8080
ENTRYPOINT ["/app/alertstore"]
