Spaces:
Running
Running
Hermes Agent commited on
Commit ·
c12e4fd
1
Parent(s): 40bf0bd
3-Stage serialized Docker build: force BuildKit sequential execution to eliminate peak RAM OOMKilled crashes
Browse files- Dockerfile +30 -14
Dockerfile
CHANGED
|
@@ -21,22 +21,40 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 21 |
&& update-ca-certificates --fresh \
|
| 22 |
&& git config --system http.sslCAInfo /etc/ssl/certs/ca-certificates.crt \
|
| 23 |
&& git config --system http.sslVerify true \
|
| 24 |
-
&& git config --system --get http.sslCAInfo \
|
| 25 |
-
&& test -f /etc/ssl/certs/ca-certificates.crt \
|
| 26 |
&& rm -rf /var/lib/apt/lists/*
|
| 27 |
|
| 28 |
COPY fix_omniroute.py /fix_omniroute.py
|
| 29 |
|
| 30 |
-
# Download OmniRoute release/v3.8.50
|
| 31 |
RUN (git clone --depth 1 --branch "${OMNIROUTE_REF}" https://github.com/diegosouzapw/OmniRoute.git /omniroute || \
|
| 32 |
(curl -sSL https://codeload.github.com/diegosouzapw/OmniRoute/tar.gz/refs/heads/${OMNIROUTE_REF} | tar -xz -C /omniroute --strip-components=1)) \
|
| 33 |
&& python3 /fix_omniroute.py /omniroute \
|
| 34 |
&& npm install --legacy-peer-deps --no-audit --no-fund \
|
| 35 |
&& npm rebuild better-sqlite3 --build-from-source \
|
| 36 |
-
&& OMNIROUTE_BASE_PATH="/omniroute" NEXT_PUBLIC_OMNIROUTE_BASE_PATH="/omniroute" NEXT_TELEMETRY_DISABLED=1 OMNIROUTE_USE_TURBOPACK=0 NODE_OPTIONS="--max-old-space-size=4096" npm run build
|
|
|
|
| 37 |
|
| 38 |
# ==============================================================================
|
| 39 |
-
# STAGE 2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# ==============================================================================
|
| 41 |
FROM debian:bookworm-slim
|
| 42 |
|
|
@@ -71,21 +89,19 @@ RUN mkdir -p /etc/apt/keyrings \
|
|
| 71 |
&& apt-get update && apt-get install -y --no-install-recommends jellyfin-server jellyfin-web ffmpeg \
|
| 72 |
&& rm -rf /var/lib/apt/lists/*
|
| 73 |
|
| 74 |
-
# 3. Install
|
| 75 |
-
RUN pip3 install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu --break-system-packages \
|
| 76 |
-
&& pip3 install --no-cache-dir aiohttp pyrogram tgcrypto open-webui httpx uvicorn fastapi sentence-transformers --break-system-packages || true
|
| 77 |
-
|
| 78 |
-
# Pre-cache Open WebUI default embedding model inside Docker image for 1s startup
|
| 79 |
-
RUN python3 -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')" || true
|
| 80 |
-
|
| 81 |
-
# 4. Install Node.js 24 LTS Runtime into final container
|
| 82 |
RUN curl -fsSL https://nodejs.org/dist/v24.1.0/node-v24.1.0-linux-x64.tar.gz 2>/dev/null \
|
| 83 |
|| curl -fsSL https://nodejs.org/dist/v22.22.2/node-v22.22.2-linux-x64.tar.gz \
|
| 84 |
| tar -xz -C /usr/local --strip-components=1
|
| 85 |
|
| 86 |
-
#
|
| 87 |
COPY --from=omniroute-builder /omniroute /omniroute
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
RUN mkdir -p /root/.cache /data/cache /data/omniroute /data/open-webui
|
| 90 |
RUN chmod -R 777 /root/.cache /data/cache /omniroute
|
| 91 |
|
|
|
|
| 21 |
&& update-ca-certificates --fresh \
|
| 22 |
&& git config --system http.sslCAInfo /etc/ssl/certs/ca-certificates.crt \
|
| 23 |
&& git config --system http.sslVerify true \
|
|
|
|
|
|
|
| 24 |
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
|
| 26 |
COPY fix_omniroute.py /fix_omniroute.py
|
| 27 |
|
| 28 |
+
# Download OmniRoute release/v3.8.50, repair migration collisions, install dependencies, rebuild better-sqlite3, and run production build STRICTLY WITHOUT || true
|
| 29 |
RUN (git clone --depth 1 --branch "${OMNIROUTE_REF}" https://github.com/diegosouzapw/OmniRoute.git /omniroute || \
|
| 30 |
(curl -sSL https://codeload.github.com/diegosouzapw/OmniRoute/tar.gz/refs/heads/${OMNIROUTE_REF} | tar -xz -C /omniroute --strip-components=1)) \
|
| 31 |
&& python3 /fix_omniroute.py /omniroute \
|
| 32 |
&& npm install --legacy-peer-deps --no-audit --no-fund \
|
| 33 |
&& npm rebuild better-sqlite3 --build-from-source \
|
| 34 |
+
&& OMNIROUTE_BASE_PATH="/omniroute" NEXT_PUBLIC_OMNIROUTE_BASE_PATH="/omniroute" NEXT_TELEMETRY_DISABLED=1 OMNIROUTE_USE_TURBOPACK=0 NODE_OPTIONS="--max-old-space-size=4096" npm run build \
|
| 35 |
+
&& touch /tmp/omniroute-build-complete
|
| 36 |
|
| 37 |
# ==============================================================================
|
| 38 |
+
# STAGE 2: Serialized Python AI Stack Builder (Executes ONLY after Stage 1 finishes)
|
| 39 |
+
# ==============================================================================
|
| 40 |
+
FROM debian:bookworm-slim AS python-builder
|
| 41 |
+
|
| 42 |
+
# FORCE BuildKit dependency serialization: COPY marker from omniroute-builder
|
| 43 |
+
COPY --from=omniroute-builder /tmp/omniroute-build-complete /tmp/
|
| 44 |
+
|
| 45 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 46 |
+
python3 python3-pip python3-dev build-essential gcc g++ \
|
| 47 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 48 |
+
|
| 49 |
+
# Install PyTorch CPU + Open WebUI + Utilities strictly WITHOUT || true
|
| 50 |
+
RUN pip3 install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu --break-system-packages \
|
| 51 |
+
&& pip3 install --no-cache-dir aiohttp pyrogram tgcrypto open-webui httpx uvicorn fastapi sentence-transformers --break-system-packages
|
| 52 |
+
|
| 53 |
+
# Pre-cache Open WebUI default embedding model inside build container
|
| 54 |
+
RUN python3 -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')"
|
| 55 |
+
|
| 56 |
+
# ==============================================================================
|
| 57 |
+
# STAGE 3: Multi-Service Production Runtime (Debian Bookworm)
|
| 58 |
# ==============================================================================
|
| 59 |
FROM debian:bookworm-slim
|
| 60 |
|
|
|
|
| 89 |
&& apt-get update && apt-get install -y --no-install-recommends jellyfin-server jellyfin-web ffmpeg \
|
| 90 |
&& rm -rf /var/lib/apt/lists/*
|
| 91 |
|
| 92 |
+
# 3. Install Node.js 24 LTS Runtime into final container
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
RUN curl -fsSL https://nodejs.org/dist/v24.1.0/node-v24.1.0-linux-x64.tar.gz 2>/dev/null \
|
| 94 |
|| curl -fsSL https://nodejs.org/dist/v22.22.2/node-v22.22.2-linux-x64.tar.gz \
|
| 95 |
| tar -xz -C /usr/local --strip-components=1
|
| 96 |
|
| 97 |
+
# 4. Copy pre-compiled OmniRoute production runtime from Stage 1
|
| 98 |
COPY --from=omniroute-builder /omniroute /omniroute
|
| 99 |
|
| 100 |
+
# 5. Copy pre-compiled Python packages and HuggingFace cache from Stage 2
|
| 101 |
+
COPY --from=python-builder /usr/local/lib/python3.11/dist-packages /usr/local/lib/python3.11/dist-packages
|
| 102 |
+
COPY --from=python-builder /usr/local/bin /usr/local/bin
|
| 103 |
+
COPY --from=python-builder /root/.cache /root/.cache
|
| 104 |
+
|
| 105 |
RUN mkdir -p /root/.cache /data/cache /data/omniroute /data/open-webui
|
| 106 |
RUN chmod -R 777 /root/.cache /data/cache /omniroute
|
| 107 |
|