Spaces:
Paused
Paused
Update Dockerfile
Browse files- 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
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
TARGET_ROOT
|
| 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 |
-
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 \
|