qbhf2 commited on
Commit
bb3d7b0
·
verified ·
1 Parent(s): 30c11f5

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -56
Dockerfile CHANGED
@@ -3,15 +3,15 @@ FROM python:3.11-slim-bookworm
3
 
4
  ENV DEBIAN_FRONTEND=noninteractive
5
 
6
- # System deps for Blender GUI-less rendering + runtime fetch tools
7
  RUN apt-get update && apt-get install -y --no-install-recommends \
8
- ca-certificates wget curl bzip2 xz-utils git rsync bash \
9
  libglib2.0-0 libx11-6 libxi6 libxxf86vm1 libxrender1 libxfixes3 \
10
  libxkbcommon0 libxrandr2 libasound2 libxinerama1 libsm6 libice6 \
11
  libgl1 libegl1 libglu1-mesa libdbus-1-3 libxcb1 \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- # Local copy of model-viewer (no external loads at runtime)
15
  RUN mkdir -p /app/static && \
16
  wget -q -O /app/static/model-viewer.min.js \
17
  https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js
@@ -24,80 +24,53 @@ RUN wget -q https://download.blender.org/release/Blender${BLENDER_MAJOR}/blender
24
  && rm blender-${BLENDER_VERSION}-linux-x64.tar.xz \
25
  && ln -s /opt/blender-${BLENDER_VERSION}-linux-x64/blender /usr/local/bin/blender
26
 
27
- # Pillow inside Blender's embedded Python
28
  RUN /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m ensurepip && \
29
  /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m pip install --no-cache-dir Pillow
30
 
31
- # -------- Where the repo will live at runtime --------
32
- WORKDIR /srv/app
33
-
34
- # -------- Startup script: fetch private repo, install, run app.py --------
35
- # Space settings required:
36
- # Secret: GIT_TOKEN (PAT with repo read access)
37
- # Variable: GIT_REPO (chaous/render OR https://github.com/chaous/render.git)
38
- # Variable: GIT_REF (optional, default "main")
39
- # Variable: GIT_SUBDIR (optional)
40
  RUN printf '%s\n' \
41
  '#!/usr/bin/env bash' \
42
  'set -euo pipefail' \
43
  'export GIT_TERMINAL_PROMPT=0' \
44
  '' \
45
  'export BLENDER_BIN="${BLENDER_BIN:-blender}"' \
46
- 'TARGET_ROOT="/srv/app"' \
47
  'REPO="${GIT_REPO:-}"' \
48
  'REF="${GIT_REF:-main}"' \
49
  'SUBDIR="${GIT_SUBDIR:-}"' \
50
- 'UA="hf-space/1.0"' \
51
  '' \
52
  'if [[ -z "${REPO}" || -z "${GIT_TOKEN:-}" ]]; then' \
53
  ' echo "[error] GIT_REPO and GIT_TOKEN must be set." >&2; exit 1' \
54
  'fi' \
55
  '' \
56
- 'fetch_tarball() {' \
57
- ' # Args: owner name ref' \
58
- ' local owner="$1"; local name="$2"; local ref="$3"' \
59
- ' echo "[info] Trying codeload tarball ${owner}/${name}@${ref}..."' \
60
- ' local url1="https://codeload.github.com/${owner}/${name}/tar.gz/${ref}"' \
61
- ' if curl -fsSL -H "Authorization: Bearer ${GIT_TOKEN}" -H "User-Agent: ${UA}" -o /tmp/repo.tar.gz "$url1"; then' \
62
- ' return 0; fi' \
63
- ' echo "[warn] codeload failed; trying API tarball..."' \
64
- ' local url2="https://api.github.com/repos/${owner}/${name}/tarball/${ref}"' \
65
- ' if curl -fsSL -H "Authorization: Bearer ${GIT_TOKEN}" -H "User-Agent: ${UA}" -H "X-GitHub-Api-Version: 2022-11-28" -o /tmp/repo.tar.gz "$url2"; then' \
66
- ' return 0; fi' \
67
- ' return 1' \
68
- '}' \
69
- '' \
70
- 'echo "[info] Fetching ${REPO}@${REF}..."' \
71
  'if [[ "${REPO}" == *"://"* ]]; then' \
72
- ' # URL form' \
73
- ' if [[ "${REPO}" == *"github.com"* ]]; then' \
74
- ' path="${REPO#*github.com/}"; path="${path%.git}"; owner="${path%%/*}"; name="${path#*/}"; name="${name%%/*}"' \
75
- ' if fetch_tarball "$owner" "$name" "$REF"; then' \
76
- ' rm -rf "${TARGET_ROOT:?}/"*; tar -xzf /tmp/repo.tar.gz -C "${TARGET_ROOT}" --strip-components=1; rm -f /tmp/repo.tar.gz' \
77
- ' else' \
78
- ' echo "[warn] Tarball failed; falling back to git clone..."' \
79
- ' rm -rf "${TARGET_ROOT:?}/"*' \
80
- ' git -c http.extraHeader="Authorization: Bearer ${GIT_TOKEN}" clone --depth 1 --branch "${REF}" "${REPO}" "${TARGET_ROOT}"' \
81
- ' fi' \
82
- ' else' \
83
- ' echo "[info] Non-GitHub host; using git clone."' \
84
- ' rm -rf "${TARGET_ROOT:?}/"*' \
85
- ' git -c http.extraHeader="Authorization: Bearer ${GIT_TOKEN}" clone --depth 1 --branch "${REF}" "${REPO}" "${TARGET_ROOT}"' \
86
- ' fi' \
87
  'else' \
88
- ' # owner/repo form' \
89
- ' owner="${REPO%%/*}"; name="${REPO#*/}"' \
90
- ' if fetch_tarball "$owner" "$name" "$REF"; then' \
91
- ' rm -rf "${TARGET_ROOT:?}/"*; tar -xzf /tmp/repo.tar.gz -C "${TARGET_ROOT}" --strip-components=1; rm -f /tmp/repo.tar.gz' \
92
- ' else' \
93
- ' echo "[warn] Tarball failed; falling back to git clone..."' \
94
- ' rm -rf "${TARGET_ROOT:?}/"*' \
95
- ' git -c http.extraHeader="Authorization: Bearer ${GIT_TOKEN}" clone --depth 1 --branch "${REF}" "https://github.com/${owner}/${name}.git" "${TARGET_ROOT}"' \
96
- ' fi' \
97
  'fi' \
98
  '' \
99
- 'if [[ -n "${SUBDIR}" && -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \
100
- ' cd "${TARGET_ROOT}/${SUBDIR}"' \
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  'else' \
102
  ' cd "${TARGET_ROOT}"' \
103
  'fi' \
 
3
 
4
  ENV DEBIAN_FRONTEND=noninteractive
5
 
6
+ # System deps for Blender GUI-less rendering + git + shell
7
  RUN apt-get update && apt-get install -y --no-install-recommends \
8
+ ca-certificates wget curl bzip2 xz-utils git bash rsync \
9
  libglib2.0-0 libx11-6 libxi6 libxxf86vm1 libxrender1 libxfixes3 \
10
  libxkbcommon0 libxrandr2 libasound2 libxinerama1 libsm6 libice6 \
11
  libgl1 libegl1 libglu1-mesa libdbus-1-3 libxcb1 \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Local copy of model-viewer (avoid external loads at runtime)
15
  RUN mkdir -p /app/static && \
16
  wget -q -O /app/static/model-viewer.min.js \
17
  https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js
 
24
  && rm blender-${BLENDER_VERSION}-linux-x64.tar.xz \
25
  && ln -s /opt/blender-${BLENDER_VERSION}-linux-x64/blender /usr/local/bin/blender
26
 
27
+ # Pillow for Blenders embedded Python (some scripts import PIL there)
28
  RUN /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m ensurepip && \
29
  /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m pip install --no-cache-dir Pillow
30
 
31
+ # -------- Runtime: fetch private repo, install, run app.py --------
32
+ # Required Space settings:
33
+ # Secret: GIT_TOKEN (PAT with repo read access)
34
+ # Variable: GIT_REPO (chaous/render OR https://github.com/chaous/render.git)
35
+ # Variable: GIT_REF (optional, default "main")
36
+ # Variable: GIT_SUBDIR (optional, if app.py is not at repo root)
 
 
 
37
  RUN printf '%s\n' \
38
  '#!/usr/bin/env bash' \
39
  'set -euo pipefail' \
40
  'export GIT_TERMINAL_PROMPT=0' \
41
  '' \
42
  'export BLENDER_BIN="${BLENDER_BIN:-blender}"' \
43
+ 'TARGET_ROOT="${TARGET_ROOT:-/tmp/app}"' \
44
  'REPO="${GIT_REPO:-}"' \
45
  'REF="${GIT_REF:-main}"' \
46
  'SUBDIR="${GIT_SUBDIR:-}"' \
 
47
  '' \
48
  'if [[ -z "${REPO}" || -z "${GIT_TOKEN:-}" ]]; then' \
49
  ' echo "[error] GIT_REPO and GIT_TOKEN must be set." >&2; exit 1' \
50
  'fi' \
51
  '' \
52
+ '# Normalize repo to a full HTTPS URL if needed' \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  'if [[ "${REPO}" == *"://"* ]]; then' \
54
+ ' GIT_URL="${REPO}"' \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  'else' \
56
+ ' GIT_URL="https://github.com/${REPO}.git"' \
 
 
 
 
 
 
 
 
57
  'fi' \
58
  '' \
59
+ 'echo "[info] Cloning ${GIT_URL}@${REF} into ${TARGET_ROOT}..."' \
60
+ 'rm -rf "${TARGET_ROOT}"' \
61
+ 'mkdir -p "${TARGET_ROOT}"' \
62
+ 'chmod -R 777 "${TARGET_ROOT}" || true' \
63
+ '' \
64
+ '# Use header auth (no token in URL or logs)' \
65
+ 'git -c http.extraHeader="Authorization: token ${GIT_TOKEN}" clone --depth 1 --branch "${REF}" "${GIT_URL}" "${TARGET_ROOT}"' \
66
+ '' \
67
+ 'if [[ -n "${SUBDIR}" ]]; then' \
68
+ ' if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \
69
+ ' cd "${TARGET_ROOT}/${SUBDIR}"' \
70
+ ' else' \
71
+ ' echo "[warn] GIT_SUBDIR=${SUBDIR} not found; using repo root."' \
72
+ ' cd "${TARGET_ROOT}"' \
73
+ ' fi' \
74
  'else' \
75
  ' cd "${TARGET_ROOT}"' \
76
  'fi' \