Spaces:
Sleeping
Sleeping
Adarsh Kumar commited on
Update Dockerfile
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273FROM python:3.11-slimENV DEBIAN_FRONTEND=noninteractive \PYTHONUNBUFFERED=1 \PYTHONDONTWRITEBYTECODE=1 \PORT=7860 \HOST=0.0.0.0 \DISPLAY=:99 \DEFAULT_MODEL=@cf/moonshotai/kimi-k2.5RUN apt-get update && apt-get install -y --no-install-recommends \xvfb \wget \gnupg \ca-certificates \curl \libx11-6 \libx11-xcb1 \libxcb1 \libxcomposite1 \libxcursor1 \libxdamage1 \libxext6 \libxfixes3 \libxi6 \libxrandr2 \libxrender1 \libxss1 \libxtst6 \libglib2.0-0 \libgtk-3-0 \libnspr4 \libnss3 \libatk1.0-0 \libatk-bridge2.0-0 \libdrm2 \libgbm1 \libcups2 \libasound2 \libpango-1.0-0 \libpangocairo-1.0-0 \fonts-liberation \xdg-utils \lsb-release \&& rm -rf /var/lib/apt/lists/*RUN wget -O /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \&& apt-get update \&& apt-get install -y --no-install-recommends /tmp/chrome.deb \&& rm -f /tmp/chrome.deb \&& rm -rf /var/lib/apt/lists/* \&& google-chrome --versionWORKDIR /appCOPY requirements.txt .RUN pip install --no-cache-dir --upgrade pip \&& pip install --no-cache-dir -r requirements.txtCOPY cloudflare_provider.py .COPY server.py .COPY start.sh /app/start.shRUN chmod +x /app/start.shRUN mkdir -p /app/cache \&& useradd -m -u 1000 appuser \&& chown -R appuser:appuser /appUSER appuserEXPOSE 7860CMD ["/app/start.sh"]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110# ╔══════════════════════════════════════════════════════════════╗# ║ 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 \libxcomposite1 \libxcursor1 \libxdamage1 \libxext6 \libxfixes3 \libxi6 \libxrandr2 \libxrender1 \libxss1 \libxtst6 \libglib2.0-0 \libgtk-3-0 \libnspr4 \libnss3 \libatk1.0-0 \libatk-bridge2.0-0 \libdrm2 \libgbm1 \libcups2 \libasound2 \libpango-1.0-0 \libpangocairo-1.0-0 \fonts-liberation \xdg-utils \lsb-release \procps \&& 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 \&& apt-get install -y --no-install-recommends /tmp/chrome.deb \&& rm -f /tmp/chrome.deb \&& 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 \HEALTH_INTERVAL=60 \DEFAULT_MODEL=@cf/moonshotai/kimi-k2.5EXPOSE 7860CMD ["/app/start.sh"]
Dockerfile+83-46