# nexor-agora hub — FastAPI + prebuilt Svelte SPA. Self-contained (pip, no workspace).

# Stage 1 — build the Svelte SPA (Vite). Output lands in src/nexor_agora/frontend.
FROM node:22-slim AS frontend
WORKDIR /app/web
COPY web/package.json web/package-lock.json* ./
RUN npm ci
COPY web/ ./
RUN npm run build

# Stage 2 — Python runtime. Copies the built SPA in before installing the package
# (the wheel force-includes src/nexor_agora/frontend — see pyproject.toml).
FROM python:3.12-slim

WORKDIR /app

COPY pyproject.toml README.md ./
COPY src/ ./src/
COPY --from=frontend /app/src/nexor_agora/frontend ./src/nexor_agora/frontend

RUN pip install --no-cache-dir .

ENV NEXOR_AGORA_HOST=0.0.0.0 \
    NEXOR_AGORA_PORT=8400 \
    NEXOR_AGORA_LOG_LEVEL=INFO

EXPOSE 8400

HEALTHCHECK --interval=15s --timeout=5s --retries=5 --start-period=15s \
    CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8400/api/v1/health').status==200 else 1)" || exit 1

CMD ["python", "-m", "nexor_agora", "serve"]
