File size: 2,312 Bytes
30f6f10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3893b0
30f6f10
00dca45
 
 
e34e4d2
00dca45
30f6f10
 
 
00dca45
 
 
30f6f10
 
 
 
 
 
 
00dca45
e34e4d2
30f6f10
 
 
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
FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    libcurl4-openssl-dev \
    libssl-dev \
    # Chrome dependencies
    wget \
    gnupg \
    fonts-liberation \
    libasound2 \
    libatk-bridge2.0-0 \
    libatk1.0-0 \
    libatspi2.0-0 \
    libcups2 \
    libdbus-1-3 \
    libdrm2 \
    libgbm1 \
    libgtk-3-0 \
    libnspr4 \
    libnss3 \
    libxcomposite1 \
    libxdamage1 \
    libxfixes3 \
    libxkbcommon0 \
    libxrandr2 \
    xdg-utils \
    # Install Chrome
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
    && apt-get update \
    && apt-get install -y google-chrome-stable \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first to leverage Docker cache
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 配置 DrissionPage
RUN cd /usr/local/lib/python3.11/site-packages/DrissionPage/_configs/ && \
    sed -i "/browser_path/s/$(grep 'browser_path' 'configs.ini' | awk -F '=' '{print $2}')/\/usr\/bin\/google-chrome-stable/" configs.ini && \
    sed -i "/arguments/s/\[/\[\'--no-sandbox\', \'--headless=new\', \'--disable-dev-shm-usage\', \'--disable-gpu\', \'--disable-software-rasterizer\', \'--disable-extensions\', \'--disable-setuid-sandbox\', \'--no-first-run\', \'--no-zygote\', \'--single-process\', \'--remote-debugging-port=9222\', \'--window-size=1920,1080\', \'--user-agent=Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/120.0.0.0 Safari\/537.36\', \'--enable-logging\', \'--v=1\', \'--remote-debugging-address=127.0.0.1\', /" configs.ini

# Copy the rest of the application
COPY . .

# 创建并设置 Chrome 数据目录
RUN mkdir -p /tmp/chrome-data && chmod 777 /tmp/chrome-data

# Expose the port the app runs on
EXPOSE 7860

# Environment variables with defaults
ENV OPENAI_API_KEY=None
ENV ENVIRONMENT="production"
ENV PORT=7860
ENV CHROME_PATH=/usr/bin/google-chrome-stable
ENV CHROME_USER_DATA_DIR=/tmp/chrome-data

# Command to run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]