shadowbrain / Dockerfile
taemin1980's picture
πŸ”± Imperial Deployment: Shadow Brain Core ignition
d50a68d verified
Raw
History Blame Contribute Delete
2.9 kB
# πŸ”± 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