Update Dockerfile
Browse files- Dockerfile +41 -42
Dockerfile
CHANGED
|
@@ -1,65 +1,64 @@
|
|
| 1 |
-
FROM python:3.11-slim
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
RUN apt-get update && apt-get install -y \
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
RUN useradd -m -u 1000 user
|
| 10 |
-
|
| 11 |
WORKDIR /app
|
| 12 |
-
|
| 13 |
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
| 14 |
ENV GRADIO_SERVER_PORT="7860"
|
| 15 |
ENV LLAMA_SERVER_URL="http://127.0.0.1:8080"
|
| 16 |
-
|
| 17 |
-
# ──
|
| 18 |
RUN wget -q --show-progress \
|
| 19 |
"https://huggingface.co/unsloth/Qwen2.5-Coder-0.5B-Instruct-128K-GGUF/resolve/main/Qwen2.5-Coder-0.5B-Instruct-F16.gguf" \
|
| 20 |
-O /app/model.gguf && \
|
| 21 |
-
echo "✅ Model
|
| 22 |
-
|
| 23 |
-
# ──
|
| 24 |
-
RUN wget -q --show-progress \
|
| 25 |
-
"https://github.com/ggerganov/llama.cpp/releases/download/b4786/llama-b4786-bin-ubuntu-x64.zip" \
|
| 26 |
-
-O /tmp/llama.zip && \
|
| 27 |
-
unzip /tmp/llama.zip -d /tmp/llama_bin && \
|
| 28 |
-
find /tmp/llama_bin -name "llama-server" -exec cp {} /usr/local/bin/llama-server \; && \
|
| 29 |
-
chmod +x /usr/local/bin/llama-server && \
|
| 30 |
-
rm -rf /tmp/llama.zip /tmp/llama_bin && \
|
| 31 |
-
echo "✅ llama-server: $(llama-server --version 2>&1 | head -1)"
|
| 32 |
-
|
| 33 |
-
# ── 3. Python deps ──────────────────────────────────────────────────────────
|
| 34 |
COPY requirements.txt .
|
| 35 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 36 |
pip install --no-cache-dir -r requirements.txt
|
| 37 |
-
|
| 38 |
-
# ──
|
| 39 |
COPY --chown=user:user . /app
|
| 40 |
-
|
| 41 |
-
# ──
|
| 42 |
-
RUN
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
--
|
| 47 |
-
--
|
| 48 |
-
--
|
| 49 |
-
--
|
| 50 |
-
--
|
|
|
|
| 51 |
&\n\
|
| 52 |
-
|
| 53 |
-
echo "[startup] Waiting for llama-server..."\n\
|
| 54 |
for i in $(seq 1 30); do\n\
|
| 55 |
-
curl -sf http://127.0.0.1:8080/health && break\n\
|
| 56 |
sleep 2\n\
|
| 57 |
done\n\
|
| 58 |
-
echo "[startup]
|
| 59 |
exec python app.py\n\
|
| 60 |
' > /app/start.sh && chmod +x /app/start.sh
|
| 61 |
-
|
| 62 |
USER user
|
| 63 |
EXPOSE 7860
|
| 64 |
-
|
| 65 |
CMD ["/app/start.sh"]
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
# ── Stage 1: copy llama-server out of the official pre-built image ────────────
|
| 3 |
+
FROM ghcr.io/ggml-org/llama.cpp:server AS llamacpp
|
| 4 |
+
|
| 5 |
+
# ── Stage 2: the actual app ───────────────────────────────────────────────────
|
| 6 |
+
FROM python:3.11-slim
|
| 7 |
+
|
| 8 |
+
# libgomp1 is required by llama-server (OpenMP runtime)
|
| 9 |
RUN apt-get update && apt-get install -y \
|
| 10 |
+
ffmpeg wget curl libgomp1 \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
# Copy the pre-built llama-server binary from stage 1
|
| 14 |
+
COPY --from=llamacpp /llama-server /usr/local/bin/llama-server
|
| 15 |
+
RUN chmod +x /usr/local/bin/llama-server && \
|
| 16 |
+
llama-server --version 2>&1 | head -1 && \
|
| 17 |
+
echo "✅ llama-server ready"
|
| 18 |
+
|
| 19 |
RUN useradd -m -u 1000 user
|
|
|
|
| 20 |
WORKDIR /app
|
| 21 |
+
|
| 22 |
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
| 23 |
ENV GRADIO_SERVER_PORT="7860"
|
| 24 |
ENV LLAMA_SERVER_URL="http://127.0.0.1:8080"
|
| 25 |
+
|
| 26 |
+
# ── Download GGUF model at build time ─────────────────────────────────────────
|
| 27 |
RUN wget -q --show-progress \
|
| 28 |
"https://huggingface.co/unsloth/Qwen2.5-Coder-0.5B-Instruct-128K-GGUF/resolve/main/Qwen2.5-Coder-0.5B-Instruct-F16.gguf" \
|
| 29 |
-O /app/model.gguf && \
|
| 30 |
+
echo "✅ Model: $(du -sh /app/model.gguf)"
|
| 31 |
+
|
| 32 |
+
# ── Python dependencies ───────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
COPY requirements.txt .
|
| 34 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 35 |
pip install --no-cache-dir -r requirements.txt
|
| 36 |
+
|
| 37 |
+
# ── App code ──────────────────────────────────────────────────────────────────
|
| 38 |
COPY --chown=user:user . /app
|
| 39 |
+
|
| 40 |
+
# ── Startup script: launch llama-server then Gradio ──────────────────────────
|
| 41 |
+
RUN printf '#!/bin/bash\n\
|
| 42 |
+
set -e\n\
|
| 43 |
+
echo "[startup] Starting llama-server..."\n\
|
| 44 |
+
llama-server \\\n\
|
| 45 |
+
--model /app/model.gguf \\\n\
|
| 46 |
+
--host 127.0.0.1 \\\n\
|
| 47 |
+
--port 8080 \\\n\
|
| 48 |
+
--ctx-size 512 \\\n\
|
| 49 |
+
--threads 2 \\\n\
|
| 50 |
+
--no-mmap \\\n\
|
| 51 |
&\n\
|
| 52 |
+
echo "[startup] Waiting for llama-server to be ready..."\n\
|
|
|
|
| 53 |
for i in $(seq 1 30); do\n\
|
| 54 |
+
curl -sf http://127.0.0.1:8080/health && echo "" && break || true\n\
|
| 55 |
sleep 2\n\
|
| 56 |
done\n\
|
| 57 |
+
echo "[startup] Launching Gradio app"\n\
|
| 58 |
exec python app.py\n\
|
| 59 |
' > /app/start.sh && chmod +x /app/start.sh
|
| 60 |
+
|
| 61 |
USER user
|
| 62 |
EXPOSE 7860
|
| 63 |
+
|
| 64 |
CMD ["/app/start.sh"]
|