cloudflare-bypass-api / Dockerfile
WaspCode Bot
Deploy Cloudflare Bypass API to HF Spaces
f262da8
Raw History Blame Contribute Delete
3.86 kB
FROM python:3.12-slim
# Prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1
# ── SeleniumBase UC Mode ──────────────────────────────────────────────────────
# UC Mode REQUIRES official Google Chrome, NOT apt's "chromium".
# Chromium lacks the patching hooks that make undetected-chromedriver work.
# SB_SKIP_BROWSER_DOWNLOAD=1 tells SeleniumBase to NOT auto-fetch Chrome on startup
# (we install it manually below via the official Google repo).
ENV SB_SKIP_BROWSER_DOWNLOAD=1
# ── Scrapling StealthyFetcher (Playwright) ────────────────────────────────────
# PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD only suppresses the pip-install hook.
# We still need 'playwright install' to run AFTER pip installs, pointing at a
# writable path for the non-root user. Set here so the install step picks it up.
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
PLAYWRIGHT_BROWSERS_PATH=/home/user/.cache/ms-playwright
# ── Install system deps ───────────────────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
# Network / utils
wget gnupg curl ca-certificates unzip tzdata \
# Virtual display (required for Chrome UC Mode on headless servers)
xvfb xauth x11-utils \
# Chrome shared library dependencies
libnss3 libfontconfig1 libxrender1 libxext6 libx11-6 \
libatk-bridge2.0-0 libgtk-3-0 libgbm1 libdbus-glib-1-2 \
libxrandr2 libxss1 libxi6 libxtst6 libxfixes3 libxdamage1 \
libxcomposite1 libxcursor1 fonts-liberation \
# libasound2t64 is the correct name in Debian Bookworm (python:3.12-slim)
libasound2t64 \
# Python build tools (for curl_cffi compilation if no wheel available)
build-essential gcc libffi-dev \
&& rm -rf /var/lib/apt/lists/*
# ── Install official Google Chrome Stable ────────────────────────────────────
# This is what SeleniumBase UC Mode actually patches and needs.
RUN wget -q -O /tmp/google-chrome.deb \
"https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" \
&& apt-get update \
&& apt-get install -y /tmp/google-chrome.deb \
&& rm /tmp/google-chrome.deb \
&& rm -rf /var/lib/apt/lists/*
# ── Non-root user (required by Hugging Face) ─────────────────────────────────
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
# ── Python dependencies ───────────────────────────────────────────────────────
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt
# ── Install Playwright browser for Scrapling StealthyFetcher ─────────────────
# This runs AFTER pip install so the playwright CLI is available.
# It downloads only Chromium (smallest) with all its needed system libs.
RUN python -m playwright install chromium
# ── Application source ────────────────────────────────────────────────────────
COPY --chown=user . .
# Hugging Face requires port 7860
EXPOSE 7860
# Start the API server on port 7860
# Stage 4 (browser) is disabled by default on HF to avoid memory issues
# Enable with: ENABLE_STAGE4=true
CMD ["python", "main.py"]