Skip to content

Commit 36e5fb7

Browse files
committed
feat: llm container wait for indexer healthcheck
1 parent 2eced12 commit 36e5fb7

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

docker-compose-ollama.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,19 @@ services:
4646
- ${LOCAL_FILES_PATH}:/usr/src/app/local_files/
4747
- ./indexer:/usr/src/app
4848
ports:
49-
- 8001:8000
49+
- 8001:8001
5050
environment:
5151
- PYTHONPATH=/usr/src
5252
- PYTHONUNBUFFERED=TRUE
5353
- LOCAL_FILES_PATH=${LOCAL_FILES_PATH}
5454
- EMBEDDING_MODEL_ID=${EMBEDDING_MODEL_ID}
5555
- EMBEDDING_SIZE=${EMBEDDING_SIZE}
5656
- START_INDEXING=${START_INDEXING}
57+
healthcheck:
58+
test: ["CMD", "curl", "-f", "http://localhost:8001/health"]
59+
interval: 10s
60+
timeout: 5s
61+
retries: 3
5762
depends_on:
5863
- qdrant
5964

@@ -66,7 +71,7 @@ services:
6671
volumes:
6772
- ./llm:/usr/src/app
6873
ports:
69-
- 8003:8000
74+
- 8003:8003
7075
environment:
7176
- PYTHONPATH=/usr/src
7277
- PYTHONUNBUFFERED=TRUE
@@ -76,6 +81,7 @@ services:
7681
- ollama
7782
- qdrant
7883
- indexer
84+
entrypoint: ["./wait-for-it.sh", "http://indexer:8001/health", "60", "--", "python", "app.py"]
7985

8086
chat:
8187
build: ./chat

indexer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ COPY . .
1616
ENV START_INDEXING=${START_INDEXING}
1717
RUN echo "START_INDEXING is $START_INDEXING"
1818

19-
ENV PORT 8000
19+
ENV PORT 8001
2020
ENV CURRENT_HOST 0.0.0.0
2121
ENV WORKERS 1
2222

indexer/app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pydantic import BaseModel
66
from async_queue import AsyncQueue
77
from fastapi import FastAPI, APIRouter
8+
from fastapi.responses import JSONResponse
89
from contextlib import asynccontextmanager
910
from async_loop import index_loop, crawl_loop
1011

@@ -20,6 +21,34 @@
2021
class Query(BaseModel):
2122
query: str
2223

24+
@router.get(
25+
"/health",
26+
response_description="Health check",
27+
status_code=200,
28+
)
29+
async def health():
30+
try:
31+
result = indexer.find("Indexer healthy")
32+
if not result:
33+
return JSONResponse(
34+
status_code=500,
35+
content={"status": "error", "detail": "Indexer is not healthy"},
36+
)
37+
38+
return JSONResponse(
39+
status_code=200,
40+
content={"status": "ok", "detail": "Indexer is healthy"},
41+
)
42+
43+
except Exception as e:
44+
logger.error(f"Error during health check: {e}")
45+
46+
return JSONResponse(
47+
status_code=500,
48+
content={"status": "error", "detail": str(e)},
49+
)
50+
51+
2352
@router.post(
2453
"/query",
2554
response_description='Query local data storage',

llm/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ RUN pip install huggingface_hub
1010
RUN huggingface-cli download $RERANKER_MODEL --repo-type model
1111
RUN pip install --no-cache-dir -r requirements.txt
1212
COPY . .
13+
RUN apt-get update && apt-get install -y curl
14+
COPY ./wait-for-it.sh /usr/local/bin/wait-for-it.sh
15+
RUN chmod +x /usr/local/bin/wait-for-it.sh
1316

1417
ENV PORT 8000
1518
ENV CURRENT_HOST 0.0.0.0

llm/wait-for-it.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
HOST=$1
6+
TIMEOUT=$2
7+
8+
if [ -z "$HOST" ] || [ -z "$TIMEOUT" ]; then
9+
echo "Usage: $0 <host:port/path> <timeout>"
10+
exit 1
11+
fi
12+
13+
echo "Waiting for $HOST to return HTTP 200..."
14+
15+
for ((i=1;i<=TIMEOUT;i++)); do
16+
STATUS=$(curl -o /dev/null -s -w "%{http_code}" "$HOST" || echo "000")
17+
if [ "$STATUS" -eq 200 ]; then
18+
echo "Service $HOST is ready."
19+
exit 0
20+
fi
21+
echo "Service $HOST not ready, retrying ($i/$TIMEOUT)..."
22+
sleep 1
23+
done
24+
25+
echo "Timeout reached while waiting for $HOST"
26+
exit 1

0 commit comments

Comments
 (0)