File size: 3,839 Bytes
865f055
 
 
 
 
 
 
 
 
 
 
 
 
d9a17cb
 
3dfe443
5843cda
d9a17cb
 
 
 
 
 
 
ad42a8f
 
d9a17cb
865f055
 
 
d9a17cb
 
865f055
 
 
 
d9a17cb
5843cda
ad42a8f
5843cda
 
 
9b34ea9
d9a17cb
ad42a8f
 
865f055
3dfe443
 
 
 
5843cda
 
 
 
d9a17cb
86a6810
 
 
d9a17cb
865f055
86a6810
865f055
 
86a6810
 
 
5843cda
865f055
3dfe443
 
9b34ea9
3dfe443
 
 
 
 
 
 
86a6810
4874383
86a6810
3dfe443
 
d9a17cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
FROM python:3.13-slim-bookworm AS builder

RUN apt-get update \
    && apt-get install -y --no-install-recommends equivs \
    && equivs-control libgl1-mesa-dri \
    && printf 'Section: misc\nPriority: optional\nStandards-Version: 3.9.2\nPackage: libgl1-mesa-dri\nVersion: 99.0.0\nDescription: Dummy package for libgl1-mesa-dri\n' >> libgl1-mesa-dri \
    && equivs-build libgl1-mesa-dri \
    && mv libgl1-mesa-dri_*.deb /libgl1-mesa-dri.deb \
    && equivs-control adwaita-icon-theme \
    && printf 'Section: misc\nPriority: optional\nStandards-Version: 3.9.2\nPackage: adwaita-icon-theme\nVersion: 99.0.0\nDescription: Dummy package for adwaita-icon-theme\n' >> adwaita-icon-theme \
    && equivs-build adwaita-icon-theme \
    && mv adwaita-icon-theme_*.deb /adwaita-icon-theme.deb

FROM python:3.13-slim-bookworm AS chrome-downloader

# Chrome 136 stable(可按需换版本号)
ARG CHROME_VERSION=136.0.7103.113
RUN apt-get update && apt-get install -y --no-install-recommends curl unzip \
    && curl -Lo /tmp/chrome.zip \
       "https://storage.googleapis.com/chrome-for-testing-public/${CHROME_VERSION}/linux64/chrome-linux64.zip" \
    && curl -Lo /tmp/chromedriver.zip \
       "https://storage.googleapis.com/chrome-for-testing-public/${CHROME_VERSION}/linux64/chromedriver-linux64.zip" \
    && unzip /tmp/chrome.zip -d /opt/ \
    && unzip /tmp/chromedriver.zip -d /opt/ \
    && chmod -R a+rx /opt/chrome-linux64 \
    && chmod a+rx /opt/chromedriver-linux64/chromedriver

FROM python:3.13-slim-bookworm

COPY --from=builder /*.deb /
COPY --from=chrome-downloader /opt/chrome-linux64 /opt/chrome
COPY --from=chrome-downloader /opt/chromedriver-linux64/chromedriver /usr/bin/chromedriver

RUN dpkg -i /libgl1-mesa-dri.deb \
    && dpkg -i /adwaita-icon-theme.deb \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
       libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
       libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 \
       libgbm1 libasound2 libpango-1.0-0 libcairo2 libatspi2.0-0 \
       libwayland-client0 libglib2.0-0 libdbus-1-3 \
       libx11-6 libxcb1 libxext6 libfontconfig1 libfreetype6 libexpat1 \
       fonts-liberation fonts-noto-color-emoji \
       xvfb dumb-init git procps curl xauth \
    && rm -rf /var/lib/apt/lists/* \
    && chmod a+rx /opt/chrome/chrome /usr/bin/chromedriver

# ══ wrapper:只注入必须的沙盒参数,不加任何 headless/gpu 标志 ══
# 关键:去掉 --disable-gpu,让 xvfb 提供完整的 GPU 环境
# 去掉 --headless,改由 HEADLESS=false + xvfb 实现无屏幕运行
RUN printf '#!/bin/bash\nexec /opt/chrome/chrome --no-sandbox --disable-dev-shm-usage "$@"\n' \
      > /usr/local/bin/google-chrome \
    && chmod a+rx /usr/local/bin/google-chrome \
    && google-chrome --version

RUN useradd -m -u 1000 user

WORKDIR /app

RUN git clone https://github.com/FlareSolverr/FlareSolverr.git . \
    && chown -R user:user /app

RUN pip install -r requirements.txt --no-cache-dir \
    && rm -rf /root/.cache

USER user

RUN mkdir -p "/home/user/.config/chromium/Crash Reports/pending"

ENV LOG_LEVEL=info \
    PORT=7860 \
    BROWSER_EXECUTABLE_PATH=/usr/local/bin/google-chrome \
    # ★ 关键优化1:关闭 headless 模式,使用 xvfb 虚拟显示器
    # headless Chrome 有大量可被 Cloudflare 检测的 fingerprint
    HEADLESS=false \
    # ★ 关键优化2:指定 xvfb 虚拟屏幕编号,确保 Chrome 使用虚拟显示
    DISPLAY=:99 \
    # ★ 优化3:延长超时,给 Cloudflare 挑战更多求解时间
    BROWSER_TIMEOUT=60000

EXPOSE 7860

# xvfb-run 参数:-s 指定屏幕分辨率为 1920x1080,模拟真实显示器
ENTRYPOINT ["dumb-init", "xvfb-run", "-a", "-s", "-screen 0 1920x1080x24 -ac"]
CMD ["python", "-u", "src/flaresolverr.py"]