File size: 2,866 Bytes
6170d37
f19a4ca
689e710
 
 
 
6170d37
689e710
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5ca79c
6170d37
689e710
 
e36d4b5
689e710
cacfd35
e36d4b5
6170d37
 
cacfd35
 
6170d37
e36d4b5
 
 
 
cc42de8
cacfd35
6170d37
689e710
 
e36d4b5
 
 
 
689e710
 
e36d4b5
 
 
 
 
 
 
 
 
689e710
 
 
 
6170d37
689e710
 
 
6170d37
689e710
 
6170d37
689e710
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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
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 \
    libgbm-dev \
    libasound2-dev \
    xvfb \
    git \
    chromium \
    && 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 'rm -rf /app/src/proxy-lite' is NOT needed here.
# pip -e will clone into /app/src/proxy-lite by itself.
# If it complains about it already existing from a *previous* build,
# --force-reinstall will handle it by recreating/overwriting.
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 common Python dependencies from requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# --- END: Core Python and proxy-lite setup ---

# Copy your Flask application code (app.py) and other project files.
# This should happen AFTER all dependencies are installed.
COPY . .

# --- START: Directory permission workaround ---
# Create the directory proxy-lite's recorder insists on writing to
# and grant full permissions. This addresses the PermissionError.
# This directory is relative to where proxy-lite is installed inside the container.
# It should be safe to create it here as proxy-lite is already installed.
RUN mkdir -p /app/src/proxy-lite/local_trajectories \
    && chmod -R 777 /app/src/proxy-lite/local_trajectories
# --- END: Directory permission workaround ---

# Install Playwright browser binaries within the container
RUN playwright install chromium

# Set environment variables for Playwright
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.
CMD exec gunicorn --bind 0.0.0.0:7860 --workers 2 --worker-class gevent app:app --timeout 300