Update Dockerfile
Browse files- 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. 【
|
| 17 |
-
RUN
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
RUN echo '{"admin_password": "123456", "password": "123456"}' > config.json
|
| 29 |
|
| 30 |
-
# 5. 安装
|
| 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 |
-
#
|
| 41 |
-
ENV
|
| 42 |
-
ENV
|
| 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"]
|