SkyNetWalker commited on
Commit
da805c9
·
verified ·
1 Parent(s): fcf6b9b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -22
Dockerfile CHANGED
@@ -1,32 +1,40 @@
1
- # Use a base Ubuntu image
2
- FROM ubuntu:22.04
3
 
4
  # Set environment variables to prevent interactive prompts during apt operations
5
  ENV DEBIAN_FRONTEND=noninteractive
6
 
7
- # Install system dependencies: curl for Ollama, wget for model download, git (optional, but good for debugging), python3 and pip for the application
8
- RUN apt update && apt install -y curl wget git python3 python3-pip
9
 
10
- # Install Ollama using its official installation script
11
- # This script automatically detects the system architecture and installs the correct binary.
12
- RUN curl -fsSL https://ollama.com/install.sh | sh
 
 
 
13
 
14
  # Set the working directory inside the container
15
- WORKDIR /app
16
-
17
- # Define environment variables for the model repository and filename
18
- # This makes it easy to change the model later without editing the RUN command directly.
19
- ENV MODEL_REPO="unsloth/gemma-3-4b-it-GGUF"
20
- # CORRECTED FILENAME: Removed '-qat'
21
- ENV MODEL_FILENAME="gemma-3-4b-it.Q4_K_M.gguf"
22
-
23
- # Download the specific GGUF model file directly from Hugging Face Hub.
24
- # We use 'wget -O' to save the file with the desired filename in the current directory.
25
- # The 'resolve/main' path ensures we get the raw file content.
26
- RUN wget -O ${MODEL_FILENAME} https://huggingface.co/${MODEL_REPO}/resolve/main/${MODEL_FILENAME}
27
-
28
- # Copy the Modelfile, application script, Python requirements, and the startup script into the container
29
- COPY Modelfile .
 
 
 
 
 
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 .