| # Use a more recent Debian version officially supported by Playwright | |
| FROM python:3.11-slim-bookworm | |
| # Set the working directory inside the container | |
| WORKDIR /app | |
| # Install system dependencies required by Playwright, Git, and other libs | |
| # This list is more aligned with Debian Bookworm's requirements for Playwright Chromium | |
| RUN apt-get update && apt-get install -y \ | |
| 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 \ | |
| libgbm1 \ | |
| libasound2-dev \ | |
| xvfb \ | |
| git \ | |
| libxkbcommon0 \ | |
| libfontconfig1 \ | |
| libstdc++6 \ | |
| libx11-6 \ | |
| libxcb1 \ | |
| libnss3-dev \ | |
| # 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. | |
| 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 for Playwright BEFORE installing browsers, | |
| # and use xvfb-run to ensure a display environment for installation verification. | |
| ENV DISPLAY=:99 | |
| ENV XDG_RUNTIME_DIR=/tmp | |
| # Install Playwright browser binaries within the container | |
| # Wrapping with xvfb-run helps ensure the environment is ready for browser checks during install | |
| RUN xvfb-run python -m playwright install chromium | |
| # Set environment variables for Playwright (can be redundant but good to ensure persistence) | |
| ENV PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright/ | |
| # --- Debugging: Check Playwright version and browser installation (moved AFTER install) --- | |
| RUN echo "--- Checking Playwright Version ---" | |
| RUN python -m playwright --version | |
| RUN echo "--- Listing Playwright Browser Cache (Recursive) ---" | |
| # This will list contents of subdirectories as well | |
| 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 | |