Team Ai
Apppublic

ArtificialSeedAI/render

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
Dockerfile116 linesDownload Raw Back to root
1# -------- Base Python with libs Blender needs (CPU headless) --------2FROM python:3.11-slim-bookworm3 4ENV DEBIAN_FRONTEND=noninteractive \5    PIP_DISABLE_PIP_VERSION_CHECK=1 \6    PIP_NO_CACHE_DIR=1 \7    HOME=/home/user8 9# System deps for Blender GUI-less rendering + git + shell10RUN apt-get update && apt-get install -y --no-install-recommends \11    ca-certificates wget curl bzip2 xz-utils git bash rsync \12    libglib2.0-0 libx11-6 libxi6 libxxf86vm1 libxrender1 libxfixes3 \13    libxkbcommon0 libxrandr2 libasound2 libxinerama1 libsm6 libice6 \14    libgl1 libegl1 libglu1-mesa libdbus-1-3 libxcb1 \15 && rm -rf /var/lib/apt/lists/* && \16    mkdir -p /home/user && chmod -R 755 /home/user17 18# Local copy of model-viewer (avoid external loads at runtime)19RUN mkdir -p /app/static && \20    wget -q -O /app/static/model-viewer.min.js \21      https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js22 23# -------- Install official Blender (includes OpenImageDenoise) --------24ARG BLENDER_VERSION=4.1.125ARG BLENDER_MAJOR=4.126RUN wget -q https://download.blender.org/release/Blender${BLENDER_MAJOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz \27 && tar -xJf blender-${BLENDER_VERSION}-linux-x64.tar.xz -C /opt \28 && rm blender-${BLENDER_VERSION}-linux-x64.tar.xz \29 && ln -s /opt/blender-${BLENDER_VERSION}-linux-x64/blender /usr/local/bin/blender30 31# Pillow for Blender’s embedded Python (some scripts import PIL there)32RUN /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m ensurepip && \33    /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m pip install --no-cache-dir Pillow34 35# -------- Runtime: fetch private repo, create venv, install, run app.py --------36# Space settings required:37#   Secret:   GIT_TOKEN                         (PAT with repo read access)38#   Variable: GIT_REPO                          (chaous/render OR https://github.com/chaous/render.git)39#   Variable: GIT_REF       (optional, default "main")40#   Variable: GIT_SUBDIR    (optional, if app.py is not at repo root)41RUN printf '%s\n' \42'#!/usr/bin/env bash' \43'set -euo pipefail' \44'export GIT_TERMINAL_PROMPT=0' \45'' \46'export BLENDER_BIN="${BLENDER_BIN:-blender}"' \47'TARGET_ROOT="${TARGET_ROOT:-/tmp/app}"' \48'VENV_DIR="${VENV_DIR:-/tmp/venv}"' \49'REPO="${GIT_REPO:-}"' \50'REF="${GIT_REF:-main}"' \51'SUBDIR="${GIT_SUBDIR:-}"' \52'' \53'if [[ -z "${REPO}" || -z "${GIT_TOKEN:-}" ]]; then' \54'  echo "[error] GIT_REPO and GIT_TOKEN must be set." >&2; exit 1' \55'fi' \56'' \57'# Normalize to full GitHub HTTPS URL' \58'if [[ "${REPO}" == *"://"* ]]; then' \59'  BASE_URL="${REPO}"' \60'else' \61'  BASE_URL="https://github.com/${REPO}.git"' \62'fi' \63'' \64'# Build auth URL (token in URL prevents interactive prompts). Uses x-access-token as user.' \65'if [[ "${BASE_URL}" == https://github.com/* ]]; then' \66'  AUTH_URL="${BASE_URL/https:\/\//https:\/\/x-access-token:${GIT_TOKEN}@}"' \67'  SAN_URL="${BASE_URL}"' \68'else' \69'  AUTH_URL="${BASE_URL}"' \70'  SAN_URL="${BASE_URL}"' \71'fi' \72'' \73'echo "[info] Cloning ${SAN_URL}@${REF} into ${TARGET_ROOT}..."' \74'rm -rf "${TARGET_ROOT}" "${VENV_DIR}"' \75'mkdir -p "${TARGET_ROOT}"' \76'git clone --depth 1 --branch "${REF}" "${AUTH_URL}" "${TARGET_ROOT}"' \77'' \78'if [[ -n "${SUBDIR}" ]]; then' \79'  if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \80'    cd "${TARGET_ROOT}/${SUBDIR}"' \81'  else' \82'    echo "[warn] GIT_SUBDIR=${SUBDIR} not found; using repo root."' \83'    cd "${TARGET_ROOT}"' \84'  fi' \85'else' \86'  cd "${TARGET_ROOT}"' \87'fi' \88'' \89'echo "[info] Creating venv at ${VENV_DIR}..."' \90'python -m venv "${VENV_DIR}"' \91'source "${VENV_DIR}/bin/activate"' \92'python -m pip install --upgrade pip' \93'' \94'if [[ -f requirements.txt ]]; then' \95'  echo "[info] Installing repo requirements..."' \96'  pip install -r requirements.txt' \97'fi' \98'' \99'if [[ ! -f app.py ]]; then' \100'  echo "[error] app.py not found in repo path." >&2; ls -la; exit 1' \101'fi' \102'' \103'echo "[info] Starting app.py..."' \104'exec "${VENV_DIR}/bin/python" app.py' \105> /usr/local/bin/start.sh \106 && chmod +x /usr/local/bin/start.sh107 108# -------- HF Space runtime env --------109ENV PORT=7860 \110    GRADIO_SERVER_NAME=0.0.0.0 \111    GRADIO_SERVER_PORT=7860 \112    BLENDER_BIN=blender113 114EXPOSE 7860115CMD ["/usr/local/bin/start.sh"]116