# PPI Benchmark Studio: one image for the shared server and for local use.
# Stage 1 builds the web UI; stage 2 runs the API, the job workers and serves the UI.
FROM node:22.11.0-bookworm-slim AS web
WORKDIR /build/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci --no-audit --no-fund
COPY frontend/ ./
RUN npx tsc -b && npx vite build --outDir /build/static

FROM python:3.10.16-slim-bookworm
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 \
    STUDIO_STORAGE=/data STUDIO_EXAMPLES=/app/examples STUDIO_STATIC=/app/static \
    MPLCONFIGDIR=/tmp/mpl
RUN useradd --create-home --uid 1000 studio
WORKDIR /app
COPY pyproject.toml ./
COPY engine/ engine/
COPY api/studio_api/*.py api/studio_api/
RUN pip install --no-cache-dir ".[full]"
COPY examples/ examples/
COPY --from=web /build/static /app/static
RUN mkdir -p /data && chown studio:studio /data
USER studio
VOLUME ["/data"]
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=5s CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/api/health')"
CMD ["uvicorn", "studio_api.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers", "--forwarded-allow-ips", "*"]
