Spaces:
Sleeping
Sleeping
Adarsh Kumar commited on
Update Dockerfile
Browse files12345678910111213141516171819202122232425 unmodified lines505152535455562 unmodified lines59606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031042 unmodified lines107108109110# ╔══════════════════════════════════════════════════════════════╗# ║ Dockerfile — Cloudflare AI API ║# ║ ║# ║ Stack: Python 3.11 · FastAPI · Chrome · Xvfb ║# ║ Port: 7860 (HuggingFace Spaces default) ║# ║ ║# ║ KEY FIX: /tmp/.X11-unix is pre-created as root with ║# ║ sticky-bit 1777 so non-root Xvfb can use it. ║# ║ Xvfb is started by entrypoint.sh (not pyvirtualdisplay) ║# ║ so we have full control over display :99. ║# ╚══════════════════════════════════════════════════════════════╝FROM python:3.11-slim# ── System deps ───────────────────────────────────────────────RUN apt-get update && apt-get install -y --no-install-recommends \xvfb \x11-utils \wget \gnupg \ca-certificates \libx11-6 \libx11-xcb1 \libxcb1 \25 unmodified linesprocps \&& rm -rf /var/lib/apt/lists/*# ── Google Chrome stable ───────────────────────────────────────RUN wget -q -O /tmp/chrome.deb \https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \&& apt-get update \2 unmodified lines&& rm -rf /var/lib/apt/lists/* \&& google-chrome --version# ── Pre-create X11 socket directory AS ROOT ───────────────────# CRITICAL FIX: Xvfb needs /tmp/.X11-unix to exist with sticky-bit.# When running as non-root, Xvfb cannot create it → "euid != 0" error.# Creating it here (as root at build time) permanently fixes this.RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix# ── Working directory ──────────────────────────────────────────WORKDIR /app# ── Python deps ────────────────────────────────────────────────COPY requirements.txt .RUN pip install --no-cache-dir --upgrade pip \&& pip install --no-cache-dir -r requirements.txt# ── App source ─────────────────────────────────────────────────COPY cloudflare_provider.py .COPY server.py .COPY entrypoint.sh .# ── Directories + permissions ──────────────────────────────────RUN mkdir -p /app/cache \&& useradd -m -u 1000 appuser \&& chown -R appuser:appuser /app \&& chmod +x /app/entrypoint.sh \# Keep X11 socket dir world-writable after user creation&& chmod 1777 /tmp/.X11-unixUSER appuser# ── Environment ────────────────────────────────────────────────ENV PYTHONUNBUFFERED=1 \PYTHONDONTWRITEBYTECODE=1 \# Display set by entrypoint.sh (Xvfb :99)DISPLAY=:99 \# VR_DISPLAY=0: we manage Xvfb ourselves in entrypoint.sh# so pyvirtualdisplay does NOT try to start a second XvfbVR_DISPLAY=0 \# Signals the provider that a real display exists via DISPLAY envXVFB_EXTERNAL=1 \# Pool configPOOL_SIZE=2 \PORT=7860 \HOST=0.0.0.0 \2 unmodified linesEXPOSE 7860CMD ["/app/start.sh"]1234567891011121314151617181920212223242525 unmodified lines515253545556572 unmodified lines6061626364656667686970717273747576777879808182838485868788892 unmodified lines92939495# ╔══════════════════════════════════════════════════════════════╗# ║ Dockerfile — Cloudflare AI API ║# ║ Stack: Python 3.11 · FastAPI · Chrome · Xvfb ║# ║ Port: 7860 ║# ╚══════════════════════════════════════════════════════════════╝FROM python:3.11-slimENV DEBIAN_FRONTEND=noninteractive \PYTHONUNBUFFERED=1 \PYTHONDONTWRITEBYTECODE=1SHELL ["/bin/bash", "-o", "pipefail", "-c"]# System depsRUN apt-get update && apt-get install -y --no-install-recommends \xvfb \x11-utils \wget \ca-certificates \gnupg \curl \libx11-6 \libx11-xcb1 \libxcb1 \25 unmodified linesprocps \&& rm -rf /var/lib/apt/lists/*# Google Chrome stableRUN wget -q -O /tmp/chrome.deb \https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \&& apt-get update \2 unmodified lines&& rm -rf /var/lib/apt/lists/* \&& google-chrome --version# Pre-create X11 socket directoryRUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unixWORKDIR /app# Python depsCOPY requirements.txt .RUN pip install --no-cache-dir --upgrade pip \&& pip install --no-cache-dir -r requirements.txt# App sourceCOPY cloudflare_provider.py server.py entrypoint.sh ./# User + permissionsRUN useradd -m -u 1000 appuser \&& mkdir -p /app/cache \&& chown -R appuser:appuser /app \&& chmod +x /app/entrypoint.sh \&& chmod 1777 /tmp/.X11-unixUSER appuserENV DISPLAY=:99 \XVFB_EXTERNAL=1 \POOL_SIZE=2 \PORT=7860 \HOST=0.0.0.0 \2 unmodified linesEXPOSE 7860CMD ["/app/entrypoint.sh"]
Dockerfile+21-36