Skip to content

Commit 8256d7e

Browse files
committed
fix(docker): 预装 playwright chromium 并导出浏览器路径
1 parent 2ed365e commit 8256d7e

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

Dockerfile.headed

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,14 @@ WORKDIR /app
44

55
ENV PYTHONDONTWRITEBYTECODE=1 \
66
PYTHONUNBUFFERED=1 \
7-
ALLOW_DOCKER_HEADED_CAPTCHA=true
7+
ALLOW_DOCKER_HEADED_CAPTCHA=true \
8+
PLAYWRIGHT_BROWSERS_PATH=0
89

9-
# 安装 Chrome 运行依赖(无头模式仍需要这些系统库)
10+
# 在镜像构建阶段预装 Playwright Chromium,供 personal/browser 模式复用
1011
COPY requirements.txt ./
1112

12-
RUN apt-get update \
13-
&& apt-get install -y --no-install-recommends \
14-
ca-certificates \
15-
curl \
16-
libnss3 \
17-
libnspr4 \
18-
libatk1.0-0 \
19-
libatk-bridge2.0-0 \
20-
libcups2 \
21-
libdrm2 \
22-
libxkbcommon0 \
23-
libxcomposite1 \
24-
libxdamage1 \
25-
libxfixes3 \
26-
libxrandr2 \
27-
libgbm1 \
28-
libpango-1.0-0 \
29-
libcairo2 \
30-
libasound2 \
31-
&& rm -rf /var/lib/apt/lists/*
32-
33-
RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt
13+
RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt \
14+
&& python -m playwright install --with-deps chromium
3415

3516
COPY . .
3617
COPY docker/entrypoint.headed.sh /usr/local/bin/entrypoint.headed.sh

docker/entrypoint.headed.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
#!/bin/sh
22
set -eu
33

4+
resolve_browser_path() {
5+
python - <<'PY'
6+
from playwright.sync_api import sync_playwright
7+
8+
with sync_playwright() as p:
9+
print(p.chromium.executable_path or "")
10+
PY
11+
}
12+
13+
if [ -z "${BROWSER_EXECUTABLE_PATH:-}" ] || [ ! -x "${BROWSER_EXECUTABLE_PATH:-}" ]; then
14+
detected_browser_path="$(resolve_browser_path 2>/dev/null | tr -d '\r' | tail -n 1)"
15+
if [ -n "${detected_browser_path}" ] && [ -x "${detected_browser_path}" ]; then
16+
export BROWSER_EXECUTABLE_PATH="${detected_browser_path}"
17+
fi
18+
fi
19+
420
echo "[entrypoint] starting flow2api (headless browser mode)"
21+
if [ -n "${BROWSER_EXECUTABLE_PATH:-}" ] && [ -x "${BROWSER_EXECUTABLE_PATH}" ]; then
22+
echo "[entrypoint] browser executable: ${BROWSER_EXECUTABLE_PATH}"
23+
"${BROWSER_EXECUTABLE_PATH}" --version || true
24+
else
25+
echo "[entrypoint] warning: no valid browser executable found for personal/browser captcha" >&2
26+
fi
27+
528
exec python main.py

0 commit comments

Comments
 (0)