qbhf2 commited on
Commit
c7ff2eb
·
verified ·
1 Parent(s): 06721eb

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +61 -67
Dockerfile CHANGED
@@ -36,78 +36,72 @@ RUN pip install --no-cache-dir -r requirements.txt
36
  # -------- Fallback App code (used only if GIT_TOKEN/GIT_REPO not set) --------
37
  COPY app.py render.py /app/
38
 
39
- # -------- Runtime bootstrap to pull private repo safely --------
40
  # Expects Space settings:
41
  # Secret: GIT_TOKEN
42
  # Variable: GIT_REPO (e.g. owner/private-repo)
43
  # Variable: GIT_REF (optional, default "main")
44
  # Variable: GIT_SUBDIR (optional, if app.py not at repo root)
45
- RUN set -eux; \
46
- cat > /usr/local/bin/start.sh << 'EOF'
47
- #!/usr/bin/env bash
48
- set -euo pipefail
49
-
50
- export BLENDER_BIN="${BLENDER_BIN:-blender}"
51
-
52
- TARGET_ROOT="/srv/app"
53
- mkdir -p "$TARGET_ROOT"
54
-
55
- REPO="${GIT_REPO:-}"
56
- REF="${GIT_REF:-main}"
57
- SUBDIR="${GIT_SUBDIR:-}"
58
-
59
- use_bundled_fallback() {
60
- echo "[info] Using bundled /app fallback (no private repo configured or fetch failed)."
61
- rsync -a /app/ "${TARGET_ROOT}/"
62
- cd "${TARGET_ROOT}"
63
- exec python app.py
64
- }
65
-
66
- if [[ -z "${REPO}" ]] || [[ -z "${GIT_TOKEN:-}" ]]; then
67
- use_bundled_fallback
68
- fi
69
-
70
- echo "[info] Downloading ${REPO}@${REF} tarball from GitHub..."
71
- ARCHIVE_URL="https://api.github.com/repos/${REPO}/tarball/${REF}"
72
-
73
- # Download using header auth; avoid printing token
74
- if ! wget -q --header="Authorization: Bearer ${GIT_TOKEN}" -O /tmp/repo.tar.gz "${ARCHIVE_URL}"; then
75
- echo "[warn] Download failed; falling back to bundled app."
76
- use_bundled_fallback
77
- fi
78
-
79
- # Extract and normalize to TARGET_ROOT (strip top dir)
80
- rm -rf "${TARGET_ROOT:?}/"*
81
- tar -xzf /tmp/repo.tar.gz -C "${TARGET_ROOT}" --strip-components=1
82
- rm -f /tmp/repo.tar.gz
83
-
84
- # Optional subdir
85
- if [[ -n "${SUBDIR}" ]]; then
86
- if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then
87
- TARGET_ROOT="${TARGET_ROOT}/${SUBDIR}"
88
- else
89
- echo "[warn] GIT_SUBDIR='${SUBDIR}' not found; continuing from repo root."
90
- fi
91
- fi
92
-
93
- # Install repo-specific deps if present
94
- if [[ -f "${TARGET_ROOT}/requirements.txt" ]]; then
95
- echo "[info] Installing repo requirements..."
96
- pip install --no-cache-dir -r "${TARGET_ROOT}/requirements.txt"
97
- fi
98
-
99
- cd "${TARGET_ROOT}"
100
-
101
- # Sanity check
102
- if [[ ! -f "app.py" ]]; then
103
- echo "[warn] app.py not found in repo path; falling back to bundled app."
104
- use_bundled_fallback
105
- fi
106
-
107
- echo "[info] Starting app from private repo..."
108
- exec python app.py
109
- EOF
110
- RUN chmod +x /usr/local/bin/start.sh
111
 
112
  # Hugging Face Spaces env
113
  ENV PORT=7860 \
 
36
  # -------- Fallback App code (used only if GIT_TOKEN/GIT_REPO not set) --------
37
  COPY app.py render.py /app/
38
 
39
+ # -------- Runtime bootstrap to pull private repo safely (no heredoc; robust on HF) --------
40
  # Expects Space settings:
41
  # Secret: GIT_TOKEN
42
  # Variable: GIT_REPO (e.g. owner/private-repo)
43
  # Variable: GIT_REF (optional, default "main")
44
  # Variable: GIT_SUBDIR (optional, if app.py not at repo root)
45
+ RUN printf '%s\n' \
46
+ '#!/usr/bin/env bash' \
47
+ 'set -euo pipefail' \
48
+ '' \
49
+ 'export BLENDER_BIN="${BLENDER_BIN:-blender}"' \
50
+ '' \
51
+ 'TARGET_ROOT="/srv/app"' \
52
+ 'mkdir -p "$TARGET_ROOT"' \
53
+ '' \
54
+ 'REPO="${GIT_REPO:-}"' \
55
+ 'REF="${GIT_REF:-main}"' \
56
+ 'SUBDIR="${GIT_SUBDIR:-}"' \
57
+ '' \
58
+ 'use_bundled_fallback() {' \
59
+ ' echo "[info] Using bundled /app fallback (no private repo configured or fetch failed)."' \
60
+ ' rsync -a /app/ "${TARGET_ROOT}/"' \
61
+ ' cd "${TARGET_ROOT}"' \
62
+ ' exec python app.py' \
63
+ '}' \
64
+ '' \
65
+ 'if [[ -z "${REPO}" ]] || [[ -z "${GIT_TOKEN:-}" ]]; then' \
66
+ ' use_bundled_fallback' \
67
+ 'fi' \
68
+ '' \
69
+ 'echo "[info] Downloading ${REPO}@${REF} tarball from GitHub..."' \
70
+ 'ARCHIVE_URL="https://api.github.com/repos/${REPO}/tarball/${REF}"' \
71
+ '' \
72
+ 'if ! wget -q --header="Authorization: Bearer ${GIT_TOKEN}" -O /tmp/repo.tar.gz "${ARCHIVE_URL}"; then' \
73
+ ' echo "[warn] Download failed; falling back to bundled app."' \
74
+ ' use_bundled_fallback' \
75
+ 'fi' \
76
+ '' \
77
+ 'rm -rf "${TARGET_ROOT:?}/"*' \
78
+ 'tar -xzf /tmp/repo.tar.gz -C "${TARGET_ROOT}" --strip-components=1' \
79
+ 'rm -f /tmp/repo.tar.gz' \
80
+ '' \
81
+ 'if [[ -n "${SUBDIR}" ]]; then' \
82
+ ' if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \
83
+ ' TARGET_ROOT="${TARGET_ROOT}/${SUBDIR}"' \
84
+ ' else' \
85
+ ' echo "[warn] GIT_SUBDIR=${SUBDIR} not found; continuing from repo root."' \
86
+ ' fi' \
87
+ 'fi' \
88
+ '' \
89
+ 'if [[ -f "${TARGET_ROOT}/requirements.txt" ]]; then' \
90
+ ' echo "[info] Installing repo requirements..."' \
91
+ ' pip install --no-cache-dir -r "${TARGET_ROOT}/requirements.txt"' \
92
+ 'fi' \
93
+ '' \
94
+ 'cd "${TARGET_ROOT}"' \
95
+ '' \
96
+ 'if [[ ! -f "app.py" ]]; then' \
97
+ ' echo "[warn] app.py not found in repo path; falling back to bundled app."' \
98
+ ' use_bundled_fallback' \
99
+ 'fi' \
100
+ '' \
101
+ 'echo "[info] Starting app from private repo..."' \
102
+ 'exec python app.py' \
103
+ > /usr/local/bin/start.sh \
104
+ && chmod +x /usr/local/bin/start.sh
 
 
 
 
 
 
105
 
106
  # Hugging Face Spaces env
107
  ENV PORT=7860 \