FROM python:3.12-slim AS base
WORKDIR /app

# Install server dependencies
COPY web/requirements.txt /tmp/
RUN pip install --no-cache-dir -r /tmp/requirements.txt

# ----------
FROM base AS builder
COPY web/static/generate_icons.py /tmp/
RUN python /tmp/generate_icons.py && mv icon-*.png /tmp/

# ----------
FROM base AS runner

# Game source
COPY main.py player.py scene.py function_list.py class_list.py race_list.py enum_list.py spell_list.py ./

# Web server
COPY web/server.py ./web/server.py
COPY web/static/index.html web/static/manifest.json web/static/sw.js ./web/static/
COPY --from=builder /tmp/icon-192.png /tmp/icon-512.png ./web/static/

EXPOSE 8080
CMD ["uvicorn", "web.server:app", "--host", "0.0.0.0", "--port", "8080"]
