-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (57 loc) · 1.76 KB
/
Dockerfile
File metadata and controls
70 lines (57 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Use official Python image
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV OLLAMA_HOST="0.0.0.0"
ENV PYTHONPATH=/app
# Set working directory
WORKDIR /app
# Install minimal system dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Install Ollama (CPU version) with retry
RUN for i in {1..3}; do \
if curl -fsSL https://ollama.com/install.sh | sh; then \
break; \
else \
echo "Ollama installation failed, retrying in 5 seconds..."; \
sleep 5; \
fi; \
done && \
if ! command -v ollama >/dev/null 2>&1; then \
echo "Ollama installation failed after retries"; \
exit 1; \
fi
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt \
&& pip cache purge
# Copy application files
COPY . .
# Create necessary directories
RUN mkdir -p /app/uploads /app/kg_storage /app/vector_stores /app/chroma_db
# Set proper permissions
RUN chmod -R 755 /app
# Expose port
EXPOSE 8004
# Add health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=3 \
CMD curl --fail http://localhost:8004/health || exit 1
# Create startup script
RUN echo '#!/bin/bash\n\
set -e\n\
echo "Starting Ollama server..."\n\
ollama serve &\n\
OLLAMA_PID=$!\n\
echo "Waiting for Ollama to be ready..."\n\
sleep 5\n\
echo "Starting FastAPI application..."\n\
uvicorn ontographrag.api.app:app --host 0.0.0.0 --port 8004 --workers 1\n\
' > /app/start.sh && chmod +x /app/start.sh
# Command to run the application
CMD ["/app/start.sh"]