Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +30 -22
Dockerfile
CHANGED
@@ -1,32 +1,40 @@
|
|
1 |
-
# Use
|
2 |
-
FROM
|
3 |
|
4 |
# Set environment variables to prevent interactive prompts during apt operations
|
5 |
ENV DEBIAN_FRONTEND=noninteractive
|
6 |
|
7 |
-
# Install system dependencies:
|
8 |
-
RUN apt update && apt install -y
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
# Set the working directory inside the container
|
15 |
-
WORKDIR /app
|
16 |
-
|
17 |
-
# Define
|
18 |
-
|
19 |
-
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
COPY app.py .
|
31 |
COPY requirements.txt .
|
32 |
COPY run.sh .
|
|
|
1 |
+
# Use the official Ollama base image, which already includes Ollama
|
2 |
+
FROM ollama/ollama:latest
|
3 |
|
4 |
# Set environment variables to prevent interactive prompts during apt operations
|
5 |
ENV DEBIAN_FRONTEND=noninteractive
|
6 |
|
7 |
+
# Install system dependencies: git (optional), python3 and pip for the application
|
8 |
+
RUN apt update && apt install -y git python3 python3-pip
|
9 |
|
10 |
+
# Set up a non-root user as recommended for Hugging Face Spaces
|
11 |
+
RUN useradd -m -u 1000 user
|
12 |
+
USER user
|
13 |
+
ENV HOME=/home/user \
|
14 |
+
PATH=/home/user/.local/bin:$PATH \
|
15 |
+
OLLAMA_HOST=0.0.0.0 # Allow Ollama to be accessed from outside localhost
|
16 |
|
17 |
# Set the working directory inside the container
|
18 |
+
WORKDIR $HOME/app
|
19 |
+
|
20 |
+
# Define the model to be pulled
|
21 |
+
ENV OLLAMA_HF_MODEL="hf.co/unsloth/gemma-3-4b-it-qat-GGUF:Q4_K_M"
|
22 |
+
|
23 |
+
# Pull the model during the build process
|
24 |
+
# Start ollama serve in background, wait for it, pull the model, then kill ollama.
|
25 |
+
# This ensures the model is downloaded and cached within the image.
|
26 |
+
RUN ollama serve & \
|
27 |
+
echo "Waiting for Ollama to start for model pull..." && \
|
28 |
+
sleep 5 && \
|
29 |
+
while ! curl -s http://localhost:11434 > /dev/null; do \
|
30 |
+
sleep 1; \
|
31 |
+
done && \
|
32 |
+
echo "Ollama started. Pulling model: ${OLLAMA_HF_MODEL}" && \
|
33 |
+
ollama pull ${OLLAMA_HF_MODEL} && \
|
34 |
+
echo "Model pull complete. Stopping Ollama for build process." && \
|
35 |
+
pkill ollama || true # '|| true' to prevent build failure if pkill returns non-zero when ollama already stopped
|
36 |
+
|
37 |
+
# Copy the application files
|
38 |
COPY app.py .
|
39 |
COPY requirements.txt .
|
40 |
COPY run.sh .
|