hzruo commited on
Commit
1809a06
·
verified ·
1 Parent(s): 461b6d3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +49 -46
Dockerfile CHANGED
@@ -1,66 +1,69 @@
1
  FROM python:3.11-slim
2
 
3
- WORKDIR /app
4
-
5
-
6
- # Install system dependencies
7
  RUN apt-get update && apt-get install -y \
8
- build-essential \
9
- curl \
10
- libcurl4-openssl-dev \
11
- libssl-dev \
12
- # Chrome dependencies
13
  wget \
14
  gnupg \
15
- fonts-liberation \
16
- libasound2 \
17
- libatk-bridge2.0-0 \
18
- libatk1.0-0 \
19
- libatspi2.0-0 \
20
- libcups2 \
21
- libdbus-1-3 \
22
- libdrm2 \
23
- libgbm1 \
24
- libgtk-3-0 \
25
- libnspr4 \
26
- libnss3 \
27
- libxcomposite1 \
28
- libxdamage1 \
29
- libxfixes3 \
30
- libxkbcommon0 \
31
- libxrandr2 \
32
- xdg-utils \
33
- # Install Chrome
34
  && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
35
  && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
36
  && apt-get update \
37
- && apt-get install -y google-chrome-stable \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  && rm -rf /var/lib/apt/lists/*
39
 
40
- # Copy requirements first to leverage Docker cache
 
 
 
 
 
 
 
 
 
 
 
 
41
  COPY requirements.txt .
 
 
42
  RUN pip install --no-cache-dir -r requirements.txt
43
 
44
- # 配置 DrissionPage
45
- RUN cd /usr/local/lib/python3.11/site-packages/DrissionPage/_configs/ && \
46
- sed -i "/browser_path/s/$(grep 'browser_path' 'configs.ini' | awk -F '=' '{print $2}')/\/usr\/bin\/google-chrome-stable/" configs.ini && \
47
- 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
48
 
49
- # Copy the rest of the application
50
  COPY . .
51
 
52
- # 创建并设置 Chrome 数据目录
53
- RUN mkdir -p /tmp/chrome-data && chmod 777 /tmp/chrome-data
 
 
54
 
55
- # Expose the port the app runs on
56
  EXPOSE 7860
57
 
58
- # Environment variables with defaults
59
- ENV OPENAI_API_KEY=None
60
- ENV ENVIRONMENT="production"
61
- ENV PORT=7860
62
- ENV CHROME_PATH=/usr/bin/google-chrome-stable
63
- ENV CHROME_USER_DATA_DIR=/tmp/chrome-data
64
-
65
- # Command to run the application
66
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.11-slim
2
 
3
+ # 安装 Chrome 和必要的依赖
 
 
 
4
  RUN apt-get update && apt-get install -y \
 
 
 
 
 
5
  wget \
6
  gnupg \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
8
  && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
9
  && apt-get update \
10
+ && apt-get install -y \
11
+ google-chrome-stable \
12
+ fonts-ipafont-gothic \
13
+ fonts-wqy-zenhei \
14
+ fonts-thai-tlwg \
15
+ fonts-kacst \
16
+ fonts-freefont-ttf \
17
+ libxss1 \
18
+ libx11-xcb1 \
19
+ libxcomposite1 \
20
+ libxcursor1 \
21
+ libxdamage1 \
22
+ libxi6 \
23
+ libxtst6 \
24
+ libglib2.0-0 \
25
+ libnss3 \
26
+ libcups2 \
27
+ libxss1 \
28
+ libxrandr2 \
29
+ libasound2 \
30
+ libpangocairo-1.0-0 \
31
+ libatk1.0-0 \
32
+ libatk-bridge2.0-0 \
33
+ libgtk-3-0 \
34
  && rm -rf /var/lib/apt/lists/*
35
 
36
+ # 设置工作目录
37
+ WORKDIR /app
38
+
39
+ # 设置环境变量
40
+ ENV PYTHONUNBUFFERED=1 \
41
+ PYTHONDONTWRITEBYTECODE=1 \
42
+ PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
43
+ CHROME_BIN=/usr/bin/google-chrome \
44
+ CHROME_PATH=/usr/lib/google-chrome/ \
45
+ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
46
+ PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome
47
+
48
+ # 复制依赖文件
49
  COPY requirements.txt .
50
+
51
+ # 安装 Python 依赖
52
  RUN pip install --no-cache-dir -r requirements.txt
53
 
54
+ # 安装 Playwright 浏览器
55
+ RUN playwright install chromium
 
 
56
 
57
+ # 复制应用代码
58
  COPY . .
59
 
60
+ # 创建非 root 用户
61
+ RUN useradd -m -u 1000 appuser && \
62
+ chown -R appuser:appuser /app
63
+ USER appuser
64
 
65
+ # 暴露端口
66
  EXPOSE 7860
67
 
68
+ # 启动命令
 
 
 
 
 
 
 
69
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]