Spaces:
Paused
Paused
File size: 4,294 Bytes
f636d45 2bc9675 f636d45 bb3d7b0 f636d45 bb3d7b0 f636d45 2bc9675 f636d45 bb3d7b0 f636d45 bb3d7b0 f636d45 2bc9675 bb3d7b0 c7ff2eb 9fc5909 c7ff2eb bb3d7b0 2bc9675 c7ff2eb 39c45d5 30c11f5 c7ff2eb 6d67087 9fc5909 6d67087 9fc5909 6d67087 30c11f5 2bc9675 6d67087 2bc9675 bb3d7b0 2bc9675 bb3d7b0 39c45d5 c7ff2eb 2bc9675 39c45d5 c7ff2eb 2bc9675 c7ff2eb 39c45d5 30c11f5 c7ff2eb 39c45d5 2bc9675 c7ff2eb f636d45 39c45d5 f636d45 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | # -------- 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"]
|