Spaces:
Sleeping
Sleeping
Create dockerfile
Browse files- dockerfile +55 -0
dockerfile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# =============== Hugging Face Spaces Official Base (2025) ===============
|
| 2 |
+
# This is the exact base image HF recommends for Playwright apps
|
| 3 |
+
FROM python:3.10-slim-bookworm
|
| 4 |
+
|
| 5 |
+
# Set environment variables (critical for headless + no buffering)
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
+
PYTHONUNBUFFERED=1 \
|
| 8 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 9 |
+
PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright
|
| 10 |
+
|
| 11 |
+
# Create non-root user (required by Hugging Face security policy)
|
| 12 |
+
RUN useradd -m -s /bin/bash appuser
|
| 13 |
+
|
| 14 |
+
# Install system basics + Playwright dependencies in one layer
|
| 15 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 16 |
+
ca-certificates \
|
| 17 |
+
wget \
|
| 18 |
+
gnupg \
|
| 19 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 20 |
+
|
| 21 |
+
# Set workdir
|
| 22 |
+
WORKDIR /home/appuser/app
|
| 23 |
+
|
| 24 |
+
# Copy requirements first (maximizes cache)
|
| 25 |
+
COPY requirements.txt .
|
| 26 |
+
|
| 27 |
+
# Install Python packages
|
| 28 |
+
RUN pip install --upgrade --no-cache-dir pip && \
|
| 29 |
+
pip install --no-cache-dir -r requirements.txt
|
| 30 |
+
|
| 31 |
+
# ========= THIS IS THE MAGIC LINE FOR HUGGING FACE =========
|
| 32 |
+
# Installs Playwright + browsers + ALL system dependencies automatically
|
| 33 |
+
RUN pip install playwright && \
|
| 34 |
+
playwright install --with-deps chromium
|
| 35 |
+
# ===========================================================
|
| 36 |
+
# (We only need Chromium — saves ~300MB vs installing all browsers)
|
| 37 |
+
|
| 38 |
+
# Copy your app code
|
| 39 |
+
COPY . .
|
| 40 |
+
|
| 41 |
+
# Fix permissions
|
| 42 |
+
RUN chown -R appuser:appuser /home/appuser
|
| 43 |
+
|
| 44 |
+
# Switch to non-root user (mandatory on HF)
|
| 45 |
+
USER appuser
|
| 46 |
+
|
| 47 |
+
# Expose Gradio default port
|
| 48 |
+
EXPOSE 7860
|
| 49 |
+
|
| 50 |
+
# Healthcheck (HF loves this)
|
| 51 |
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=90s --retries=3 \
|
| 52 |
+
CMD wget --no-verbose --tries=1 --spider http://localhost:7860 || exit 1
|
| 53 |
+
|
| 54 |
+
# Start the app (standard for Gradio on HF Spaces)
|
| 55 |
+
CMD ["python", "app.py"]
|