Download Dockerfile from Xunjunaa/pp03: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/spaces/Xunjunaa/pp03/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/Xunjunaa/pp03/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/Xunjunaa/pp03/resolve/main/Dockerfile
2.25 kB
| # notes — Hugging Face Spaces (Docker SDK) | |
| # | |
| # 本 Space 在容器里跑一个带图形栈的自动化服务(Xvfb 虚拟帧缓冲), | |
| # 需要桌面浏览器环境来保证外部站点的兼容性。 | |
| # | |
| # 鉴权(在 Space > Settings 里配): | |
| # Secrets: RELAY_KEYS, ADMIN_KEY | |
| # Variables: HEADLESS=false / ADMIN_ENABLED=true | |
| # | |
| # ---- | |
| # 用 python:3.11-slim 作为基础镜像(已包含 Python 与最小系统库) | |
| FROM python:3.11-slim | |
| # HF Spaces 要求: 非 root 用户运行 | |
| ENV DEBIAN_FRONTEND=noninteractive \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| PIP_DISABLE_PIP_VERSION_CHECK=1 \ | |
| PLAYWRIGHT_BROWSERS_PATH=/ms-playwright | |
| # 系统依赖: Xvfb(虚拟帧缓冲) + Chromium 运行需要的共享库。 | |
| # Playwright 的 --with-deps 在 HF 镜像源常超时, 这里手动列出。 | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| xvfb \ | |
| xauth \ | |
| libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 \ | |
| libdbus-1-3 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 \ | |
| libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 \ | |
| libasound2 libatspi2.0-0 libxshmfence1 \ | |
| fonts-liberation fonts-noto-cjk \ | |
| curl ca-certificates \ | |
| && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| # 先装 Python 依赖(单独一层, 改代码时不必重装) | |
| COPY requirements.txt . | |
| RUN pip install -r requirements.txt | |
| # 装 Playwright 的 Chromium(及其额外.webkit/firmware 系统库由 --with-deps 拉入) | |
| RUN playwright install chromium | |
| # 应用代码 | |
| COPY server.py config.py admin.html ./ | |
| # 非 root 用户 | |
| RUN useradd -m -u 1000 huggingface \ | |
| && mkdir -p /ms-playwright /home/huggingface/.cache \ | |
| && chown -R huggingface /ms-playwright /app /home/huggingface/.cache | |
| # HF 自动注入 HF_SPACE=1; server.py / config.py 据此走容器化路径。 | |
| ENV HF_SPACE=1 \ | |
| PORT=7860 \ | |
| HOME=/home/huggingface | |
| USER huggingface | |
| EXPOSE 7860 | |
| # 关键: 用 xvfb-run 包住 uvicorn, 给有头浏览器提供虚拟显示。 | |
| # 监听 PORT(默认 7860), HF Space 默认探测该端口。 | |
| CMD ["sh", "-c", "xvfb-run -a --server-args='-screen 0 1280x900x24' uvicorn server:app --host 0.0.0.0 --port ${PORT:-7860} --proxy-headers --forwarded-allow-ips='*'"] | |