BOM发料对比

This commit is contained in:
hjq
2026-06-23 11:02:37 +08:00
parent a8a6388d85
commit 9be2b1373f
5 changed files with 111 additions and 35 deletions

View File

@@ -9,22 +9,28 @@ ENV DEBIAN_FRONTEND=noninteractive
# Debian 12 (Bookworm) 的 apt 源文件变成了 /etc/apt/sources.list.d/debian.sources
# 这里替换源以加速下载,并安装必要的系统依赖
# 必须安装Xvfb(虚拟屏幕), Chromium(浏览器核心), 中文字体(防乱码)
# Linux 生产环境优先使用 Google Chrome Stable避免 Chromium 在
# DevTools WebSocket 握手阶段与 DrissionPage 出现兼容性问题。
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || \
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list 2>/dev/null || true && \
apt-get update && \
apt-get install -y --no-install-recommends \
xvfb \
xauth \
chromium \
chromium-driver \
ca-certificates \
curl \
gnupg \
fonts-wqy-zenhei \
tzdata \
&& rm -rf /var/lib/apt/lists/*
&& install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /etc/apt/keyrings/google-chrome.gpg && \
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/google-chrome.gpg] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
apt-get update && \
apt-get install -y --no-install-recommends google-chrome-stable && \
rm -rf /var/lib/apt/lists/*
# 设置时区为中国上海
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV CHROME_BIN=/usr/bin/google-chrome
# 复制依赖清单并安装 Python 库
COPY requirements.txt .
@@ -38,9 +44,8 @@ COPY . .
EXPOSE 5050
# 启动脚本:
# 1. 清理可能因异常重启遗留的虚拟屏幕锁文件(防止 xvfb 报错退出)
# 2. 切换到 web_ui 目录执行 gunicorn
# 3. 使用 xvfb-run -a 自动分配空闲的虚拟屏幕
# 4. 浏览器自动化服务必须单 worker 运行,避免多个 Gunicorn 进程同时抢占 Chromium DevTools 端口
# 5. 使用 gthread 提升单进程下的并发响应能力
CMD sh -c "rm -f /tmp/.X*-lock && cd web_ui && xvfb-run -a --server-args='-screen 0 1920x1080x24' gunicorn -w 1 --threads 8 --worker-class gthread -b 0.0.0.0:5050 --access-logfile - --timeout 120 app:app"
# 1. 切换到 web_ui 目录执行 gunicorn
# 2. 浏览器自动化服务必须单 worker 运行,避免多个 Gunicorn 进程同时抢占 DevTools 会话
# 3. Headless Chrome 已足够,无需再叠加 Xvfb减少 Linux 初始化链路的不确定性
# 4. 使用 gthread 提升单进程下的并发响应能力
CMD sh -c "cd web_ui && gunicorn -w 1 --threads 8 --worker-class gthread -b 0.0.0.0:5050 --access-logfile - --timeout 120 app:app"