gcharanteja commited on
Commit
2bfce12
Β·
1 Parent(s): d9b4eb6

Refactor Dockerfile and start.sh for improved clarity and functionality

Browse files
Files changed (2) hide show
  1. Dockerfile +7 -6
  2. start.sh +16 -11
Dockerfile CHANGED
@@ -1,20 +1,18 @@
1
  FROM ollama/ollama:latest
2
 
3
- # Install Python and dependencies
4
  RUN apt-get update && apt-get install -y \
5
  python3 \
6
  python3-pip \
7
- python3-venv \
8
- curl \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
  WORKDIR /app
12
 
13
- # Create virtual environment (safer)
14
  RUN python3 -m venv /opt/venv
15
  ENV PATH="/opt/venv/bin:$PATH"
16
 
17
- # Copy requirements and install
18
  COPY requirements.txt .
19
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
20
 
@@ -26,5 +24,8 @@ RUN chmod +x start.sh
26
 
27
  EXPOSE 7860
28
 
29
- # Use our start script
 
 
 
30
  CMD ["./start.sh"]
 
1
  FROM ollama/ollama:latest
2
 
3
+ # Install Python + pip
4
  RUN apt-get update && apt-get install -y \
5
  python3 \
6
  python3-pip \
 
 
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
  WORKDIR /app
10
 
11
+ # Setup Python environment
12
  RUN python3 -m venv /opt/venv
13
  ENV PATH="/opt/venv/bin:$PATH"
14
 
15
+ # Copy and install requirements
16
  COPY requirements.txt .
17
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
18
 
 
24
 
25
  EXPOSE 7860
26
 
27
+ # IMPORTANT: Override Ollama's default entrypoint
28
+ ENTRYPOINT []
29
+
30
+ # Run our start script
31
  CMD ["./start.sh"]
start.sh CHANGED
@@ -1,29 +1,34 @@
1
  #!/bin/bash
2
 
3
  echo "=== [HF Space] Starting Ollama + FastAPI ==="
 
4
 
5
- # Start Ollama in background (official image already has it)
6
- echo "Starting Ollama server..."
 
 
7
  ollama serve &
8
- sleep 5
9
 
10
- # Wait for Ollama
11
- echo "Waiting for Ollama..."
12
- for i in {1..40}; do
13
- if curl -s http://127.0.0.1:11434/api/tags >/dev/null; then
14
- echo "βœ… Ollama ready!"
15
  break
16
  fi
17
  sleep 3
 
 
 
18
  done
19
 
20
  # Pull model (only first time)
21
  if ! ollama list | grep -q "tinyllama"; then
22
- echo "πŸ“₯ Pulling tinyllama... (this can take 2-5 mins on first build)"
23
  ollama pull tinyllama
24
  else
25
- echo "βœ… tinyllama already available"
26
  fi
27
 
28
- echo "πŸš€ Starting FastAPI..."
29
  uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860} --workers 2
 
1
  #!/bin/bash
2
 
3
  echo "=== [HF Space] Starting Ollama + FastAPI ==="
4
+ echo "Time: $(date)"
5
 
6
+ export OLLAMA_HOST=0.0.0.0
7
+ export OMP_NUM_THREADS=4
8
+
9
+ echo "Starting Ollama server in background..."
10
  ollama serve &
11
+ OLLAMA_PID=$!
12
 
13
+ echo "Waiting for Ollama to be ready..."
14
+ for i in {1..60}; do
15
+ if curl -s http://127.0.0.1:11434/api/tags >/dev/null 2>&1; then
16
+ echo "βœ… Ollama is ready!"
 
17
  break
18
  fi
19
  sleep 3
20
+ if [ $i -eq 20 ]; then
21
+ echo "Still waiting for Ollama..."
22
+ fi
23
  done
24
 
25
  # Pull model (only first time)
26
  if ! ollama list | grep -q "tinyllama"; then
27
+ echo "πŸ“₯ Downloading tinyllama model... (this may take 3-8 minutes)"
28
  ollama pull tinyllama
29
  else
30
+ echo "βœ… tinyllama model already downloaded"
31
  fi
32
 
33
+ echo "πŸš€ Starting FastAPI server on port ${PORT:-7860}..."
34
  uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860} --workers 2