Spaces:
Paused
Paused
| 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"] |