Spaces:
Running
Running
| # π± Imperial Shadow Brain (API Core) - Hugging Face Spaces Dockerfile | |
| # [v3.0.0] β Playwright MCP Full Support (Node.js + Chromium) | |
| FROM python:3.10-slim | |
| # 1. Install System Dependencies (Playwright OS Dependencies + Node.js) | |
| # Playwright requires specific system libraries to run chromium in headless mode. | |
| # Node.js is required for npx @playwright/mcp --headless (MCP stdio server). | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libpq-dev \ | |
| gcc \ | |
| curl \ | |
| gnupg \ | |
| # Chromium runtime dependencies | |
| libglib2.0-0 \ | |
| libnss3 \ | |
| libnspr4 \ | |
| libatk1.0-0 \ | |
| libatk-bridge2.0-0 \ | |
| libcups2 \ | |
| libdrm2 \ | |
| libxkbcommon0 \ | |
| libxcomposite1 \ | |
| libxdamage1 \ | |
| libxext6 \ | |
| libxfixes3 \ | |
| libxrandr2 \ | |
| libgbm1 \ | |
| libasound2 \ | |
| libpango-1.0-0 \ | |
| libcairo2 \ | |
| # π± [HF Headless Fix] κ°μ λμ€νλ μ΄(Xvfb) β google-surf-mcp λ± headed λΈλΌμ°μ κ° | |
| # HF 컨ν μ΄λ(X server μμ)μμ λμνλλ‘ νλ€. xauth λ xvfb-run μ νμ. | |
| xvfb \ | |
| xauth \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # 2. Install Node.js 20 LTS (required for npx @playwright/mcp) | |
| RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ | |
| && apt-get install -y --no-install-recommends nodejs \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # 3. Pre-install MCP servers globally so npx doesn't need to download at runtime | |
| RUN npm install -g @playwright/mcp google-surf-mcp | |
| # 3b. [HF Headless Fix] X11 μ λμ€ μμΌ λλ ν°λ¦¬λ₯Ό 미리 μμ±(sticky). λΉroot(user 1000)λ‘ μ€νλλ | |
| # 컨ν μ΄λμμ xvfb-run μ΄ X μλ² μμΌμ λ§λ€ μ μμ΄μΌ νλ€. μμΌλ©΄ "Missing X server" κ° κ³μ λλ€. | |
| RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix | |
| # 4. Set Environment Variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PORT=7860 | |
| ENV APP_ENV=live | |
| # 5. Create non-root user for HF Spaces (Best Practice) | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| # 6. Copy and Install Python Dependencies | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir --user -r requirements.txt && \ | |
| python -m playwright install chromium | |
| # 7. Copy Application Source Code | |
| COPY --chown=user . . | |
| # 8. Expose the required port for HF Spaces | |
| EXPOSE 7860 | |
| # 9. Start the Imperial Core | |
| # Use shell form to resolve environment variable $PORT provided by HF Spaces. | |
| # π± [HF Headless Fix] xvfb-run μΌλ‘ κ°μ λμ€νλ μ΄ μμμ μ€ν β gunicornμ΄ λμ°λ | |
| # MCP λΈλΌμ°μ μμ νλ‘μΈμ€(google-surf λ±)κ° DISPLAY λ₯Ό μμλ°μ μ μ ꡬλλλ€. | |
| CMD xvfb-run --auto-servernum --server-args="-screen 0 1280x1024x24 -nolisten tcp" gunicorn --bind 0.0.0.0:${PORT:-7860} --workers 1 --threads 4 --timeout 120 --access-logfile - --error-logfile - app:app | |