-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·159 lines (128 loc) · 4.41 KB
/
deploy.sh
File metadata and controls
executable file
·159 lines (128 loc) · 4.41 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
#!/bin/bash
# AI AnswerBot Deployment Script
# This script builds and deploys the AI AnswerBot system
set -e
echo "🤖 AI AnswerBot Deployment Script"
echo "================================="
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to build Docker images
build_images() {
echo "🐳 Building Docker images..."
echo "Building Math Agent..."
docker build -t math-agent:latest ./math-agent/
echo "Building Weather Agent..."
docker build -t weather-agent:latest ./weather-agent/
echo "Building QnA Agent..."
docker build -t qna-agent:latest ./qna-agent/
echo "Building Router..."
docker build -t router:latest ./router/
echo "✅ All Docker images built successfully!"
}
# Function to deploy with Docker Compose (for local testing)
deploy_docker_compose() {
echo "🚀 Deploying with Docker Compose..."
docker-compose down --remove-orphans
docker-compose up -d
echo "⏳ Waiting for services to be ready..."
sleep 10
echo "🔍 Checking service health..."
curl -f http://localhost:8000/health || echo "Router not ready yet"
curl -f http://localhost:8001/health || echo "Math Agent not ready yet"
curl -f http://localhost:8002/health || echo "Weather Agent not ready yet"
curl -f http://localhost:8003/health || echo "QnA Agent not ready yet"
echo "✅ Docker Compose deployment complete!"
echo "🌐 Router available at: http://localhost:8000"
}
# Function to deploy to Kubernetes
deploy_kubernetes() {
echo "☸️ Deploying to Kubernetes..."
# Check if kubectl is available
if ! command_exists kubectl; then
echo "❌ kubectl not found. Please install kubectl first."
exit 1
fi
# Check if cluster is accessible
if ! kubectl cluster-info >/dev/null 2>&1; then
echo "❌ Cannot connect to Kubernetes cluster. Please check your kubeconfig."
exit 1
fi
# Apply Kubernetes manifests
echo "Applying Kubernetes manifests..."
kubectl apply -f k8s/
# Wait for deployments to be ready
echo "⏳ Waiting for deployments to be ready..."
kubectl wait --for=condition=available --timeout=300s deployment/math-agent
kubectl wait --for=condition=available --timeout=300s deployment/weather-agent
kubectl wait --for=condition=available --timeout=300s deployment/qna-agent
kubectl wait --for=condition=available --timeout=300s deployment/router
echo "✅ Kubernetes deployment complete!"
echo "🌐 Router available at: http://localhost:30080"
}
# Function to run tests
run_tests() {
echo "🧪 Running tests..."
# Test Math Agent
echo "Testing Math Agent..."
curl -X POST http://localhost:8000/ask \
-H "Content-Type: application/json" \
-d '{"question": "What is 12 + 45?"}' || echo "Math test failed"
# Test Weather Agent
echo "Testing Weather Agent..."
curl -X POST http://localhost:8000/ask \
-H "Content-Type: application/json" \
-d '{"question": "What is the weather in London?"}' || echo "Weather test failed"
# Test QnA Agent
echo "Testing QnA Agent..."
curl -X POST http://localhost:8000/ask \
-H "Content-Type: application/json" \
-d '{"question": "What is AI?"}' || echo "QnA test failed"
echo "✅ Tests completed!"
}
# Function to show usage
show_usage() {
echo "Usage: $0 [OPTION]"
echo "Options:"
echo " build Build Docker images"
echo " docker Deploy with Docker Compose"
echo " k8s Deploy to Kubernetes"
echo " test Run tests"
echo " clean Clean up resources"
echo " help Show this help message"
}
# Function to clean up
cleanup() {
echo "🧹 Cleaning up..."
# Clean Docker Compose
docker-compose down --remove-orphans --volumes
# Clean Kubernetes
if command_exists kubectl; then
kubectl delete -f k8s/ --ignore-not-found=true
fi
echo "✅ Cleanup complete!"
}
# Main script logic
case "${1:-help}" in
build)
build_images
;;
docker)
build_images
deploy_docker_compose
;;
k8s)
build_images
deploy_kubernetes
;;
test)
run_tests
;;
clean)
cleanup
;;
help|*)
show_usage
;;
esac