| FROM python:3.11-slim | |
| # Playwright/Chromium system dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| # Chromium dependencies | |
| libnss3 \ | |
| libnspr4 \ | |
| libatk1.0-0 \ | |
| libatk-bridge2.0-0 \ | |
| libcups2 \ | |
| libdrm2 \ | |
| libxkbcommon0 \ | |
| libxcomposite1 \ | |
| libxdamage1 \ | |
| libxrandr2 \ | |
| libgbm1 \ | |
| libpango-1.0-0 \ | |
| libcairo2 \ | |
| libasound2 \ | |
| libatspi2.0-0 \ | |
| libxshmfence1 \ | |
| # Font rendering | |
| fonts-liberation \ | |
| fontconfig \ | |
| # General utilities | |
| wget \ | |
| && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| # Install Python dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Set browser path BEFORE install so Playwright puts browsers here | |
| ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright | |
| # Install Playwright Chromium browser + all required system deps | |
| RUN playwright install --with-deps chromium | |
| # Copy application code | |
| COPY app/ ./app/ | |
| # Copy static assets (fonts & images used for PDF rendering) | |
| COPY fonts/ ./fonts/ | |
| COPY images/ ./images/ | |
| # Copy env example as fallback | |
| COPY .env.example .env.example | |
| # Hugging Face Spaces uses port 7860 by default | |
| ENV PORT=7860 | |
| EXPOSE 7860 | |
| # Production command — single worker to stay within HF Spaces memory limits | |
| # Playwright + Chromium is memory-heavy; 2 workers causes OOM restarts | |
| CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860} --workers 1 --timeout-keep-alive 120"] | |