Skip to content

Commit e442ea8

Browse files
Add ollama-init service for auto model pull in docker compose
New ollama-init service pulls nomic-embed-text and qwen2.5-coder:1.5b before CodeRAG starts. Fix ollama image tag 0.5 → latest. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent baef4c8 commit e442ea8

2 files changed

Lines changed: 81 additions & 27 deletions

File tree

docker-compose.yml

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,54 @@
99
# ============================================================================
1010

1111
services:
12+
# --------------------------------------------------------------------------
13+
# Ollama — local LLM / embedding model server
14+
# --------------------------------------------------------------------------
15+
ollama:
16+
image: ollama/ollama:latest
17+
container_name: coderag-ollama
18+
ports:
19+
- "11434:11434"
20+
volumes:
21+
- ollama-data:/root/.ollama
22+
# GPU support (uncomment for NVIDIA GPU)
23+
# deploy:
24+
# resources:
25+
# reservations:
26+
# devices:
27+
# - driver: nvidia
28+
# count: all
29+
# capabilities: [gpu]
30+
restart: unless-stopped
31+
networks:
32+
- coderag-net
33+
healthcheck:
34+
test: ["CMD", "ollama", "list"]
35+
interval: 30s
36+
timeout: 10s
37+
retries: 3
38+
39+
# --------------------------------------------------------------------------
40+
# Ollama Init — pull required models before CodeRAG starts
41+
# Uses the same ollama image (has CLI) and shares the model volume.
42+
# --------------------------------------------------------------------------
43+
ollama-init:
44+
image: ollama/ollama:latest
45+
container_name: coderag-ollama-init
46+
volumes:
47+
- ./scripts/ollama-init.sh:/init.sh:ro
48+
entrypoint: ["/bin/sh", "/init.sh"]
49+
environment:
50+
OLLAMA_HOST: http://ollama:11434
51+
CODERAG_EMBEDDING_MODEL: ${CODERAG_EMBEDDING_MODEL:-nomic-embed-text}
52+
CODERAG_ENRICHMENT_MODEL: ${CODERAG_ENRICHMENT_MODEL:-qwen2.5-coder:1.5b}
53+
depends_on:
54+
ollama:
55+
condition: service_healthy
56+
networks:
57+
- coderag-net
58+
restart: "no"
59+
1260
# --------------------------------------------------------------------------
1361
# CodeRAG — MCP server + API server + CLI
1462
# --------------------------------------------------------------------------
@@ -37,6 +85,8 @@ services:
3785
depends_on:
3886
ollama:
3987
condition: service_healthy
88+
ollama-init:
89+
condition: service_completed_successfully
4090
networks:
4191
- coderag-net
4292
healthcheck:
@@ -49,33 +99,6 @@ services:
4999
# Default command: start the API server (override for other commands)
50100
command: ["serve", "--port", "3000"]
51101

52-
# --------------------------------------------------------------------------
53-
# Ollama — local LLM / embedding model server
54-
# --------------------------------------------------------------------------
55-
ollama:
56-
image: ollama/ollama:0.5
57-
container_name: coderag-ollama
58-
ports:
59-
- "11434:11434"
60-
volumes:
61-
- ollama-data:/root/.ollama
62-
# GPU support (uncomment for NVIDIA GPU)
63-
# deploy:
64-
# resources:
65-
# reservations:
66-
# devices:
67-
# - driver: nvidia
68-
# count: all
69-
# capabilities: [gpu]
70-
restart: unless-stopped
71-
networks:
72-
- coderag-net
73-
healthcheck:
74-
test: ["CMD", "ollama", "list"]
75-
interval: 30s
76-
timeout: 10s
77-
retries: 3
78-
79102
# --------------------------------------------------------------------------
80103
# Viewer — CodeRAG visualization SPA (optional profile)
81104
# --------------------------------------------------------------------------

scripts/ollama-init.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
set -e
3+
4+
OLLAMA_HOST="${OLLAMA_HOST:-http://ollama:11434}"
5+
EMBED_MODEL="${CODERAG_EMBEDDING_MODEL:-nomic-embed-text}"
6+
ENRICH_MODEL="${CODERAG_ENRICHMENT_MODEL:-qwen2.5-coder:1.5b}"
7+
8+
echo "=== CodeRAG Ollama Init ==="
9+
echo "Ollama host: $OLLAMA_HOST"
10+
echo "Embedding model: $EMBED_MODEL"
11+
echo "Enrichment model: $ENRICH_MODEL"
12+
echo ""
13+
14+
pull_model() {
15+
local model="$1"
16+
echo "Checking model: $model"
17+
if ollama list 2>/dev/null | grep -q "$model"; then
18+
echo " Already present: $model"
19+
else
20+
echo " Pulling $model (this may take a few minutes)..."
21+
ollama pull "$model"
22+
echo " Done: $model"
23+
fi
24+
}
25+
26+
pull_model "$EMBED_MODEL"
27+
pull_model "$ENRICH_MODEL"
28+
29+
echo ""
30+
echo "All models ready:"
31+
ollama list

0 commit comments

Comments
 (0)