Spaces:
Paused
Paused
File size: 4,542 Bytes
f636d45 06721eb f636d45 9fc5909 f636d45 39c45d5 f636d45 39c45d5 f636d45 39c45d5 f636d45 9fc5909 c7ff2eb 9fc5909 c7ff2eb 39c45d5 c7ff2eb 9fc5909 c7ff2eb 9fc5909 c7ff2eb 39c45d5 c7ff2eb 39c45d5 c7ff2eb 39c45d5 c7ff2eb 39c45d5 c7ff2eb 39c45d5 c7ff2eb 39c45d5 c7ff2eb 39c45d5 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 117 118 119 | # -------- Base Python with libs Blender needs (CPU headless) --------
FROM python:3.11-slim-bookworm
ENV DEBIAN_FRONTEND=noninteractive
# System deps for Blender GUI-less rendering + runtime fetch tools
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates wget curl bzip2 xz-utils git rsync bash \
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/*
# Local copy of model-viewer (no 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 inside 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
# -------- Working dir where repo will be extracted --------
WORKDIR /srv/app
# -------- Startup script: download private repo then run app.py --------
# Required Space settings:
# Secret: GIT_TOKEN (PAT with repo read access)
# Variable: GIT_REPO (e.g. chaous/render OR https://github.com/chaous/render.git)
# Variable: GIT_REF (optional, default "main"; branch/tag/commit)
# 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="/srv/app"' \
'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 in Space settings." >&2' \
' exit 1' \
'fi' \
'' \
'fetch_github_tarball() {' \
' local owner="$1"; local name="$2"; local ref="$3"' \
' echo "[info] Downloading github.com/${owner}/${name}@${ref} tarball..."' \
' local ARCHIVE_URL="https://api.github.com/repos/${owner}/${name}/tarball/${ref}"' \
' wget -q --header="Authorization: token ${GIT_TOKEN}" -O /tmp/repo.tar.gz "${ARCHIVE_URL}"' \
' rm -rf "${TARGET_ROOT:?}/"*' \
' tar -xzf /tmp/repo.tar.gz -C "${TARGET_ROOT}" --strip-components=1' \
' rm -f /tmp/repo.tar.gz' \
'}' \
'' \
'echo "[info] Fetching ${REPO}@${REF}..."' \
'if [[ "${REPO}" == *"://"* ]]; then' \
' # URL form' \
' if [[ "${REPO}" == *"github.com"* ]]; then' \
' path="${REPO#*github.com/}"; path="${path%.git}"' \
' owner="${path%%/*}"; name="${path#*/}"; name="${name%%/*}"' \
' fetch_github_tarball "${owner}" "${name}" "${REF}"' \
' else' \
' echo "[info] Non-GitHub host detected; using git clone."' \
' rm -rf "${TARGET_ROOT:?}/"*' \
' git -c http.extraHeader="Authorization: Bearer ${GIT_TOKEN}" clone --depth 1 --branch "${REF}" "${REPO}" "${TARGET_ROOT}"' \
' fi' \
'else' \
' # owner/repo form' \
' owner="${REPO%%/*}"; name="${REPO#*/}"' \
' fetch_github_tarball "${owner}" "${name}" "${REF}"' \
'fi' \
'' \
'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' \
'' \
'if [[ -f requirements.txt ]]; then' \
' echo "[info] Installing repo requirements..."' \
' pip install --no-cache-dir -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 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"]
|