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 | |
# Install git and xvfb for Playwright environment | |
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 essential files from the repo root to /app in the container | |
COPY requirements.txt . | |
COPY app.py . | |
# Copy the entire 'proxy-lite-demo-v2' directory into /app/proxy-lite-demo-v2 | |
# This ensures src, pyproject.toml, etc., are in their original nested structure within the container. | |
COPY proxy-lite-demo-v2 /app/proxy-lite-demo-v2/ | |
# Copy the 'proxy-lite-work' directory if it's needed by the app | |
# (Based on your tree, this is at the root of your repo) | |
COPY proxy-lite-work /app/proxy-lite-work/ | |
# --- IMPORTANT: Add proxy-lite-demo-v2/src to PYTHONPATH --- | |
# This is crucial so that 'app.py' (now at /app) can find 'from proxy_lite import ...' | |
ENV PYTHONPATH=/app/proxy-lite-demo-v2/src:$PYTHONPATH | |
# --- START: Directory permission workaround --- | |
# Create the directory proxy-lite's recorder insists on writing to | |
# and grant full permissions. This addresses the PermissionError. | |
# This line creates the directory *directly* under /app, which is now the correct path | |
RUN mkdir -p /app/proxy-lite-demo-v2/local_trajectories \ | |
&& chmod -R 777 /app/proxy-lite-demo-v2/local_trajectories | |
# --- END: Directory permission workaround --- | |
# Upgrade pip, setuptools, and wheel for a robust Python build environment. | |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel | |
# Install all Python dependencies from requirements.txt, which now includes the editable install | |
# of proxy-lite from its correct nested path. | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Set environment variables required for Playwright at runtime | |
ENV DISPLAY=:99 | |
ENV XDG_RUNTIME_DIR=/tmp | |
# --- Debugging: Check Playwright version and browser installation --- | |
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 /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. | |
# This assumes app.py is at the root of /app, which is true because we copied it there. | |
CMD exec gunicorn --bind 0.0.0.0:7860 --workers 2 --worker-class gevent app:app --timeout 300 |