# goodNews web/API image (multi-stage: build the SvelteKit site, then serve it
# from the FastAPI app).
#
# The SQLite database is NOT baked in — mount it at /data so the API and the
# ingestion CLI (run separately, e.g. via cron/systemd on the host) share one
# file. Build:  docker build -t goodnews .
# Run:    docker run -p 8000:8000 -v /srv/goodnews/data:/data goodnews

# --- Stage 1: build the static frontend ---
FROM node:22-slim AS web
WORKDIR /web
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build

# --- Stage 2: the Python API, serving the built site ---
FROM python:3.13-slim
WORKDIR /app

COPY pyproject.toml README.md ./
COPY goodnews ./goodnews
RUN pip install --no-cache-dir ".[web]"

# FastAPI serves this directory (goodnews/api.py: FRONTEND_DIR = ROOT/frontend/build).
COPY --from=web /web/build ./frontend/build

ENV GOODNEWS_DB=/data/goodnews.sqlite3
VOLUME ["/data"]

EXPOSE 8000
CMD ["uvicorn", "goodnews.api:app", "--host", "0.0.0.0", "--port", "8000"]
