Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +19 -15
Dockerfile
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
# -------- Base Python with libs Blender needs (CPU headless) --------
|
| 2 |
FROM python:3.11-slim-bookworm
|
| 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 \
|
|
@@ -9,7 +12,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 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 && \
|
|
@@ -28,8 +32,8 @@ RUN wget -q https://download.blender.org/release/Blender${BLENDER_MAJOR}/blender
|
|
| 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 |
-
#
|
| 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")
|
|
@@ -41,6 +45,7 @@ RUN printf '%s\n' \
|
|
| 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:-}"' \
|
|
@@ -56,25 +61,19 @@ RUN printf '%s\n' \
|
|
| 56 |
' BASE_URL="https://github.com/${REPO}.git"' \
|
| 57 |
'fi' \
|
| 58 |
'' \
|
| 59 |
-
'# Build auth URL (token in URL
|
| 60 |
'if [[ "${BASE_URL}" == https://github.com/* ]]; then' \
|
| 61 |
' AUTH_URL="${BASE_URL/https:\/\//https:\/\/x-access-token:${GIT_TOKEN}@}"' \
|
| 62 |
' SAN_URL="${BASE_URL}"' \
|
| 63 |
'else' \
|
| 64 |
-
' # Non-GitHub host: fall back to header-based clone' \
|
| 65 |
' AUTH_URL="${BASE_URL}"' \
|
| 66 |
' SAN_URL="${BASE_URL}"' \
|
| 67 |
'fi' \
|
| 68 |
'' \
|
| 69 |
'echo "[info] Cloning ${SAN_URL}@${REF} into ${TARGET_ROOT}..."' \
|
| 70 |
-
'rm -rf "${TARGET_ROOT}"' \
|
| 71 |
'mkdir -p "${TARGET_ROOT}"' \
|
| 72 |
-
'' \
|
| 73 |
-
'if [[ "${BASE_URL}" == https://github.com/* ]]; then' \
|
| 74 |
-
' git clone --depth 1 --branch "${REF}" "${AUTH_URL}" "${TARGET_ROOT}"' \
|
| 75 |
-
'else' \
|
| 76 |
-
' git -c http.extraHeader="Authorization: Bearer ${GIT_TOKEN}" clone --depth 1 --branch "${REF}" "${AUTH_URL}" "${TARGET_ROOT}"' \
|
| 77 |
-
'fi' \
|
| 78 |
'' \
|
| 79 |
'if [[ -n "${SUBDIR}" ]]; then' \
|
| 80 |
' if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \
|
|
@@ -87,9 +86,14 @@ RUN printf '%s\n' \
|
|
| 87 |
' cd "${TARGET_ROOT}"' \
|
| 88 |
'fi' \
|
| 89 |
'' \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
'if [[ -f requirements.txt ]]; then' \
|
| 91 |
' echo "[info] Installing repo requirements..."' \
|
| 92 |
-
' pip install
|
| 93 |
'fi' \
|
| 94 |
'' \
|
| 95 |
'if [[ ! -f app.py ]]; then' \
|
|
@@ -97,7 +101,7 @@ RUN printf '%s\n' \
|
|
| 97 |
'fi' \
|
| 98 |
'' \
|
| 99 |
'echo "[info] Starting app.py..."' \
|
| 100 |
-
'exec python app.py' \
|
| 101 |
> /usr/local/bin/start.sh \
|
| 102 |
&& chmod +x /usr/local/bin/start.sh
|
| 103 |
|
|
|
|
| 1 |
# -------- Base Python with libs Blender needs (CPU headless) --------
|
| 2 |
FROM python:3.11-slim-bookworm
|
| 3 |
|
| 4 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 5 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 6 |
+
PIP_NO_CACHE_DIR=1 \
|
| 7 |
+
HOME=/home/user
|
| 8 |
|
| 9 |
# System deps for Blender GUI-less rendering + git + shell
|
| 10 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
| 12 |
libglib2.0-0 libx11-6 libxi6 libxxf86vm1 libxrender1 libxfixes3 \
|
| 13 |
libxkbcommon0 libxrandr2 libasound2 libxinerama1 libsm6 libice6 \
|
| 14 |
libgl1 libegl1 libglu1-mesa libdbus-1-3 libxcb1 \
|
| 15 |
+
&& rm -rf /var/lib/apt/lists/* && \
|
| 16 |
+
mkdir -p /home/user && chmod -R 755 /home/user
|
| 17 |
|
| 18 |
# Local copy of model-viewer (avoid external loads at runtime)
|
| 19 |
RUN mkdir -p /app/static && \
|
|
|
|
| 32 |
RUN /opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m ensurepip && \
|
| 33 |
/opt/blender-${BLENDER_VERSION}-linux-x64/${BLENDER_MAJOR}/python/bin/python3.11 -m pip install --no-cache-dir Pillow
|
| 34 |
|
| 35 |
+
# -------- Runtime: fetch private repo, create venv, install, run app.py --------
|
| 36 |
+
# Space settings required:
|
| 37 |
# Secret: GIT_TOKEN (PAT with repo read access)
|
| 38 |
# Variable: GIT_REPO (chaous/render OR https://github.com/chaous/render.git)
|
| 39 |
# Variable: GIT_REF (optional, default "main")
|
|
|
|
| 45 |
'' \
|
| 46 |
'export BLENDER_BIN="${BLENDER_BIN:-blender}"' \
|
| 47 |
'TARGET_ROOT="${TARGET_ROOT:-/tmp/app}"' \
|
| 48 |
+
'VENV_DIR="${VENV_DIR:-/tmp/venv}"' \
|
| 49 |
'REPO="${GIT_REPO:-}"' \
|
| 50 |
'REF="${GIT_REF:-main}"' \
|
| 51 |
'SUBDIR="${GIT_SUBDIR:-}"' \
|
|
|
|
| 61 |
' BASE_URL="https://github.com/${REPO}.git"' \
|
| 62 |
'fi' \
|
| 63 |
'' \
|
| 64 |
+
'# Build auth URL (token in URL prevents interactive prompts). Uses x-access-token as user.' \
|
| 65 |
'if [[ "${BASE_URL}" == https://github.com/* ]]; then' \
|
| 66 |
' AUTH_URL="${BASE_URL/https:\/\//https:\/\/x-access-token:${GIT_TOKEN}@}"' \
|
| 67 |
' SAN_URL="${BASE_URL}"' \
|
| 68 |
'else' \
|
|
|
|
| 69 |
' AUTH_URL="${BASE_URL}"' \
|
| 70 |
' SAN_URL="${BASE_URL}"' \
|
| 71 |
'fi' \
|
| 72 |
'' \
|
| 73 |
'echo "[info] Cloning ${SAN_URL}@${REF} into ${TARGET_ROOT}..."' \
|
| 74 |
+
'rm -rf "${TARGET_ROOT}" "${VENV_DIR}"' \
|
| 75 |
'mkdir -p "${TARGET_ROOT}"' \
|
| 76 |
+
'git clone --depth 1 --branch "${REF}" "${AUTH_URL}" "${TARGET_ROOT}"' \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
'' \
|
| 78 |
'if [[ -n "${SUBDIR}" ]]; then' \
|
| 79 |
' if [[ -d "${TARGET_ROOT}/${SUBDIR}" ]]; then' \
|
|
|
|
| 86 |
' cd "${TARGET_ROOT}"' \
|
| 87 |
'fi' \
|
| 88 |
'' \
|
| 89 |
+
'echo "[info] Creating venv at ${VENV_DIR}..."' \
|
| 90 |
+
'python -m venv "${VENV_DIR}"' \
|
| 91 |
+
'source "${VENV_DIR}/bin/activate"' \
|
| 92 |
+
'python -m pip install --upgrade pip' \
|
| 93 |
+
'' \
|
| 94 |
'if [[ -f requirements.txt ]]; then' \
|
| 95 |
' echo "[info] Installing repo requirements..."' \
|
| 96 |
+
' pip install -r requirements.txt' \
|
| 97 |
'fi' \
|
| 98 |
'' \
|
| 99 |
'if [[ ! -f app.py ]]; then' \
|
|
|
|
| 101 |
'fi' \
|
| 102 |
'' \
|
| 103 |
'echo "[info] Starting app.py..."' \
|
| 104 |
+
'exec "${VENV_DIR}/bin/python" app.py' \
|
| 105 |
> /usr/local/bin/start.sh \
|
| 106 |
&& chmod +x /usr/local/bin/start.sh
|
| 107 |
|