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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +40 -32
Dockerfile CHANGED
@@ -24,19 +24,19 @@ 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 (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
- # -------- Working dir where repo will be extracted --------
32
  WORKDIR /srv/app
33
 
34
- # -------- Startup script: download private repo then run app.py --------
35
- # Required Space settings:
36
- # Secret: GIT_TOKEN (PAT with repo read access)
37
- # Variable: GIT_REPO (e.g. chaous/render OR https://github.com/chaous/render.git)
38
- # Variable: GIT_REF (optional, default "main"; branch/tag/commit)
39
- # Variable: GIT_SUBDIR (optional, if app.py is not at repo root)
40
  RUN printf '%s\n' \
41
  '#!/usr/bin/env bash' \
42
  'set -euo pipefail' \
@@ -47,47 +47,57 @@ RUN printf '%s\n' \
47
  'REPO="${GIT_REPO:-}"' \
48
  'REF="${GIT_REF:-main}"' \
49
  'SUBDIR="${GIT_SUBDIR:-}"' \
 
50
  '' \
51
  'if [[ -z "${REPO}" || -z "${GIT_TOKEN:-}" ]]; then' \
52
- ' echo "[error] GIT_REPO and GIT_TOKEN must be set in Space settings." >&2' \
53
- ' exit 1' \
54
  'fi' \
55
  '' \
56
- 'fetch_github_tarball() {' \
 
57
  ' local owner="$1"; local name="$2"; local ref="$3"' \
58
- ' echo "[info] Downloading github.com/${owner}/${name}@${ref} tarball..."' \
59
- ' local ARCHIVE_URL="https://api.github.com/repos/${owner}/${name}/tarball/${ref}"' \
60
- ' wget -q --header="Authorization: token ${GIT_TOKEN}" -O /tmp/repo.tar.gz "${ARCHIVE_URL}"' \
61
- ' rm -rf "${TARGET_ROOT:?}/"*' \
62
- ' tar -xzf /tmp/repo.tar.gz -C "${TARGET_ROOT}" --strip-components=1' \
63
- ' rm -f /tmp/repo.tar.gz' \
 
 
 
64
  '}' \
65
  '' \
66
  'echo "[info] Fetching ${REPO}@${REF}..."' \
67
  'if [[ "${REPO}" == *"://"* ]]; then' \
68
  ' # URL form' \
69
  ' if [[ "${REPO}" == *"github.com"* ]]; then' \
70
- ' path="${REPO#*github.com/}"; path="${path%.git}"' \
71
- ' owner="${path%%/*}"; name="${path#*/}"; name="${name%%/*}"' \
72
- ' fetch_github_tarball "${owner}" "${name}" "${REF}"' \
 
 
 
 
 
73
  ' else' \
74
- ' echo "[info] Non-GitHub host detected; using git clone."' \
75
  ' rm -rf "${TARGET_ROOT:?}/"*' \
76
  ' git -c http.extraHeader="Authorization: Bearer ${GIT_TOKEN}" clone --depth 1 --branch "${REF}" "${REPO}" "${TARGET_ROOT}"' \
77
  ' fi' \
78
  'else' \
79
  ' # owner/repo form' \
80
  ' owner="${REPO%%/*}"; name="${REPO#*/}"' \
81
- ' fetch_github_tarball "${owner}" "${name}" "${REF}"' \
82
- 'fi' \
83
- '' \
84
- 'if [[ -n "${SUBDIR}" ]]; then' \
85
- ' if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \
86
- ' cd "${TARGET_ROOT}/${SUBDIR}"' \
87
  ' else' \
88
- ' echo "[warn] GIT_SUBDIR=${SUBDIR} not found; using repo root."' \
89
- ' cd "${TARGET_ROOT}"' \
 
90
  ' fi' \
 
 
 
 
91
  'else' \
92
  ' cd "${TARGET_ROOT}"' \
93
  'fi' \
@@ -98,9 +108,7 @@ RUN printf '%s\n' \
98
  'fi' \
99
  '' \
100
  'if [[ ! -f app.py ]]; then' \
101
- ' echo "[error] app.py not found in repo path." >&2' \
102
- ' ls -la' \
103
- ' exit 1' \
104
  'fi' \
105
  '' \
106
  'echo "[info] Starting app.py..."' \
 
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' \
 
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' \
 
108
  'fi' \
109
  '' \
110
  'if [[ ! -f app.py ]]; then' \
111
+ ' echo "[error] app.py not found in repo path." >&2; ls -la; exit 1' \
 
 
112
  'fi' \
113
  '' \
114
  'echo "[info] Starting app.py..."' \