step 6 (A2): switch space to sdk:docker, install cadgenbench from private LeForge via GH_PAT build secret
Browse filesThe HF Spaces Gradio SDK can't substitute Space secrets into requirements.txt
at build time (only at runtime), and embedding the literal token in
requirements.txt is a no-go (would land in git history of the Space).
Switching to sdk: docker collapses two open Step 6 sub-decisions into one
small change:
(A2) private GitHub dep install -- handled by `RUN --mount=type=secret`
in the Dockerfile; the PAT (Space secret GH_PAT) is mounted at
/run/secrets/GH_PAT for that one RUN and never lands in any layer.
(D) Playwright/Chromium for STEP -> PNG rendering -- handled by
`playwright install --with-deps chromium` in the same Dockerfile.
Layer ordering optimises rebuild speed: OS deps + requirements.txt deps
+ Chromium come early (stable), cadgenbench from git comes mid (bumps
on each commit), app.py + results.jsonl come last (changes most).
Front-matter: sdk: gradio -> sdk: docker, drop sdk_version + app_file
(Docker SDK uses Dockerfile CMD), add app_port: 7860. .dockerignore
keeps legacy/'s 19 MB out of the build context.
GH_PAT set on the Space via HfApi().add_space_secret(...) -- fine-grained
GitHub PAT, read-only Contents on MichaelRabinovich/LeForge, 1-year
expiry. Mirrors at /tmp/gh_pat locally for `docker build --secret`.
Co-authored-by: Cursor <cursoragent@cursor.com>
- .dockerignore +11 -0
- Dockerfile +69 -0
- README.md +2 -3
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Build context exclusions for `docker build` (HF Space + local).
|
| 2 |
+
# COPY directives in the Dockerfile are explicit so this is purely a
|
| 3 |
+
# build-speed optimisation: prevents sending 19 MB of legacy HTML and
|
| 4 |
+
# any local caches to the daemon on every build.
|
| 5 |
+
.git
|
| 6 |
+
.gitattributes
|
| 7 |
+
.gitignore
|
| 8 |
+
__pycache__
|
| 9 |
+
*.pyc
|
| 10 |
+
.DS_Store
|
| 11 |
+
legacy/
|
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# syntax=docker/dockerfile:1.7
|
| 2 |
+
#
|
| 3 |
+
# Hugging Face Space (sdk: docker) for the CADGenBench leaderboard.
|
| 4 |
+
#
|
| 5 |
+
# HF builds this server-side on each git push. Local smoke test:
|
| 6 |
+
#
|
| 7 |
+
# docker buildx build --platform linux/amd64 \
|
| 8 |
+
# --secret id=GH_PAT,src=/tmp/gh_pat \
|
| 9 |
+
# -t cadgenbench-space-test .
|
| 10 |
+
#
|
| 11 |
+
# The GH_PAT mount is a fine-grained GitHub PAT, read-only on
|
| 12 |
+
# MichaelRabinovich/LeForge, used only by the `pip install cadgenbench`
|
| 13 |
+
# step below. It never lands in an image layer, env var, or disk file
|
| 14 |
+
# in the final image. The same value lives on the Space as a Settings
|
| 15 |
+
# Secret (mirrors /tmp/gh_pat locally).
|
| 16 |
+
|
| 17 |
+
FROM python:3.12-slim-bookworm
|
| 18 |
+
|
| 19 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 20 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 21 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 22 |
+
PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright \
|
| 23 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 24 |
+
GRADIO_SERVER_PORT=7860
|
| 25 |
+
|
| 26 |
+
# OS deps:
|
| 27 |
+
# git, ca-certificates -> pip install from git+https://
|
| 28 |
+
# libgl1, libglib2.0-0, libsm6,
|
| 29 |
+
# libxext6, libxrender1, -> OCP / build123d / Pillow runtime
|
| 30 |
+
# libgomp1, libfontconfig1
|
| 31 |
+
# Chromium's own runtime libs are added by `playwright install --with-deps`
|
| 32 |
+
# below, so they aren't repeated here.
|
| 33 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 34 |
+
git ca-certificates \
|
| 35 |
+
libgl1 libglib2.0-0 libsm6 libxext6 libxrender1 libgomp1 libfontconfig1 \
|
| 36 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 37 |
+
|
| 38 |
+
# Space-side Python deps (gradio, pandas, huggingface_hub, datasets).
|
| 39 |
+
COPY requirements.txt /tmp/requirements.txt
|
| 40 |
+
RUN pip install --no-cache-dir -r /tmp/requirements.txt \
|
| 41 |
+
&& rm /tmp/requirements.txt
|
| 42 |
+
|
| 43 |
+
# Playwright + headless Chromium for cadgenbench's STEP -> PNG renderer
|
| 44 |
+
# (cadgenbench.common.viewer wraps tcv-screenshots -> playwright). Browsers
|
| 45 |
+
# land in /opt/ms-playwright (world-readable) so the non-root runtime user
|
| 46 |
+
# below can find them via PLAYWRIGHT_BROWSERS_PATH. ~200 MB layer.
|
| 47 |
+
RUN pip install --no-cache-dir playwright \
|
| 48 |
+
&& playwright install --with-deps chromium
|
| 49 |
+
|
| 50 |
+
# cadgenbench from the private GitHub repo, pinned to a commit. The PAT
|
| 51 |
+
# mount is visible only inside this single RUN: not embedded in any layer,
|
| 52 |
+
# not exposed as env, not written to disk after the layer commits. Bumping
|
| 53 |
+
# CADGENBENCH_SHA is the one-line path to picking up a new cadgenbench.
|
| 54 |
+
ARG CADGENBENCH_SHA=d7e0468
|
| 55 |
+
RUN --mount=type=secret,id=GH_PAT,mode=0400,required=true \
|
| 56 |
+
pip install --no-cache-dir \
|
| 57 |
+
"cadgenbench @ git+https://$(cat /run/secrets/GH_PAT)@github.com/MichaelRabinovich/LeForge.git@${CADGENBENCH_SHA}"
|
| 58 |
+
|
| 59 |
+
# Drop privileges. HF Spaces conventionally run as uid 1000 with
|
| 60 |
+
# WORKDIR /home/user/app.
|
| 61 |
+
RUN useradd -m -u 1000 user \
|
| 62 |
+
&& mkdir -p /home/user/app \
|
| 63 |
+
&& chown -R user:user /home/user/app
|
| 64 |
+
USER user
|
| 65 |
+
WORKDIR /home/user/app
|
| 66 |
+
COPY --chown=user:user app.py results.jsonl ./
|
| 67 |
+
|
| 68 |
+
EXPOSE 7860
|
| 69 |
+
CMD ["python", "app.py"]
|
|
@@ -3,9 +3,8 @@ title: CADGenBench Leaderboard
|
|
| 3 |
emoji: 🔧
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: pink
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
short_description: Leaderboard for AI-driven CAD generation
|
| 11 |
---
|
|
|
|
| 3 |
emoji: 🔧
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: pink
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
|
|
|
| 8 |
pinned: true
|
| 9 |
short_description: Leaderboard for AI-driven CAD generation
|
| 10 |
---
|