tommytracx commited on
Commit
e31322d
·
verified ·
1 Parent(s): 5cd2388

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -30
Dockerfile CHANGED
@@ -1,13 +1,20 @@
1
  # Dockerfile
2
- FROM python:3.11-slim AS builder
3
 
4
- # Set environment variables for Python optimization
5
  ENV PYTHONUNBUFFERED=1 \
6
  PYTHONDONTWRITEBYTECODE=1 \
7
- OLLAMA_MODELS=/home/ollama/.ollama \
8
- OLLAMA_HOST=0.0.0.0
 
 
 
 
 
9
 
10
- # Install build dependencies
 
 
11
  RUN apt-get update && \
12
  apt-get install -y --no-install-recommends \
13
  curl \
@@ -16,31 +23,14 @@ RUN apt-get update && \
16
  rm -rf /var/lib/apt/lists/*
17
 
18
  # Install Ollama
19
- RUN curl -fsSL https://ollama.ai/install.sh | sh
20
-
21
- # Final stage
22
- FROM python:3.11-slim
23
-
24
- # Create a non-root user
25
- RUN useradd -m -u 1000 ollama && \
26
- mkdir -p /home/ollama/.ollama && \
27
- chown -R ollama:ollama /home/ollama
28
-
29
- WORKDIR /app
30
-
31
- # Create logs directory
32
- RUN mkdir -p /app/logs && \
33
- chown -R ollama:ollama /app/logs
34
-
35
- # Copy Ollama binaries from builder stage
36
- COPY --from=builder /usr/local/bin/ollama /usr/local/bin/ollama
37
 
38
  # Copy requirements and install Python dependencies
39
  COPY requirements.txt .
40
  RUN pip install --no-cache-dir -r requirements.txt
41
 
42
  # Copy application code
43
- COPY . .
44
 
45
  # Set proper ownership and permissions
46
  RUN chown -R ollama:ollama /app && \
@@ -49,15 +39,15 @@ RUN chown -R ollama:ollama /app && \
49
  # Switch to ollama user
50
  USER ollama
51
 
52
- # Create a startup script with configurable model pulling and enhanced logging
53
  RUN echo '#!/bin/bash\n\
54
  set -e\n\
55
- LOG_FILE=/app/logs/startup.log\n\
56
- mkdir -p /app/logs\n\
57
  echo "Starting Ollama server at $(date)" >> $LOG_FILE\n\
58
  ollama serve >> $LOG_FILE 2>&1 &\n\
59
  sleep 15\n\
60
- MODELS_TO_PULL="${MODELS_TO_PULL:-hf.co/gguf-org/gemma-3-270m-gguf:Q5_K_S}"\n\
61
  echo "Pulling models: $MODELS_TO_PULL" | tee -a $LOG_FILE\n\
62
  IFS=',' read -ra MODEL_ARRAY <<< "$MODELS_TO_PULL"\n\
63
  for model in "${MODEL_ARRAY[@]}"; do\n\
@@ -77,13 +67,13 @@ for model in "${MODEL_ARRAY[@]}"; do\n\
77
  done\n\
78
  done\n\
79
  echo "Starting Gunicorn server at $(date)" | tee -a $LOG_FILE\n\
80
- exec python3 -m gunicorn --bind 0.0.0.0:7860 --workers 1 --timeout 120 --log-level info app:app >> $LOG_FILE 2>&1' > /app/start.sh && \
81
  chmod +x /app/start.sh
82
 
83
  # Expose port
84
  EXPOSE 7860
85
 
86
- # Health check with optimized parameters
87
  HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
88
  CMD curl -f http://localhost:7860/health || exit 1
89
 
 
1
  # Dockerfile
2
+ FROM python:3.11-slim
3
 
4
+ # Set environment variables for Python optimization and Ollama
5
  ENV PYTHONUNBUFFERED=1 \
6
  PYTHONDONTWRITEBYTECODE=1 \
7
+ OLLAMA_HOST=0.0.0.0 \
8
+ OLLAMA_MODELS=/data/ollama
9
+
10
+ # Create a non-root user
11
+ RUN useradd -m -u 1000 ollama && \
12
+ mkdir -p /data/ollama && \
13
+ chown -R ollama:ollama /data
14
 
15
+ WORKDIR /app
16
+
17
+ # Install system dependencies
18
  RUN apt-get update && \
19
  apt-get install -y --no-install-recommends \
20
  curl \
 
23
  rm -rf /var/lib/apt/lists/*
24
 
25
  # Install Ollama
26
+ RUN curl -fsSL https://ollama.com/install.sh | sh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  # Copy requirements and install Python dependencies
29
  COPY requirements.txt .
30
  RUN pip install --no-cache-dir -r requirements.txt
31
 
32
  # Copy application code
33
+ COPY app.py .
34
 
35
  # Set proper ownership and permissions
36
  RUN chown -R ollama:ollama /app && \
 
39
  # Switch to ollama user
40
  USER ollama
41
 
42
+ # Create a startup script with configurable model pulling and logging
43
  RUN echo '#!/bin/bash\n\
44
  set -e\n\
45
+ LOG_FILE=/data/startup.log\n\
46
+ mkdir -p /data && touch $LOG_FILE && chmod 644 $LOG_FILE\n\
47
  echo "Starting Ollama server at $(date)" >> $LOG_FILE\n\
48
  ollama serve >> $LOG_FILE 2>&1 &\n\
49
  sleep 15\n\
50
+ MODELS_TO_PULL="${MODELS_TO_PULL:-gemma-3-270m}"\n\
51
  echo "Pulling models: $MODELS_TO_PULL" | tee -a $LOG_FILE\n\
52
  IFS=',' read -ra MODEL_ARRAY <<< "$MODELS_TO_PULL"\n\
53
  for model in "${MODEL_ARRAY[@]}"; do\n\
 
67
  done\n\
68
  done\n\
69
  echo "Starting Gunicorn server at $(date)" | tee -a $LOG_FILE\n\
70
+ exec gunicorn --bind 0.0.0.0:7860 --workers 1 --timeout 120 --log-level info app:app >> $LOG_FILE 2>&1' > /app/start.sh && \
71
  chmod +x /app/start.sh
72
 
73
  # Expose port
74
  EXPOSE 7860
75
 
76
+ # Health check
77
  HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
78
  CMD curl -f http://localhost:7860/health || exit 1
79