11# Dockerfile
22
3+ ARG PROXY_ADDR="http://host.docker.internal:7890"
34FROM python:3.10-slim-bookworm AS builder
45
56ARG DEBIAN_FRONTEND=noninteractive
6- RUN apt-get update && \
7- apt-get install -y --no-install-recommends \
8- libatk1.0-0 libatk-bridge2.0-0 libcups2 libdbus-1-3 libdrm2 libgbm1 libgtk-3-0 libnspr4 libnss3 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxrandr2 libxrender1 libxtst6 ca-certificates fonts-liberation libasound2 libpangocairo-1.0-0 libpango-1.0-0 libu2f-udev \
9- supervisor curl \
10- && apt-get clean && rm -rf /var/lib/apt/lists/*
7+ ARG PROXY_ADDR
8+
9+ RUN if [ -n "$PROXY_ADDR" ]; then \
10+ printf 'Acquire::http::Proxy "%s";\n Acquire::https::Proxy "%s";\n ' "$PROXY_ADDR" "$PROXY_ADDR" > /etc/apt/apt.conf.d/99proxy; \
11+ fi && \
12+ apt-get update && \
13+ apt-get install -y --no-install-recommends curl \
14+ && apt-get clean && rm -rf /var/lib/apt/lists/* && \
15+ if [ -n "$PROXY_ADDR" ]; then rm -f /etc/apt/apt.conf.d/99proxy; fi
16+
17+ ENV HTTP_PROXY=${PROXY_ADDR}
18+ ENV HTTPS_PROXY=${PROXY_ADDR}
1119
12- # Install Poetry
1320ENV POETRY_HOME="/opt/poetry"
1421ENV POETRY_VERSION=1.8.3
15- RUN curl -sSL https://install.python-poetry.org | python3 - --version ${POETRY_VERSION}
22+ RUN curl -sSL https://install.python-poetry.org | python3 - --version ${POETRY_VERSION}
1623ENV PATH="${POETRY_HOME}/bin:${PATH}"
1724
1825WORKDIR /app_builder
19-
20- # Copy Poetry project files
2126COPY pyproject.toml poetry.lock ./
22-
23- # Configure Poetry to not create virtualenvs and install dependencies
2427RUN poetry config virtualenvs.create false --local && \
2528 poetry install --no-root --no-dev --no-interaction --no-ansi
2629
2730FROM python:3.10-slim-bookworm
2831
2932ARG DEBIAN_FRONTEND=noninteractive
30- RUN apt-get update && \
33+ ARG PROXY_ADDR
34+
35+ ENV HTTP_PROXY=${PROXY_ADDR}
36+ ENV HTTPS_PROXY=${PROXY_ADDR}
37+
38+ # 步骤 1: 安装所有系统依赖。
39+ # Playwright 的依赖也在这里一并安装。
40+ RUN \
41+ if [ -n "$PROXY_ADDR" ]; then \
42+ printf 'Acquire::http::Proxy "%s";\n Acquire::https::Proxy "%s";\n ' "$PROXY_ADDR" "$PROXY_ADDR" > /etc/apt/apt.conf.d/99proxy; \
43+ fi && \
44+ apt-get update && \
3145 apt-get install -y --no-install-recommends \
3246 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdbus-1-3 libdrm2 libgbm1 libgtk-3-0 libnspr4 libnss3 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxrandr2 libxrender1 libxtst6 ca-certificates fonts-liberation libasound2 libpangocairo-1.0-0 libpango-1.0-0 libu2f-udev \
3347 supervisor curl \
34- && apt-get clean && rm -rf /var/lib/apt/lists/*
48+ && \
49+ # 清理工作
50+ apt-get clean && \
51+ rm -rf /var/lib/apt/lists/* && \
52+ if [ -n "$PROXY_ADDR" ]; then rm -f /etc/apt/apt.conf.d/99proxy; fi
3553
3654RUN groupadd -r appgroup && useradd -r -g appgroup -s /bin/bash -d /app appuser
3755
3856WORKDIR /app
3957
40- # Copy installed packages and executables from builder stage
58+ # 步骤 2: 复制 Python 包和可执行文件。
59+ # 这是关键的顺序调整:在使用 playwright 之前先把它复制进来。
4160COPY --from=builder /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/
4261COPY --from=builder /usr/local/bin/ /usr/local/bin/
4362COPY --from=builder /opt/poetry/bin/poetry /usr/local/bin/poetry
4463
45- # Copy application code
64+ # 复制应用代码
4665COPY . .
4766
48- # Install Playwright browsers and dependencies, and fetch camoufox
49- # Note: poetry is now available in the final image if needed for any build scripts,
50- # but dependencies should already be installed.
67+ # 步骤 3: 现在 Python 模块已存在,可以安全地运行这些命令。
68+ # 注意:我们不再需要 `playwright install-deps`,因为依赖已在上面的 apt-get 中安装。
5169RUN camoufox fetch && \
52- python -m playwright install firefox && \
53- python -m playwright install-deps firefox
70+ python -m playwright install firefox
5471
72+ # 创建目录和设置权限
5573RUN mkdir -p /app/logs && \
5674 mkdir -p /app/auth_profiles/active && \
5775 mkdir -p /app/auth_profiles/saved && \
@@ -64,19 +82,18 @@ RUN mkdir -p /app/logs && \
6482
6583COPY supervisord.conf /etc/supervisor/conf.d/app.conf
6684
67- # 新增解决 ❌ 错误 (--internal-launch-mode): 执行 camoufox.server.launch_server 时发生异常: Version information not found at /app/.cache/camoufox/version.json. Please run `camoufox fetch` to install.
85+ # 修复 camoufox 缓存逻辑
6886RUN mkdir -p /var/cache/camoufox && \
69- # 2. 从 builder 阶段复制 camoufox 的缓存文件到最终镜像的 /var/cache/camoufox
70- # 这是最关键的一步,确保文件内容存在
71- cp -a /root/.cache/camoufox/* /var/cache/camoufox/ && \
72- # 3. 创建 appuser 期望的缓存路径
87+ if [ -d /root/.cache/camoufox ]; then cp -a /root/.cache/camoufox/* /var/cache/camoufox/; fi && \
7388 mkdir -p /app/.cache && \
74- # 4. 创建软链接,将 /app/.cache/camoufox 指向实际文件所在位置
75- ln -s /var/cache/camoufox /app/.cache/camoufox
76- # 新增结束
89+ ln -s /var/cache/camoufox /app/.cache/camoufox
7790
7891RUN python update_browserforge_data.py
7992
93+ # 清理代理环境变量
94+ ENV HTTP_PROXY=""
95+ ENV HTTPS_PROXY=""
96+
8097EXPOSE 2048
8198EXPOSE 3120
8299
@@ -86,16 +103,13 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright
86103
87104ENV PYTHONUNBUFFERED=1
88105
89- # Default environment variables (can be overridden by .env or runtime)
90106ENV PORT=8000
91107ENV DEFAULT_FASTAPI_PORT=2048
92108ENV DEFAULT_CAMOUFOX_PORT=9222
93109ENV STREAM_PORT=3120
94110ENV SERVER_LOG_LEVEL=INFO
95111ENV DEBUG_LOGS_ENABLED=false
96112ENV AUTO_CONFIRM_LOGIN=true
97-
98- # Backward compatibility
99113ENV SERVER_PORT=2048
100114ENV INTERNAL_CAMOUFOX_PROXY=""
101115
0 commit comments