Trisha Tomy
Restructured for Docker Space deployment and updated Dockerfile
c894916
raw
history blame
3.74 kB
# 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 \
&& rm -rf /var/lib/apt/lists/*
# Copy common Python dependencies first
# These are now at the root of your local Git repo
COPY requirements.txt .
# Copy your Flask app.py to the root of /app
# This is also now at the root of your local Git repo
COPY app.py .
# Copy the entire 'src' directory from proxy-lite-demo-v2
# This ensures 'proxy_lite' module is available for imports
COPY proxy-lite-demo-v2/src/ /app/src/
# Copy other relevant sub-directories if your app needs them
# For example, if you access 'gifs' or 'screenshots' from your app.py
COPY proxy-lite-demo-v2/gifs/ /app/proxy-lite-demo-v2/gifs/
COPY proxy-lite-demo-v2/screenshots/ /app/proxy-lite-demo-v2/screenshots/
# Add other top-level files from proxy-lite-demo-v2 if your app references them directly
COPY proxy-lite-demo-v2/README.md .
# And other directories like proxy-lite-work if your app uses them
COPY proxy-lite-work /app/proxy-lite-work
# Ensure the 'src' directory is on the Python path for imports like 'from proxy_lite import ...'
ENV PYTHONPATH=/app/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/local_trajectories \
&& chmod -R 777 /app/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 your local proxy-lite package in editable mode.
# Assuming your setup.py/pyproject.toml for proxy-lite is within src/proxy_lite
# If it's at proxy-lite-demo-v2/ (which is now copied to /app/proxy-lite-demo-v2),
# you might need to adjust this, but for now, this assumes it's within /app/src/
# If 'pip install -e .' expects it at the root of the original project,
# we need to be careful here. Let's make it explicit if it's a sub-package.
# From your original commit log: create mode 100644 proxy-lite-demo-v2/pyproject.toml
# This means proxy-lite itself might be defined by pyproject.toml at the *sub-root*.
# So, for 'pip install -e .', the '.' would need to point to /app/proxy-lite-demo-v2.
# Let's adjust this.
# Install the proxy_lite package from its expected location inside the container
RUN pip install --no-cache-dir --no-input -e /app/proxy-lite-demo-v2
# Install the rest of the Python dependencies from requirements.txt
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 runs the 'app' instance from the 'app.py' file located at the root of /app
CMD exec gunicorn --bind 0.0.0.0:7860 --workers 2 --worker-class gevent app:app --timeout 300