Spaces:
Running
Running
# Use an official Playwright Docker image for Python, matching your Playwright version and Debian base | |
FROM mcr.microsoft.com/playwright/python:v1.53.0-noble | |
# Set the working directory inside the container | |
WORKDIR /app | |
# The official Playwright image comes with most necessary system dependencies, | |
# so we only need to add git for proxy-lite and potentially any very specific missing libs. | |
# Removing the extensive list as it's largely redundant with the Playwright base image. | |
RUN apt-get update && apt-get install -y \ | |
git \ | |
xvfb \ | |
# Clean up apt caches to reduce image size | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy common Python dependencies first (needed for pip installs) | |
COPY requirements.txt . | |
# --- START: Core Python and proxy-lite setup --- | |
# Upgrade pip, setuptools, and wheel for a robust Python build environment. | |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel | |
# Install proxy-lite in "editable" mode directly from its GitHub repository. | |
# The Playwright base image already has Playwright installed, so this just handles proxy-lite | |
RUN pip install --no-cache-dir --no-input --force-reinstall -e git+https://github.com/convergence-ai/proxy-lite.git#egg=proxy-lite | |
# Install the rest of the Python dependencies from requirements.txt | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy your Flask application code (app.py) and other project files. | |
COPY . . | |
# --- START: Directory permission workaround --- | |
# Create the directory proxy-lite's recorder insists on writing to | |
# and grant full permissions. This addresses the PermissionError. | |
RUN mkdir -p /app/src/proxy-lite/local_trajectories \ | |
&& chmod -R 777 /app/src/proxy-lite/local_trajectories | |
# --- END: Directory permission workaround --- | |
# Set environment variables required for Playwright at runtime | |
ENV DISPLAY=:99 | |
ENV XDG_RUNTIME_DIR=/tmp | |
# This environment variable is set implicitly by the Playwright base image, | |
# but it's good practice to ensure it's here if ever changing base images. | |
ENV PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright/ | |
# Ensure Playwright doesn't try to re-download browsers at runtime | |
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 | |
# --- Debugging: Check Playwright version and browser installation (moved AFTER install in the original setup) --- | |
# With the official image, these are less critical as it's pre-configured, | |
# but keeping them for verification during the build. | |
RUN echo "--- Checking Playwright Version (from base image) ---" | |
RUN python -m playwright --version | |
RUN echo "--- Listing Playwright Browser Cache (Recursive, from base image) ---" | |
RUN ls -alR /root/.cache/ms-playwright/ | |
RUN echo "-----------------------------------" | |
# --- End Debugging --- | |
# 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. | |
CMD exec gunicorn --bind 0.0.0.0:7860 --workers 2 --worker-class gevent app:app --timeout 300 | |