Spaces:
Running
Running
# Use an official Python runtime as a parent image | |
FROM python:3.11-slim-buster | |
# Set the working directory inside the container | |
WORKDIR /app | |
# Install system dependencies required by Playwright, Git, and other libs | |
# This list is comprehensive for headless Chromium on Debian-based systems. | |
RUN apt-get update && apt-get install -y \ | |
# Core libraries for graphics/rendering (for browser) | |
fonts-liberation \ | |
libappindicator3-1 \ | |
libasound2 \ | |
libatk-bridge2.0-0 \ | |
libatk1.0-0 \ | |
libatspi2.0-0 \ | |
libcairo2 \ | |
libcups2 \ | |
libdbus-1-3 \ | |
libdrm2 \ | |
libgdk-pixbuf2.0-0 \ | |
libglib2.0-0 \ | |
libgtk-3-0 \ | |
libnspr4 \ | |
libnss3 \ | |
libpangocairo-1.0-0 \ | |
libxcomposite1 \ | |
libxdamage1 \ | |
libxext6 \ | |
libxfixes3 \ | |
libxrandr2 \ | |
libxrender1 \ | |
libxss1 \ | |
libxtst6 \ | |
# Specific to Chromium/GPU support (even if not using GPU, these are for display stack) | |
libgbm-dev \ | |
libasound2-dev \ | |
# xvfb provides a virtual display server, often necessary for headless browsers | |
xvfb \ | |
# Install Git, required by pip to clone proxy-lite from GitHub | |
git \ | |
# Install Chromium browser, though Playwright often manages its own, this ensures system deps are met | |
chromium \ | |
# Clean up apt caches to reduce image size | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy Python dependencies (only core Flask/Gunicorn deps, proxy-lite installed separately) | |
COPY requirements.txt . | |
# --- START: Critical steps for proxy-lite and permissions --- | |
# Create the directory that proxy-lite's recorder insists on writing to | |
# and grant full permissions. This is a workaround for the PermissionError. | |
RUN mkdir -p /app/src/proxy-lite/local_trajectories \ | |
&& chmod -R 777 /app/src/proxy-lite/local_trajectories | |
# Upgrade pip, setuptools, and wheel for a robust Python build environment. | |
# This addresses potential build issues with older versions. | |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel | |
# Install proxy-lite in "editable" mode directly from its GitHub repository. | |
# This explicitly tells pip to clone and link it, essential for its structure. | |
RUN pip install --no-cache-dir --no-input --force-reinstall -e git+https://github.com/convergence-ai/proxy-lite.git#egg=proxy-lite | |
# --- END: Critical steps for proxy-lite and permissions --- | |
# Install the rest of the common Python dependencies from requirements.txt | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy your Flask application code into the container | |
COPY . . | |
# Install Playwright browser binaries within the container | |
# This downloads the actual browser executables that Playwright controls. | |
RUN playwright install chromium | |
# Set environment variables for Playwright | |
# PLAYWRIGHT_BROWSERS_PATH: Tells Playwright where to find the installed browsers. | |
# DISPLAY, XDG_RUNTIME_DIR: Often needed for headless browser environments (xvfb). | |
ENV PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright/ | |
ENV DISPLAY=:99 | |
ENV XDG_RUNTIME_DIR=/tmp | |
# Expose the port your Flask app will listen on. Hugging Face Spaces requires 7860. | |
EXPOSE 7860 | |
# Define the command to run your Flask application using Gunicorn for production. | |
# --worker-class gevent is used because proxy-lite uses asyncio. | |
# --timeout 300s gives 5 minutes for tasks to complete. | |
CMD exec gunicorn --bind 0.0.0.0:7860 --workers 2 --worker-class gevent app:app --timeout 300 |