File size: 3,859 Bytes
f262da8 | 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 | 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"]
|