# syntax=docker/dockerfile:1

# ---------------------------------------------------------------------------
# Stage 1: Build the Frontend (React/Vite) into static assets.
# ---------------------------------------------------------------------------
FROM node:22-alpine AS frontend-build
WORKDIR /Frontend

COPY Frontend/package*.json ./
RUN npm install

COPY Frontend/ ./
RUN npm run build

# ---------------------------------------------------------------------------
# Stage 2: Runtime image running the API (FastAPI/uvicorn), serving the
# built Frontend as static files from the same process/port.
# ---------------------------------------------------------------------------
FROM python:3.14-slim AS runtime
WORKDIR /app

# Install Python dependencies first for better layer caching.
COPY Api/requirements.txt ./Api/requirements.txt
RUN pip install --no-cache-dir -r Api/requirements.txt

# Copy application code and the LLM system prompt used at runtime.
COPY Api/ ./Api/
COPY Prompts/ ./Prompts/

# Copy the built Frontend from the build stage into the expected location
# (Api/config.py -> FRONTEND_DIST_DIR = PROJECT_ROOT / "Frontend" / "dist").
COPY --from=frontend-build /Frontend/dist ./Frontend/dist

# Persisted data (sqlite DB, mod/game assets) should be mounted as volumes.
VOLUME ["/app/Api/Mods", "/app/Api/Games"]

EXPOSE 8000

# Secrets are provided as environment variables at "docker run" time, e.g.:
#   -e PROVIDER_NEXUS_SECRET=... -e LLM_OPENROUTER_SECRET=...

CMD ["uvicorn", "main:app", "--app-dir", "Api", "--host", "0.0.0.0", "--port", "8000"]
