-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
Β·213 lines (183 loc) Β· 6.57 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
Β·213 lines (183 loc) Β· 6.57 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# RAG API Docker Deployment Script
set -e
echo "π RAG API Docker Deployment Helper"
echo "====================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}β $1${NC}"
}
print_warning() {
echo -e "${YELLOW}β $1${NC}"
}
print_error() {
echo -e "${RED}β $1${NC}"
}
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check prerequisites
echo "π Checking prerequisites..."
if ! command_exists docker; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
print_status "Docker is installed"
if ! docker compose version >/dev/null 2>&1; then
print_error "Docker Compose is not available. Please ensure Docker with Compose plugin is installed."
exit 1
fi
print_status "Docker Compose is available"
# Check if Docker daemon is running
if ! docker info >/dev/null 2>&1; then
print_error "Docker daemon is not running. Please start Docker first."
exit 1
fi
print_status "Docker daemon is running"
# Parse command line arguments
COMMAND=${1:-"help"}
case $COMMAND in
"build")
echo "π¨ Building RAG API Docker image..."
docker build -t rag-api:latest .
print_status "RAG API image built successfully"
;;
"up")
echo "π Starting all services with Docker Compose..."
docker compose up -d
echo "β³ Waiting for migration to complete..."
# Wait for migration container to finish
timeout=120 # 2 minutes timeout for migration
elapsed=0
while [ $elapsed -lt $timeout ]; do
if docker compose ps migrate | grep -q "Exit 0"; then
print_status "Database migration completed successfully"
break
elif docker compose ps migrate | grep -q "Exit"; then
print_error "Database migration failed! Check logs: docker compose logs migrate"
exit 1
fi
sleep 2
elapsed=$((elapsed + 2))
done
if [ $elapsed -ge $timeout ]; then
print_error "Migration timeout! Check logs: docker compose logs migrate"
exit 1
fi
echo "β³ Waiting for services to be healthy..."
sleep 30
# Check if Ollama model needs to be pulled
echo "π₯ Checking Ollama model..."
if ! docker exec rag-ollama ollama list | grep -q llama3.2:1b; then
echo "β¬οΈ Pulling llama3.2:1b model (this may take a while)..."
docker exec rag-ollama ollama pull llama3.2:1b
fi
print_status "Ollama model ready"
echo ""
echo "π All services are running!"
echo ""
echo "π Service URLs:"
echo " β’ RAG API: http://localhost:8000"
echo " β’ API Docs: http://localhost:8000/docs"
echo " β’ Qdrant UI: http://localhost:6333/dashboard"
echo " β’ PostgreSQL: localhost:5433"
echo " β’ Redis: localhost:6379"
echo " β’ Ollama: http://localhost:11434"
;;
"down")
echo "π Stopping all services..."
docker compose down
print_status "All services stopped"
;;
"restart")
echo "π Restarting all services..."
docker compose down
docker compose up -d
print_status "All services restarted"
;;
"logs")
SERVICE=${2:-"api"}
echo "π Showing logs for $SERVICE..."
docker compose logs -f $SERVICE
;;
"status")
echo "π Service Status:"
docker compose ps
;;
"clean")
echo "π§Ή Cleaning up Docker resources..."
read -p "This will remove all containers, images, and volumes. Are you sure? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
docker compose down -v
docker rmi rag-api:latest 2>/dev/null || true
docker system prune -f
print_status "Docker resources cleaned"
else
echo "Operation cancelled"
fi
;;
"shell")
SERVICE=${2:-"api"}
echo "π Opening shell in $SERVICE container..."
docker compose exec $SERVICE /bin/bash
;;
"test")
echo "π§ͺ Running API health checks..."
# Check if API is running
if curl -f http://localhost:8000/api/v1/health >/dev/null 2>&1; then
print_status "API health check passed"
else
print_error "API health check failed"
fi
# Test document upload
echo "π Testing document upload..."
if curl -X POST "http://localhost:8000/api/v1/upload" \
-H "Content-Type: multipart/form-data" \
-F "file=@README.md" >/dev/null 2>&1; then
print_status "Document upload test passed"
else
print_warning "Document upload test failed (this is expected if no test file exists)"
fi
;;
"migrate")
echo "ποΈ Running database migration..."
if docker compose up -d postgres; then
echo "β³ Waiting for PostgreSQL to be ready..."
sleep 10
docker compose run --rm migrate
print_status "Migration completed"
else
print_error "Failed to start PostgreSQL"
fi
;;
"help"|*)
echo "Usage: $0 [COMMAND] [OPTIONS]"
echo ""
echo "Commands:"
echo " build Build the RAG API Docker image"
echo " up Start all services with Docker Compose"
echo " down Stop all services"
echo " restart Restart all services"
echo " logs Show logs for a service (default: api)"
echo " status Show status of all services"
echo " clean Clean up Docker resources (removes all data)"
echo " shell Open shell in a container (default: api)"
echo " test Run basic health checks"
echo " migrate Run database migration manually"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " $0 up # Start all services"
echo " $0 logs api # Show API logs"
echo " $0 logs postgres # Show PostgreSQL logs"
echo " $0 shell redis # Open shell in Redis container"
echo " $0 migrate # Run database migration"
;;
esac