Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +28 -44
Dockerfile
CHANGED
|
@@ -5,13 +5,13 @@ 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 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 |
-
#
|
| 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,55 +24,37 @@ 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 |
-
# --------
|
| 32 |
-
WORKDIR /app
|
| 33 |
-
COPY requirements.txt /app/requirements.txt
|
| 34 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 35 |
|
| 36 |
-
# --------
|
| 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
|
| 43 |
-
# Variable: GIT_REF
|
| 44 |
-
# Variable: GIT_SUBDIR
|
| 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 |
-
'
|
| 59 |
-
' echo "[
|
| 60 |
-
'
|
| 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]
|
| 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' \
|
|
@@ -80,30 +62,32 @@ RUN printf '%s\n' \
|
|
| 80 |
'' \
|
| 81 |
'if [[ -n "${SUBDIR}" ]]; then' \
|
| 82 |
' if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \
|
| 83 |
-
'
|
| 84 |
' else' \
|
| 85 |
-
' echo "[warn] GIT_SUBDIR=${SUBDIR} not found;
|
|
|
|
| 86 |
' fi' \
|
|
|
|
|
|
|
| 87 |
'fi' \
|
| 88 |
'' \
|
| 89 |
-
'if [[ -f
|
| 90 |
' echo "[info] Installing repo requirements..."' \
|
| 91 |
-
' pip install --no-cache-dir -r
|
| 92 |
'fi' \
|
| 93 |
'' \
|
| 94 |
-
'
|
| 95 |
-
'' \
|
| 96 |
-
'
|
| 97 |
-
'
|
| 98 |
-
' use_bundled_fallback' \
|
| 99 |
'fi' \
|
| 100 |
'' \
|
| 101 |
-
'echo "[info] Starting app
|
| 102 |
'exec python app.py' \
|
| 103 |
> /usr/local/bin/start.sh \
|
| 104 |
&& chmod +x /usr/local/bin/start.sh
|
| 105 |
|
| 106 |
-
#
|
| 107 |
ENV PORT=7860 \
|
| 108 |
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 109 |
GRADIO_SERVER_PORT=7860 \
|
|
|
|
| 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 \
|
| 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 |
&& 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 that downloads your PRIVATE GitHub repo and runs app.py --------
|
|
|
|
|
|
|
|
|
|
| 35 |
# Expects Space settings:
|
| 36 |
+
# Secret: GIT_TOKEN (GitHub PAT with repo read access)
|
| 37 |
+
# Variable: GIT_REPO (e.g. chaous/render)
|
| 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' \
|
| 43 |
'' \
|
| 44 |
'export BLENDER_BIN="${BLENDER_BIN:-blender}"' \
|
|
|
|
| 45 |
'TARGET_ROOT="/srv/app"' \
|
|
|
|
|
|
|
| 46 |
'REPO="${GIT_REPO:-}"' \
|
| 47 |
'REF="${GIT_REF:-main}"' \
|
| 48 |
'SUBDIR="${GIT_SUBDIR:-}"' \
|
| 49 |
'' \
|
| 50 |
+
'if [[ -z "${REPO}" || -z "${GIT_TOKEN:-}" ]]; then' \
|
| 51 |
+
' echo "[error] GIT_REPO and GIT_TOKEN must be set in Space settings." >&2' \
|
| 52 |
+
' exit 1' \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
'fi' \
|
| 54 |
'' \
|
| 55 |
+
'echo "[info] Fetching ${REPO}@${REF}..."' \
|
| 56 |
'ARCHIVE_URL="https://api.github.com/repos/${REPO}/tarball/${REF}"' \
|
| 57 |
+
'wget -q --header="Authorization: Bearer ${GIT_TOKEN}" -O /tmp/repo.tar.gz "${ARCHIVE_URL}"' \
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
'' \
|
| 59 |
'rm -rf "${TARGET_ROOT:?}/"*' \
|
| 60 |
'tar -xzf /tmp/repo.tar.gz -C "${TARGET_ROOT}" --strip-components=1' \
|
|
|
|
| 62 |
'' \
|
| 63 |
'if [[ -n "${SUBDIR}" ]]; then' \
|
| 64 |
' if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \
|
| 65 |
+
' cd "${TARGET_ROOT}/${SUBDIR}"' \
|
| 66 |
' else' \
|
| 67 |
+
' echo "[warn] GIT_SUBDIR=${SUBDIR} not found; using repo root."' \
|
| 68 |
+
' cd "${TARGET_ROOT}"' \
|
| 69 |
' fi' \
|
| 70 |
+
'else' \
|
| 71 |
+
' cd "${TARGET_ROOT}"' \
|
| 72 |
'fi' \
|
| 73 |
'' \
|
| 74 |
+
'if [[ -f requirements.txt ]]; then' \
|
| 75 |
' echo "[info] Installing repo requirements..."' \
|
| 76 |
+
' pip install --no-cache-dir -r requirements.txt' \
|
| 77 |
'fi' \
|
| 78 |
'' \
|
| 79 |
+
'if [[ ! -f app.py ]]; then' \
|
| 80 |
+
' echo "[error] app.py not found in repo path." >&2' \
|
| 81 |
+
' ls -la' \
|
| 82 |
+
' exit 1' \
|
|
|
|
| 83 |
'fi' \
|
| 84 |
'' \
|
| 85 |
+
'echo "[info] Starting app.py..."' \
|
| 86 |
'exec python app.py' \
|
| 87 |
> /usr/local/bin/start.sh \
|
| 88 |
&& chmod +x /usr/local/bin/start.sh
|
| 89 |
|
| 90 |
+
# -------- HF Space runtime env --------
|
| 91 |
ENV PORT=7860 \
|
| 92 |
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 93 |
GRADIO_SERVER_PORT=7860 \
|