# -------- Base Python with libs Blender needs (CPU headless) -------- FROM python:3.11-slim-bookworm ENV DEBIAN_FRONTEND=noninteractive \ PIP_DISABLE_PIP_VERSION_CHECK=1 \ PIP_NO_CACHE_DIR=1 \ HOME=/home/user # System deps for Blender GUI-less rendering + git + shell RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates wget curl bzip2 xz-utils git bash rsync \ libglib2.0-0 libx11-6 libxi6 libxxf86vm1 libxrender1 libxfixes3 \ libxkbcommon0 libxrandr2 libasound2 libxinerama1 libsm6 libice6 \ libgl1 libegl1 libglu1-mesa libdbus-1-3 libxcb1 \ && rm -rf /var/lib/apt/lists/* && \ mkdir -p /home/user && chmod -R 755 /home/user # Local copy of model-viewer (avoid external loads at runtime) RUN mkdir -p /app/static && \ wget -q -O /app/static/model-viewer.min.js \ https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js # -------- Install official Blender (includes OpenImageDenoise) -------- ARG BLENDER_VERSION=4.1.1 ARG BLENDER_MAJOR=4.1 RUN wget -q https://download.blender.org/release/Blender${BLENDER_MAJOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz \ && tar -xJf blender-${BLENDER_VERSION}-linux-x64.tar.xz -C /opt \ && rm blender-${BLENDER_VERSION}-linux-x64.tar.xz \ && ln -s /opt/blender-${BLENDER_VERSION}-linux-x64/blender /usr/local/bin/blender # Pillow for Blender’s embedded Python (some scripts import PIL there) RUN /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m ensurepip && \ /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m pip install --no-cache-dir Pillow # -------- Runtime: fetch private repo, create venv, install, run app.py -------- # Space settings required: # Secret: GIT_TOKEN (PAT with repo read access) # Variable: GIT_REPO (chaous/render OR https://github.com/chaous/render.git) # Variable: GIT_REF (optional, default "main") # Variable: GIT_SUBDIR (optional, if app.py is not at repo root) RUN printf '%s\n' \ '#!/usr/bin/env bash' \ 'set -euo pipefail' \ 'export GIT_TERMINAL_PROMPT=0' \ '' \ 'export BLENDER_BIN="${BLENDER_BIN:-blender}"' \ 'TARGET_ROOT="${TARGET_ROOT:-/tmp/app}"' \ 'VENV_DIR="${VENV_DIR:-/tmp/venv}"' \ 'REPO="${GIT_REPO:-}"' \ 'REF="${GIT_REF:-main}"' \ 'SUBDIR="${GIT_SUBDIR:-}"' \ '' \ 'if [[ -z "${REPO}" || -z "${GIT_TOKEN:-}" ]]; then' \ ' echo "[error] GIT_REPO and GIT_TOKEN must be set." >&2; exit 1' \ 'fi' \ '' \ '# Normalize to full GitHub HTTPS URL' \ 'if [[ "${REPO}" == *"://"* ]]; then' \ ' BASE_URL="${REPO}"' \ 'else' \ ' BASE_URL="https://github.com/${REPO}.git"' \ 'fi' \ '' \ '# Build auth URL (token in URL prevents interactive prompts). Uses x-access-token as user.' \ 'if [[ "${BASE_URL}" == https://github.com/* ]]; then' \ ' AUTH_URL="${BASE_URL/https:\/\//https:\/\/x-access-token:${GIT_TOKEN}@}"' \ ' SAN_URL="${BASE_URL}"' \ 'else' \ ' AUTH_URL="${BASE_URL}"' \ ' SAN_URL="${BASE_URL}"' \ 'fi' \ '' \ 'echo "[info] Cloning ${SAN_URL}@${REF} into ${TARGET_ROOT}..."' \ 'rm -rf "${TARGET_ROOT}" "${VENV_DIR}"' \ 'mkdir -p "${TARGET_ROOT}"' \ 'git clone --depth 1 --branch "${REF}" "${AUTH_URL}" "${TARGET_ROOT}"' \ '' \ 'if [[ -n "${SUBDIR}" ]]; then' \ ' if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \ ' cd "${TARGET_ROOT}/${SUBDIR}"' \ ' else' \ ' echo "[warn] GIT_SUBDIR=${SUBDIR} not found; using repo root."' \ ' cd "${TARGET_ROOT}"' \ ' fi' \ 'else' \ ' cd "${TARGET_ROOT}"' \ 'fi' \ '' \ 'echo "[info] Creating venv at ${VENV_DIR}..."' \ 'python -m venv "${VENV_DIR}"' \ 'source "${VENV_DIR}/bin/activate"' \ 'python -m pip install --upgrade pip' \ '' \ 'if [[ -f requirements.txt ]]; then' \ ' echo "[info] Installing repo requirements..."' \ ' pip install -r requirements.txt' \ 'fi' \ '' \ 'if [[ ! -f app.py ]]; then' \ ' echo "[error] app.py not found in repo path." >&2; ls -la; exit 1' \ 'fi' \ '' \ 'echo "[info] Starting app.py..."' \ 'exec "${VENV_DIR}/bin/python" app.py' \ > /usr/local/bin/start.sh \ && chmod +x /usr/local/bin/start.sh # -------- HF Space runtime env -------- ENV PORT=7860 \ GRADIO_SERVER_NAME=0.0.0.0 \ GRADIO_SERVER_PORT=7860 \ BLENDER_BIN=blender EXPOSE 7860 CMD ["/usr/local/bin/start.sh"]