# syntax=docker/dockerfile:1.7 # # Hugging Face Space (sdk: docker) for the CADGenBench leaderboard. # # HF builds this server-side on each git push. Local smoke test: # # docker buildx build --platform linux/amd64 -t cadgenbench-space-test . # # cadgenbench is installed from github.com/huggingface/cadgenbench, which # is Public. No build secrets or auth required. FROM python:3.12-slim-bookworm ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 \ GRADIO_SERVER_NAME=0.0.0.0 \ GRADIO_SERVER_PORT=7860 # OS deps: # git, ca-certificates -> pip install from git+https:// # libglib2.0-0, libsm6, libxext6, # libgomp1, libfontconfig1 -> OCP / build123d / Pillow runtime # libgl1, libglx-mesa0, libegl1, # libegl-mesa0, libxrender1 -> VTK / PyVista off-screen GL context. # The HF Space's cpu-upgrade tier has no GPU; VTK's EGL backend picks up # Mesa's software rasteriser (libegl-mesa0) at runtime, no code change. # A GPU host gets hardware OpenGL via the same libs. RUN apt-get update && apt-get install -y --no-install-recommends \ git ca-certificates \ libglib2.0-0 libsm6 libxext6 libgomp1 libfontconfig1 \ libgl1 libglx-mesa0 libegl1 libegl-mesa0 libxrender1 \ && rm -rf /var/lib/apt/lists/* # Space-side Python deps (gradio, pandas, huggingface_hub, datasets). COPY requirements.txt /tmp/requirements.txt RUN pip install --no-cache-dir -r /tmp/requirements.txt \ && rm /tmp/requirements.txt # cadgenbench from the Public GitHub repo. Defaults to `main` so every # image rebuild picks up the latest code (pre-v1: always-updated). Lock # to a specific commit SHA at the v1 release so published scores are # reproducible (see space-setup/post-gt-swap.md Stage F). ARG CADGENBENCH_SHA=1010043 # Cache-bust the install below whenever the tracked ref moves: the # GitHub commits endpoint's response changes with each new commit on # `main`, so BuildKit re-fetches and invalidates the cached pip layer. # Without it, `@main` would stay pinned to whatever `main` was at first # build. Stable (a no-op) when CADGENBENCH_SHA is a fixed commit SHA. ADD https://api.github.com/repos/huggingface/cadgenbench/commits/${CADGENBENCH_SHA} /tmp/cadgenbench.commit RUN pip install --no-cache-dir \ "cadgenbench @ git+https://github.com/huggingface/cadgenbench.git@${CADGENBENCH_SHA}" # The stock `vtk` wheel that pyvista pulls from PyPI is built with # vtkXOpenGLRenderWindow, which needs an X server and segfaults the # worker on a truly-headless container (no DISPLAY). Swap it for # `vtk-osmesa`, the same VTK build but compiled against OSMesa (pure # CPU software rasteriser, self-contained, no display server required). # This is the canonical PyVista headless-Docker recipe; the wheel # comes from Kitware's index, not PyPI proper. RUN pip uninstall -y vtk \ && pip install --no-cache-dir \ --extra-index-url https://wheels.vtk.org vtk-osmesa # Drop privileges. HF Spaces conventionally run as uid 1000 with # WORKDIR /home/user/app. RUN useradd -m -u 1000 user \ && mkdir -p /home/user/app \ && chown -R user:user /home/user/app USER user WORKDIR /home/user/app COPY --chown=user:user *.py ./ EXPOSE 7860 CMD ["python", "app.py"]