# Volleyboard — multi-stage build. Node exists ONLY in the build stage
# (react.md: no Node at runtime). The runtime image is one Python process
# serving the API and the pre-built SPA. Container listens on :8000; the gateway
# maps host 172.17.0.1:<port> -> container :8000.

# ---- stage 1: build the Vite SPA ----
FROM node:22-alpine AS frontend
WORKDIR /fe
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build   # -> /fe/dist

# ---- stage 2: python runtime ----
FROM python:3.12-slim AS runtime
WORKDIR /app
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    STATIC_DIR=/app/static

COPY backend/requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY backend/ ./
COPY --from=frontend /fe/dist ./static
# Seed tooling ships in the image so the one-time production seed is a
# `docker compose exec app python tools/load-seed.py` — the db has no host
# port (internal network only), so seeding must run from inside.
COPY tools/ ./tools/
COPY seed/ ./seed/

RUN chmod +x entrypoint.sh
EXPOSE 8000
CMD ["./entrypoint.sh"]
