Spaces:
Sleeping
Sleeping
| # ============================================ | |
| # Dockerfile for Hugging Face Spaces | |
| # Novel Scraper with Playwright | |
| # ============================================ | |
| # --- Stage 1: Use Python 3.10 slim base --- | |
| FROM python:3.10-slim-bookworm | |
| # --- Hugging Face requires port 7860 --- | |
| ENV PORT=7860 | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # --- Create non-root user (HF requirement) --- | |
| RUN useradd -m -u 1000 user | |
| # --- Install system dependencies for Playwright --- | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| # Playwright browser dependencies | |
| libnss3 \ | |
| libnspr4 \ | |
| libatk1.0-0 \ | |
| libatk-bridge2.0-0 \ | |
| libcups2 \ | |
| libdrm2 \ | |
| libdbus-1-3 \ | |
| libxkbcommon0 \ | |
| libatspi2.0-0 \ | |
| libxcomposite1 \ | |
| libxdamage1 \ | |
| libxfixes3 \ | |
| libxrandr2 \ | |
| libgbm1 \ | |
| libpango-1.0-0 \ | |
| libcairo2 \ | |
| libasound2 \ | |
| libwayland-client0 \ | |
| # Additional libs often needed | |
| libglib2.0-0 \ | |
| libgtk-3-0 \ | |
| libx11-xcb1 \ | |
| fonts-liberation \ | |
| fonts-noto-cjk \ | |
| wget \ | |
| ca-certificates \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # --- Set working directory --- | |
| WORKDIR /home/user/app | |
| # --- Copy requirements first (Docker cache optimization) --- | |
| COPY --chown=user:user requirements.txt . | |
| # --- Install Python dependencies --- | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # --- Install Playwright browsers (Chromium only to save space) --- | |
| # Must run as user who will execute the app | |
| USER user | |
| RUN playwright install chromium | |
| # --- Copy application code --- | |
| COPY --chown=user:user . . | |
| # --- Create screenshots directory --- | |
| RUN mkdir -p /home/user/app/app/static/screenshots | |
| # --- Expose the port --- | |
| EXPOSE 7860 | |
| # --- Health check --- | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ | |
| CMD python -c "import httpx; httpx.get('http://localhost:7860/health')" || exit 1 | |
| # --- Start the application --- | |
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"] |