1oscon commited on
Commit
1f15691
·
verified ·
1 Parent(s): 0ad7433

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -19
Dockerfile CHANGED
@@ -2,7 +2,7 @@ FROM python:3.10-slim
2
 
3
  WORKDIR /app
4
 
5
- # 1. 安装系统依赖 (保持原样并优化)
6
  RUN apt-get update && apt-get install -y \
7
  git wget curl unzip \
8
  libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
@@ -13,32 +13,42 @@ RUN apt-get update && apt-get install -y \
13
  # 2. 克隆项目
14
  RUN git clone https://github.com/CloudWaddie/LMArenaBridge.git .
15
 
16
- # 3. 【核心修复补丁】一键解决 JS 报错、超时和端口问题
17
- RUN echo "正在应用自动化修复补丁..." && \
18
- # 修复 JS 报错:在调用 recaptcha 前强制等待库加载完成
19
- sed -i 's/window.grecaptcha.enterprise.execute/await new Promise(r => { let i = setInterval(() => { if(window.grecaptcha?.enterprise?.execute) { clearInterval(i); r(); } }, 500); }); window.grecaptcha.enterprise.execute/g' src/main.py && \
20
- # 修复超时:将 45秒超时延长至 120秒,给 Cloudflare 足够时间
21
- sed -i 's/timeout=45000/timeout=120000/g' src/main.py && \
22
- # 修正端口
23
- sed -i 's/8000/7860/g' src/main.py && \
24
- # 修正 Uvicorn 运行参数以适配 HF
25
- sed -i 's/host="0.0.0.0", port=8000/host="0.0.0.0", port=7860/g' src/main.py
26
-
27
- # 4. 强制创建配置文件,密码定死为 123456
 
 
 
 
 
 
 
28
  RUN echo '{"admin_password": "123456", "password": "123456"}' > config.json
29
 
30
- # 5. 安装依赖 (增加 playwright 核心)
31
  RUN pip install --no-cache-dir --upgrade pip
32
  RUN pip install --no-cache-dir -r requirements.txt
33
  RUN pip install --no-cache-dir camoufox[geoip] playwright python-multipart
34
- RUN playwright install chromium && playwright install-deps
35
 
36
- # 6. 下载内核并启动
 
 
 
 
37
  RUN python -m camoufox fetch
38
  RUN chmod +x src/main.py
39
 
40
- # 设置环境变量,强制不使用代理(防止 HF 内网冲突)
41
- ENV HTTP_PROXY=""
42
- ENV HTTPS_PROXY=""
43
 
44
  CMD ["python", "src/main.py"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # 1. 安装系统核心依赖
6
  RUN apt-get update && apt-get install -y \
7
  git wget curl unzip \
8
  libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
 
13
  # 2. 克隆项目
14
  RUN git clone https://github.com/CloudWaddie/LMArenaBridge.git .
15
 
16
+ # 3. 【精准自动化修复补丁】使用 Python 脚本安全替换,解决所有报错
17
+ RUN python3 -c ' \
18
+ import os; \
19
+ path = "src/main.py"; \
20
+ content = open(path).read(); \
21
+ # 修复端口 \
22
+ content = content.replace("8000", "7860"); \
23
+ # 修复超时:从 45秒 延长到 120秒 \
24
+ content = content.replace("timeout=45000", "timeout=120000"); \
25
+ # 修复 JS 报错:注入一段不带大括号的 JS 等待逻辑,防止破坏 Python f-string 语法 \
26
+ js_wait = "await new Promise(r => setInterval(() => window.grecaptcha?.enterprise?.execute ? r() : null, 500)); await window.grecaptcha.enterprise.execute"; \
27
+ content = content.replace("window.grecaptcha.enterprise.execute", js_wait); \
28
+ # 确保启动参数正确 \
29
+ content = content.replace("host=\"0.0.0.0\", port=8000", "host=\"0.0.0.0\", port=7860"); \
30
+ with open(path, "w") as f: f.write(content); \
31
+ print("✅ 补丁应用成功"); \
32
+ '
33
+
34
+ # 4. 强制创建配置文件,密码 123456
35
  RUN echo '{"admin_password": "123456", "password": "123456"}' > config.json
36
 
37
+ # 5. 安装 Python 依赖
38
  RUN pip install --no-cache-dir --upgrade pip
39
  RUN pip install --no-cache-dir -r requirements.txt
40
  RUN pip install --no-cache-dir camoufox[geoip] playwright python-multipart
 
41
 
42
+ # 6. 安装 Playwright 浏览器内核及依赖(Hugging Face 运行必备)
43
+ RUN playwright install chromium
44
+ RUN playwright install-deps chromium
45
+
46
+ # 7. 下载 Camoufox 内核并配置
47
  RUN python -m camoufox fetch
48
  RUN chmod +x src/main.py
49
 
50
+ # 环境适配
51
+ ENV PYTHONUNBUFFERED=1
52
+ ENV PORT=7860
53
 
54
  CMD ["python", "src/main.py"]