-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-deployment.sh
More file actions
478 lines (409 loc) · 13.6 KB
/
Copy pathtest-deployment.sh
File metadata and controls
478 lines (409 loc) · 13.6 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#!/bin/bash
# ============================================
# MCP Hub - Pre-Deployment Validation
# Tests everything before production deploy
# ============================================
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
TESTS_PASSED=0
TESTS_FAILED=0
WARNINGS=0
echo ""
echo "╔════════════════════════════════════════╗"
echo "║ MCP Hub - Pre-Deployment Validation ║"
echo "╚════════════════════════════════════════╝"
echo ""
# Helper functions
pass() {
echo -e "${GREEN}✓${NC} $1"
((TESTS_PASSED++))
}
fail() {
echo -e "${RED}✗${NC} $1"
((TESTS_FAILED++))
}
warn() {
echo -e "${YELLOW}⚠${NC} $1"
((WARNINGS++))
}
info() {
echo -e "ℹ $1"
}
# ============================================
# 1. FILE STRUCTURE VALIDATION
# ============================================
echo "1. Validating File Structure..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check required files
REQUIRED_FILES=(
"docker-compose.yml"
"docker-compose.prod.yml"
".env.template"
".env.production.template"
"gateway/server.js"
"gateway/package.json"
"gateway/Dockerfile"
"nginx/nginx.conf"
"nginx/conf.d/mcp-hub.conf"
"README.md"
"QUICKSTART.md"
"CLOUD_DEPLOYMENT.md"
)
for file in "${REQUIRED_FILES[@]}"; do
if [ -f "$file" ]; then
pass "Found: $file"
else
fail "Missing: $file"
fi
done
# Check required directories
REQUIRED_DIRS=(
"gateway"
"gateway/handlers"
"nginx"
"config"
"scripts"
"agent"
"deploy"
)
for dir in "${REQUIRED_DIRS[@]}"; do
if [ -d "$dir" ]; then
pass "Directory exists: $dir"
else
fail "Missing directory: $dir"
fi
done
echo ""
# ============================================
# 2. DOCKER CONFIGURATION VALIDATION
# ============================================
echo "2. Validating Docker Configuration..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check if Docker is installed
if command -v docker &> /dev/null; then
pass "Docker is installed"
DOCKER_VERSION=$(docker --version)
info "Version: $DOCKER_VERSION"
else
fail "Docker is not installed"
fi
# Check if Docker is running
if docker info &> /dev/null; then
pass "Docker is running"
else
fail "Docker is not running"
fi
# Check Docker Compose
if command -v docker-compose &> /dev/null; then
pass "Docker Compose is installed"
COMPOSE_VERSION=$(docker-compose --version)
info "Version: $COMPOSE_VERSION"
else
fail "Docker Compose is not installed"
fi
# Validate docker-compose.yml syntax
if docker-compose config > /dev/null 2>&1; then
pass "docker-compose.yml syntax is valid"
else
fail "docker-compose.yml has syntax errors"
docker-compose config 2>&1 | head -5
fi
# Validate docker-compose.prod.yml syntax
if docker-compose -f docker-compose.prod.yml config > /dev/null 2>&1; then
pass "docker-compose.prod.yml syntax is valid"
else
fail "docker-compose.prod.yml has syntax errors"
docker-compose -f docker-compose.prod.yml config 2>&1 | head -5
fi
echo ""
# ============================================
# 3. ENVIRONMENT CONFIGURATION
# ============================================
echo "3. Validating Environment Configuration..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check if .env exists
if [ -f ".env" ]; then
pass ".env file exists"
# Check for default passwords
if grep -q "CHANGE_ME" .env 2>/dev/null; then
warn ".env contains placeholder passwords - please change them!"
else
pass "No placeholder passwords found in .env"
fi
# Check for required variables
REQUIRED_VARS=(
"POSTGRES_USER"
"POSTGRES_PASSWORD"
"MONGO_USER"
"MONGO_PASSWORD"
"REDIS_PASSWORD"
)
for var in "${REQUIRED_VARS[@]}"; do
if grep -q "^${var}=" .env; then
pass "Environment variable set: $var"
else
warn "Missing environment variable: $var"
fi
done
else
warn ".env file not found (will use template defaults)"
info "Run: cp .env.template .env"
fi
# Check .env.template
if [ -f ".env.template" ]; then
pass ".env.template exists"
else
fail ".env.template is missing"
fi
echo ""
# ============================================
# 4. GATEWAY APPLICATION VALIDATION
# ============================================
echo "4. Validating Gateway Application..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check package.json
if [ -f "gateway/package.json" ]; then
pass "gateway/package.json exists"
# Validate JSON syntax
if python3 -m json.tool gateway/package.json > /dev/null 2>&1 || node -e "require('./gateway/package.json')" > /dev/null 2>&1; then
pass "gateway/package.json is valid JSON"
else
fail "gateway/package.json has syntax errors"
fi
else
fail "gateway/package.json is missing"
fi
# Check server.js
if [ -f "gateway/server.js" ]; then
pass "gateway/server.js exists"
# Basic syntax check
if node -c gateway/server.js > /dev/null 2>&1; then
pass "gateway/server.js has valid syntax"
else
warn "Cannot validate gateway/server.js syntax (Node.js required)"
fi
else
fail "gateway/server.js is missing"
fi
# Check handlers
HANDLER_FILES=(
"gateway/handlers/base.js"
"gateway/handlers/notion.js"
"gateway/handlers/mongodb.js"
"gateway/handlers/index.js"
)
for handler in "${HANDLER_FILES[@]}"; do
if [ -f "$handler" ]; then
pass "Found: $handler"
else
fail "Missing: $handler"
fi
done
echo ""
# ============================================
# 5. NGINX CONFIGURATION VALIDATION
# ============================================
echo "5. Validating Nginx Configuration..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check nginx config files
if [ -f "nginx/nginx.conf" ]; then
pass "nginx/nginx.conf exists"
else
fail "nginx/nginx.conf is missing"
fi
if [ -f "nginx/conf.d/mcp-hub.conf" ]; then
pass "nginx/conf.d/mcp-hub.conf exists"
# Check for placeholder domain
if grep -q '${DOMAIN_NAME}' nginx/conf.d/mcp-hub.conf; then
warn "nginx config contains placeholder \${DOMAIN_NAME}"
info "Replace with your actual domain before deployment"
fi
else
fail "nginx/conf.d/mcp-hub.conf is missing"
fi
echo ""
# ============================================
# 6. SCRIPTS VALIDATION
# ============================================
echo "6. Validating Scripts..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
SCRIPT_FILES=(
"start.sh"
"stop.sh"
"install.sh"
"scripts/backup.sh"
"scripts/restore.sh"
"deploy/digitalocean-deploy.sh"
)
for script in "${SCRIPT_FILES[@]}"; do
if [ -f "$script" ]; then
pass "Found: $script"
# Check if executable
if [ -x "$script" ]; then
pass " → Executable"
else
warn " → Not executable (run: chmod +x $script)"
fi
# Basic syntax check
if bash -n "$script" > /dev/null 2>&1; then
pass " → Valid bash syntax"
else
fail " → Syntax errors detected"
fi
else
warn "Missing: $script"
fi
done
echo ""
# ============================================
# 7. DOCUMENTATION VALIDATION
# ============================================
echo "7. Validating Documentation..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
DOC_FILES=(
"README.md"
"QUICKSTART.md"
"CLOUD_DEPLOYMENT.md"
"IDE_CONNECTIONS.md"
"INDEX.md"
)
for doc in "${DOC_FILES[@]}"; do
if [ -f "$doc" ]; then
pass "Found: $doc"
# Check if not empty
if [ -s "$doc" ]; then
pass " → Contains content"
else
warn " → File is empty"
fi
else
warn "Missing: $doc"
fi
done
echo ""
# ============================================
# 8. PORT AVAILABILITY CHECK
# ============================================
echo "8. Checking Port Availability..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
REQUIRED_PORTS=(
3100
5432
27017
6379
47334
9090
)
for port in "${REQUIRED_PORTS[@]}"; do
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1 || netstat -an 2>/dev/null | grep -q ":$port.*LISTEN"; then
warn "Port $port is already in use"
info " Services may conflict. Stop existing services or change ports."
else
pass "Port $port is available"
fi
done
echo ""
# ============================================
# 9. DEPENDENCIES CHECK
# ============================================
echo "9. Checking System Dependencies..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check curl
if command -v curl &> /dev/null; then
pass "curl is installed"
else
warn "curl is not installed (needed for health checks)"
fi
# Check git
if command -v git &> /dev/null; then
pass "git is installed"
else
warn "git is not installed (recommended for updates)"
fi
# Check node (for agent)
if command -v node &> /dev/null; then
pass "Node.js is installed"
NODE_VERSION=$(node --version)
info "Version: $NODE_VERSION"
else
warn "Node.js is not installed (required for query agent)"
fi
echo ""
# ============================================
# 10. SECURITY CHECKS
# ============================================
echo "10. Security Validation..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check for .gitignore
if [ -f ".gitignore" ]; then
pass ".gitignore exists"
# Check if .env is ignored
if grep -q "^\.env$" .gitignore; then
pass ".env is in .gitignore (good!)"
else
warn ".env should be in .gitignore"
fi
else
warn ".gitignore is missing"
fi
# Check for default passwords in production template
if [ -f ".env.production.template" ]; then
if grep -q "CHANGE_ME" .env.production.template; then
pass "Production template has password placeholders (remember to change!)"
fi
fi
# Check permissions on sensitive files
if [ -f ".env" ]; then
PERM=$(stat -c %a .env 2>/dev/null || stat -f %A .env 2>/dev/null)
if [ "$PERM" = "600" ] || [ "$PERM" = "400" ]; then
pass ".env has secure permissions ($PERM)"
else
warn ".env permissions are $PERM (consider chmod 600 .env)"
fi
fi
echo ""
# ============================================
# SUMMARY
# ============================================
echo ""
echo "╔════════════════════════════════════════╗"
echo "║ Test Summary ║"
echo "╚════════════════════════════════════════╝"
echo ""
echo -e "${GREEN}Passed:${NC} $TESTS_PASSED"
echo -e "${RED}Failed:${NC} $TESTS_FAILED"
echo -e "${YELLOW}Warnings:${NC} $WARNINGS"
echo ""
if [ $TESTS_FAILED -eq 0 ]; then
if [ $WARNINGS -eq 0 ]; then
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ✓ ALL CHECKS PASSED! ║${NC}"
echo -e "${GREEN}║ Ready for deployment! 🚀 ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════╝${NC}"
echo ""
echo "Next steps:"
echo " 1. Test locally: ./start.sh"
echo " 2. Deploy to cloud: See CLOUD_DEPLOYMENT.md"
echo " 3. Connect IDE: claude mcp add --transport http mcp-hub http://localhost:3100/mcp"
exit 0
else
echo -e "${YELLOW}╔════════════════════════════════════════╗${NC}"
echo -e "${YELLOW}║ ⚠ CHECKS PASSED WITH WARNINGS ║${NC}"
echo -e "${YELLOW}║ Review warnings before deployment ║${NC}"
echo -e "${YELLOW}╚════════════════════════════════════════╝${NC}"
echo ""
echo "You can proceed, but address warnings for production."
exit 0
fi
else
echo -e "${RED}╔════════════════════════════════════════╗${NC}"
echo -e "${RED}║ ✗ SOME CHECKS FAILED ║${NC}"
echo -e "${RED}║ Fix issues before deployment ║${NC}"
echo -e "${RED}╚════════════════════════════════════════╝${NC}"
echo ""
echo "Please fix the failed checks above and run this script again."
exit 1
fi