Spaces:
Build error
Build error
Update Dockerfile
Browse files- Dockerfile +60 -25
Dockerfile
CHANGED
|
@@ -1,46 +1,81 @@
|
|
| 1 |
-
|
| 2 |
-
# you will also find guides on how best to write your Dockerfile
|
| 3 |
-
|
| 4 |
-
FROM ubuntu:20.04
|
| 5 |
|
|
|
|
| 6 |
ARG MODEL_DOWNLOAD_LINK
|
| 7 |
ENV MODEL_DOWNLOAD_LINK=${MODEL_DOWNLOAD_LINK:-https://huggingface.co/QuantFactory/MN-Violet-Lotus-12B-GGUF/resolve/main/MN-Violet-Lotus-12B.Q4_K_M.gguf?download=true}
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 10 |
|
|
|
|
| 11 |
RUN useradd -m -u 1000 user
|
| 12 |
-
|
| 13 |
-
ENV PATH="/
|
| 14 |
-
|
| 15 |
-
WORKDIR /app
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
USER root
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
| 24 |
-
RUN apt-get install -y nodejs
|
| 25 |
-
|
| 26 |
USER user
|
| 27 |
|
|
|
|
| 28 |
RUN python3 replace_hw.py
|
| 29 |
-
RUN git clone https://github.com/ggerganov/llama.cpp.git
|
| 30 |
|
| 31 |
-
|
| 32 |
-
RUN git
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
RUN npm run build
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
RUN cmake -
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
CMD ["
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM ubuntu:20.04
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# --- Model URL (Spaces can override this via Build Args) ---
|
| 4 |
ARG MODEL_DOWNLOAD_LINK
|
| 5 |
ENV MODEL_DOWNLOAD_LINK=${MODEL_DOWNLOAD_LINK:-https://huggingface.co/QuantFactory/MN-Violet-Lotus-12B-GGUF/resolve/main/MN-Violet-Lotus-12B.Q4_K_M.gguf?download=true}
|
| 6 |
|
| 7 |
+
# llama.cpp ref:
|
| 8 |
+
# PR #13249 ("move end-user examples to tools directory") was merged as 1d36b367;
|
| 9 |
+
# we pin to its parent so examples/server/* still exists and your patch applies.
|
| 10 |
+
ARG LLAMA_CPP_REF="1d36b367^"
|
| 11 |
+
|
| 12 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 13 |
|
| 14 |
+
# Spaces runs as UID 1000; create it early and set WORKDIR before COPY
|
| 15 |
RUN useradd -m -u 1000 user
|
| 16 |
+
ENV HOME=/home/user
|
| 17 |
+
ENV PATH="$HOME/.local/bin:$PATH"
|
| 18 |
+
WORKDIR $HOME/app
|
|
|
|
| 19 |
|
| 20 |
+
# Copy your repo (must include helloworld.patch and replace_hw.py at repo root)
|
| 21 |
+
COPY --chown=user . $HOME/app
|
| 22 |
|
| 23 |
USER root
|
| 24 |
|
| 25 |
+
# System deps
|
| 26 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 27 |
+
git cmake build-essential g++ \
|
| 28 |
+
wget curl ca-certificates \
|
| 29 |
+
python3 \
|
| 30 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 31 |
+
|
| 32 |
+
# Node (needed for the older examples/server/webui build)
|
| 33 |
+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
| 34 |
+
&& apt-get update && apt-get install -y --no-install-recommends nodejs \
|
| 35 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 36 |
+
|
| 37 |
+
# Prepare /data (mounted at runtime if you enable persistent storage on Spaces)
|
| 38 |
+
RUN mkdir -p /data && chmod 777 /data
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
USER user
|
| 41 |
|
| 42 |
+
# Update your patch/UI text based on MODEL_DOWNLOAD_LINK
|
| 43 |
RUN python3 replace_hw.py
|
|
|
|
| 44 |
|
| 45 |
+
# Clone llama.cpp and pin to a revision compatible with your patch
|
| 46 |
+
RUN git clone https://github.com/ggml-org/llama.cpp.git $HOME/llama.cpp
|
| 47 |
+
WORKDIR $HOME/llama.cpp
|
| 48 |
+
RUN git checkout "${LLAMA_CPP_REF}"
|
| 49 |
+
|
| 50 |
+
# Apply your UI patch (now updated by replace_hw.py)
|
| 51 |
+
RUN git apply $HOME/app/helloworld.patch
|
| 52 |
|
| 53 |
+
# Build the legacy web UI (exists in this pinned revision)
|
| 54 |
+
WORKDIR $HOME/llama.cpp/examples/server/webui
|
| 55 |
+
RUN npm install
|
| 56 |
RUN npm run build
|
| 57 |
|
| 58 |
+
# Build llama-server (CMake)
|
| 59 |
+
WORKDIR $HOME/llama.cpp
|
| 60 |
+
RUN cmake -B build -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release
|
| 61 |
+
RUN cmake --build build --config Release -j $(nproc) -t llama-server
|
| 62 |
|
| 63 |
+
# Spaces default exposed port is 7860 (set app_port in README if you change it)
|
| 64 |
+
EXPOSE 7860
|
| 65 |
|
| 66 |
+
# Download model at runtime into /data and start server
|
| 67 |
+
CMD ["bash", "-lc", "set -euo pipefail; \
|
| 68 |
+
MODEL_FILE=$(python3 -c 'import os,urllib.parse; u=os.environ[\"MODEL_DOWNLOAD_LINK\"]; print(os.path.basename(urllib.parse.urlsplit(u).path))'); \
|
| 69 |
+
MODEL_DIR=/data/models; MODEL_PATH=\"$MODEL_DIR/$MODEL_FILE\"; \
|
| 70 |
+
mkdir -p \"$MODEL_DIR\"; \
|
| 71 |
+
if [ ! -f \"$MODEL_PATH\" ]; then \
|
| 72 |
+
echo \"Downloading model -> $MODEL_PATH\"; \
|
| 73 |
+
wget -nv -O \"$MODEL_PATH\" \"$MODEL_DOWNLOAD_LINK\"; \
|
| 74 |
+
fi; \
|
| 75 |
+
exec \"$HOME/llama.cpp/build/bin/llama-server\" \
|
| 76 |
+
--host 0.0.0.0 --port 7860 \
|
| 77 |
+
-c 2048 \
|
| 78 |
+
-m \"$MODEL_PATH\" \
|
| 79 |
+
--cache-type-k q8_0 \
|
| 80 |
+
--alias \"MN-Violet-Lotus-12B\" \
|
| 81 |
+
"]
|