@@ -21,35 +21,35 @@ services:
2121 - APP_NAME=${APP_NAME:-AI Portfolio Backend}
2222 - APP_VERSION=${APP_VERSION:-1.0.0}
2323 - DEBUG=${DEBUG:-false}
24-
24+
2525 # Server Settings
2626 - HOST=0.0.0.0
2727 - PORT=8000
28-
28+
2929 # CORS Settings (comma-separated)
3030 - CORS_ORIGINS=${CORS_ORIGINS:-http://localhost:3000,http://localhost:3001}
31-
31+
3232 # Ollama LLM Settings
3333 - OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://ollama:11434}
3434 - OLLAMA_MODEL=${OLLAMA_MODEL:-llama3.2:3b}
35-
35+
3636 # ChromaDB Settings
3737 - CHROMA_PERSIST_DIR=/app/data/chroma_db
3838 - CHROMA_COLLECTION_NAME=${CHROMA_COLLECTION_NAME:-portfolio_docs}
39-
39+
4040 # Document Processing
4141 - UPLOAD_DIR=/app/data/documents
4242 - MAX_FILE_SIZE_MB=${MAX_FILE_SIZE_MB:-10}
4343 - ALLOWED_EXTENSIONS=${ALLOWED_EXTENSIONS:-.pdf,.md,.txt,.docx}
44-
44+
4545 # RAG Settings
4646 - CHUNK_SIZE=${CHUNK_SIZE:-500}
4747 - CHUNK_OVERLAP=${CHUNK_OVERLAP:-50}
4848 - TOP_K_RESULTS=${TOP_K_RESULTS:-3}
49-
50- # Embedding Model
51- - EMBEDDING_MODEL=${EMBEDDING_MODEL:-all-MiniLM-L6-v2 }
52-
49+
50+ # Embedding Model (Ollama embedding model)
51+ - EMBEDDING_MODEL=${EMBEDDING_MODEL:-nomic-embed-text }
52+
5353 # Security (REQUIRED - set in .env file)
5454 - ADMIN_API_KEY=${ADMIN_API_KEY}
5555 volumes :
@@ -62,13 +62,14 @@ services:
6262 networks :
6363 - portfolio-network
6464 depends_on :
65- - ollama
65+ ollama-init :
66+ condition : service_completed_successfully
6667 healthcheck :
6768 test : ["CMD", "curl", "-f", "http://localhost:8000/health"]
6869 interval : 30s
6970 timeout : 10s
7071 retries : 3
71- start_period : 40s
72+ start_period : 10s
7273
7374 # ===========================================================================
7475 # Frontend Service (Next.js)
@@ -113,11 +114,11 @@ services:
113114 networks :
114115 - portfolio-network
115116 healthcheck :
116- test : ["CMD", "curl", "-f", "http://localhost:11434/api/tags "]
117+ test : ["CMD-SHELL ", "ollama list || exit 1 "]
117118 interval : 30s
118119 timeout : 10s
119120 retries : 3
120- start_period : 60s
121+ start_period : 30s
121122 # Optional: Set resource limits
122123 deploy :
123124 resources :
@@ -126,6 +127,62 @@ services:
126127 reservations :
127128 memory : 4G
128129
130+ # ===========================================================================
131+ # Ollama Model Initialization (Pulls required models)
132+ # ===========================================================================
133+ # This init container ensures all required Ollama models are pulled before
134+ # the backend starts. It runs once and exits successfully.
135+ # ===========================================================================
136+ ollama-init :
137+ image : curlimages/curl:latest
138+ container_name : portfolio-ollama-init
139+ depends_on :
140+ ollama :
141+ condition : service_healthy
142+ networks :
143+ - portfolio-network
144+ environment :
145+ - OLLAMA_HOST=ollama:11434
146+ - LLM_MODEL=${OLLAMA_MODEL:-llama3.2:3b}
147+ - EMBEDDING_MODEL=${EMBEDDING_MODEL:-nomic-embed-text}
148+ entrypoint : ["/bin/sh", "-c"]
149+ command :
150+ - |
151+ echo "=== Ollama Model Initialization ==="
152+ echo "Waiting for Ollama to be ready..."
153+
154+ # Wait for Ollama API
155+ until curl -sf http://$$OLLAMA_HOST/api/tags > /dev/null 2>&1; do
156+ echo "Waiting for Ollama..."
157+ sleep 2
158+ done
159+ echo "Ollama is ready!"
160+
161+ # Function to pull model if not exists
162+ pull_model() {
163+ MODEL=$$1
164+ echo "Checking model: $$MODEL"
165+
166+ # Check if model exists
167+ if curl -sf http://$$OLLAMA_HOST/api/tags | grep -q "\"name\":\"$$MODEL\""; then
168+ echo "Model $$MODEL already exists, skipping pull"
169+ else
170+ echo "Pulling model: $$MODEL (this may take a while)..."
171+ curl -X POST http://$$OLLAMA_HOST/api/pull -d "{\"name\": \"$$MODEL\"}" --no-buffer
172+ echo ""
173+ echo "Model $$MODEL pulled successfully!"
174+ fi
175+ }
176+
177+ # Pull LLM model
178+ pull_model "$$LLM_MODEL"
179+
180+ # Pull embedding model
181+ pull_model "$$EMBEDDING_MODEL"
182+
183+ echo "=== All models ready! ==="
184+ restart : " no"
185+
129186# =============================================================================
130187# Volumes (Data Persistence)
131188# =============================================================================
@@ -145,4 +202,3 @@ volumes:
145202networks :
146203 portfolio-network :
147204 driver : bridge
148-
0 commit comments