# quantum-spherifier v1.0 — Dockerfile
# Multi-stage build for a lean production image

FROM node:20-slim AS base
WORKDIR /app

# Install system dependencies (including pdflatex for PDF generation)
RUN apt-get update && apt-get install -y --no-install-recommends \
    texlive-latex-base \
    texlive-latex-recommended \
    texlive-latex-extra \
    texlive-fonts-recommended \
    && rm -rf /var/lib/apt/lists/*

# Copy package files and install dependencies
COPY package.json package-lock.json* ./
RUN npm install --omit=dev

# Copy source
COPY . .

# Create runtime directories
RUN mkdir -p /app/research /app/data

# Environment
ENV QSPHERIFIER_RESEARCH_DIR=/app/research
ENV QSPHERIFIER_PORT=3000
ENV QSPHERIFIER_HOST=0.0.0.0
ENV NODE_ENV=production

EXPOSE 3000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
  CMD node -e "fetch('http://localhost:3000/api/status').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"

CMD ["node", "web/server.js"]
