-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphase3_production_setup.sh
More file actions
executable file
·952 lines (806 loc) · 22.8 KB
/
Copy pathphase3_production_setup.sh
File metadata and controls
executable file
·952 lines (806 loc) · 22.8 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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
#!/bin/bash
# 🚀 AgentFlow Phase 3: Production Deployment
# Complete production setup with Docker, cloud deployment, and monitoring
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
NC='\033[0m'
# Configuration
PROJECT_NAME="agentflow"
VERSION="1.0.0"
ENVIRONMENT=${1:-production}
echo -e "${MAGENTA}🚀 AgentFlow Phase 3: Production Deployment${NC}"
echo -e "${BLUE}Setting up enterprise-grade production infrastructure${NC}"
echo ""
# Function to check prerequisites
check_prerequisites() {
echo -e "${CYAN}📋 Checking prerequisites...${NC}"
# Check Docker
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Docker is not installed${NC}"
exit 1
fi
# Check Docker Compose
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}❌ Docker Compose is not installed${NC}"
exit 1
fi
# Check Node.js
if ! command -v node &> /dev/null; then
echo -e "${RED}❌ Node.js is not installed${NC}"
exit 1
fi
echo -e "${GREEN}✅ Prerequisites check passed${NC}"
}
# Function to create Docker configuration
create_docker_config() {
echo -e "${CYAN}🐳 Creating Docker configuration...${NC}"
# Create Dockerfile for backend
cat > backend/Dockerfile << 'EOF'
# Multi-stage build for AgentFlow Backend
FROM node:18-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force
# Copy source code
COPY . .
# Create production build
RUN npm run build 2>/dev/null || echo "No build script defined"
# Production stage
FROM node:18-alpine AS production
# Install system dependencies
RUN apk add --no-cache \
dumb-init \
sqlite \
curl \
&& addgroup -g 1001 -S nodejs \
&& adduser -S nodejs -u 1001
WORKDIR /app
# Copy built application
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nodejs:nodejs /app/ ./
# Create directories
RUN mkdir -p /app/data /app/logs && chown -R nodejs:nodejs /app
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3001/health || exit 1
USER nodejs
EXPOSE 3001
ENTRYPOINT ["dumb-init", "--"]
CMD ["node", "src/server.js"]
EOF
# Create Docker Compose for complete stack
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
# AgentFlow Backend
agentflow-backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: agentflow-backend
environment:
- NODE_ENV=production
- DEPLOYMENT_MODE=api
- PORT=3001
- DATABASE_URL=file:/app/data/agentflow.db
- REDIS_URL=redis://redis:6379
- LOG_LEVEL=info
ports:
- "3001:3001"
volumes:
- backend_data:/app/data
- backend_logs:/app/logs
depends_on:
- redis
- prometheus
networks:
- agentflow_network
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.backend.rule=Host(`api.agentflow.local`)"
- "traefik.http.services.backend.loadbalancer.server.port=3001"
# Redis for caching and session management
redis:
image: redis:7-alpine
container_name: agentflow-redis
command: redis-server --requirepass ${REDIS_PASSWORD:-agentflow123}
volumes:
- redis_data:/data
networks:
- agentflow_network
restart: unless-stopped
# PostgreSQL for production database (optional upgrade from SQLite)
postgres:
image: postgres:15-alpine
container_name: agentflow-postgres
environment:
- POSTGRES_DB=agentflow
- POSTGRES_USER=agentflow
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-agentflow123}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- agentflow_network
restart: unless-stopped
# Nginx reverse proxy
nginx:
image: nginx:alpine
container_name: agentflow-nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/ssl:/etc/nginx/ssl:ro
- nginx_logs:/var/log/nginx
depends_on:
- agentflow-backend
networks:
- agentflow_network
restart: unless-stopped
# Prometheus for monitoring
prometheus:
image: prom/prometheus:latest
container_name: agentflow-prometheus
ports:
- "9090:9090"
volumes:
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--storage.tsdb.retention.time=200h'
- '--web.enable-lifecycle'
networks:
- agentflow_network
restart: unless-stopped
# Grafana for dashboards
grafana:
image: grafana/grafana:latest
container_name: agentflow-grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin123}
- GF_USERS_ALLOW_SIGN_UP=false
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/dashboards:/etc/grafana/provisioning/dashboards:ro
- ./monitoring/grafana/datasources:/etc/grafana/provisioning/datasources:ro
networks:
- agentflow_network
restart: unless-stopped
# Ollama for local AI models
ollama:
image: ollama/ollama:latest
container_name: agentflow-ollama
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
environment:
- OLLAMA_HOST=0.0.0.0
networks:
- agentflow_network
restart: unless-stopped
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
volumes:
backend_data:
driver: local
backend_logs:
driver: local
redis_data:
driver: local
postgres_data:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
ollama_data:
driver: local
nginx_logs:
driver: local
networks:
agentflow_network:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
EOF
echo -e "${GREEN}✅ Docker configuration created${NC}"
}
# Function to create Nginx configuration
create_nginx_config() {
echo -e "${CYAN}🌐 Creating Nginx configuration...${NC}"
mkdir -p nginx/ssl
cat > nginx/nginx.conf << 'EOF'
events {
worker_connections 1024;
}
http {
upstream backend {
server agentflow-backend:3001;
}
# Rate limiting
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
# Main server block
server {
listen 80;
listen 443 ssl http2;
server_name agentflow.local *.agentflow.local;
# SSL configuration
ssl_certificate /etc/nginx/ssl/agentflow.crt;
ssl_certificate_key /etc/nginx/ssl/agentflow.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# Redirect HTTP to HTTPS
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
# API routes
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# Health check
location /health {
proxy_pass http://backend/health;
access_log off;
}
# Static files for iOS app
location / {
root /var/www/html;
try_files $uri $uri/ /index.html;
expires 1y;
add_header Cache-Control "public, immutable";
}
# Security
location ~ /\. {
deny all;
}
}
}
EOF
# Create self-signed SSL certificate for development
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout nginx/ssl/agentflow.key \
-out nginx/ssl/agentflow.crt \
-subj "/C=US/ST=CA/L=SF/O=AgentFlow/CN=agentflow.local" 2>/dev/null || echo "SSL cert creation skipped"
echo -e "${GREEN}✅ Nginx configuration created${NC}"
}
# Function to create monitoring configuration
create_monitoring_config() {
echo -e "${CYAN}📊 Creating monitoring configuration...${NC}"
mkdir -p monitoring/grafana/{dashboards,datasources}
# Prometheus configuration
cat > monitoring/prometheus.yml << 'EOF'
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
# - "first_rules.yml"
scrape_configs:
- job_name: 'agentflow-backend'
static_configs:
- targets: ['agentflow-backend:3001']
metrics_path: '/metrics'
scrape_interval: 5s
- job_name: 'redis'
static_configs:
- targets: ['redis:6379']
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
EOF
# Grafana datasource
cat > monitoring/grafana/datasources/prometheus.yml << 'EOF'
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
EOF
# Grafana dashboard
cat > monitoring/grafana/dashboards/agentflow.json << 'EOF'
{
"dashboard": {
"id": null,
"title": "AgentFlow Production Metrics",
"tags": ["agentflow"],
"timezone": "browser",
"panels": [
{
"id": 1,
"title": "API Response Time",
"type": "graph",
"targets": [
{
"expr": "histogram_quantile(0.95, agentflow_http_request_duration_seconds_bucket)",
"legendFormat": "95th percentile"
}
]
},
{
"id": 2,
"title": "Model Execution Count",
"type": "singlestat",
"targets": [
{
"expr": "agentflow_model_executions_total",
"legendFormat": "Total Executions"
}
]
}
],
"time": {
"from": "now-1h",
"to": "now"
},
"refresh": "5s"
}
}
EOF
echo -e "${GREEN}✅ Monitoring configuration created${NC}"
}
# Function to create Kubernetes manifests
create_kubernetes_config() {
echo -e "${CYAN}☸️ Creating Kubernetes configuration...${NC}"
mkdir -p k8s
# Namespace
cat > k8s/namespace.yaml << 'EOF'
apiVersion: v1
kind: Namespace
metadata:
name: agentflow
labels:
name: agentflow
EOF
# ConfigMap
cat > k8s/configmap.yaml << 'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: agentflow-config
namespace: agentflow
data:
NODE_ENV: "production"
DEPLOYMENT_MODE: "api"
PORT: "3001"
LOG_LEVEL: "info"
EOF
# Secret
cat > k8s/secret.yaml << 'EOF'
apiVersion: v1
kind: Secret
metadata:
name: agentflow-secret
namespace: agentflow
type: Opaque
stringData:
OPENAI_API_KEY: ""
GEMINI_API_KEY: ""
ANTHROPIC_API_KEY: ""
DATABASE_PASSWORD: "agentflow123"
REDIS_PASSWORD: "agentflow123"
EOF
# Deployment
cat > k8s/deployment.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: agentflow-backend
namespace: agentflow
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: agentflow-backend
template:
metadata:
labels:
app: agentflow-backend
spec:
containers:
- name: agentflow-backend
image: agentflow/backend:latest
ports:
- containerPort: 3001
env:
- name: NODE_ENV
valueFrom:
configMapKeyRef:
name: agentflow-config
key: NODE_ENV
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: agentflow-secret
key: OPENAI_API_KEY
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health
port: 3001
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /health
port: 3001
initialDelaySeconds: 5
periodSeconds: 5
EOF
# Service
cat > k8s/service.yaml << 'EOF'
apiVersion: v1
kind: Service
metadata:
name: agentflow-backend-service
namespace: agentflow
spec:
selector:
app: agentflow-backend
ports:
- protocol: TCP
port: 80
targetPort: 3001
type: ClusterIP
EOF
# Ingress
cat > k8s/ingress.yaml << 'EOF'
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: agentflow-ingress
namespace: agentflow
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
spec:
tls:
- hosts:
- api.agentflow.com
secretName: agentflow-tls
rules:
- host: api.agentflow.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: agentflow-backend-service
port:
number: 80
EOF
echo -e "${GREEN}✅ Kubernetes configuration created${NC}"
}
# Function to create cloud deployment scripts
create_cloud_deployment() {
echo -e "${CYAN}☁️ Creating cloud deployment scripts...${NC}"
mkdir -p deployment
# AWS deployment script
cat > deployment/deploy-aws.sh << 'EOF'
#!/bin/bash
# AWS ECS Deployment Script
echo "🚀 Deploying AgentFlow to AWS ECS..."
# Build and push Docker image
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-west-2.amazonaws.com
docker build -t agentflow/backend ./backend
docker tag agentflow/backend:latest 123456789.dkr.ecr.us-west-2.amazonaws.com/agentflow:latest
docker push 123456789.dkr.ecr.us-west-2.amazonaws.com/agentflow:latest
# Update ECS service
aws ecs update-service --cluster agentflow-cluster --service agentflow-service --force-new-deployment
echo "✅ AWS deployment completed"
EOF
# Google Cloud deployment script
cat > deployment/deploy-gcp.sh << 'EOF'
#!/bin/bash
# Google Cloud Run Deployment Script
echo "🚀 Deploying AgentFlow to Google Cloud Run..."
# Build and deploy
gcloud builds submit --tag gcr.io/PROJECT_ID/agentflow ./backend
gcloud run deploy agentflow \
--image gcr.io/PROJECT_ID/agentflow \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars NODE_ENV=production,DEPLOYMENT_MODE=api
echo "✅ Google Cloud deployment completed"
EOF
# Azure deployment script
cat > deployment/deploy-azure.sh << 'EOF'
#!/bin/bash
# Azure Container Instances Deployment Script
echo "🚀 Deploying AgentFlow to Azure..."
# Build and push to ACR
az acr build --registry agentflowregistry --image agentflow:latest ./backend
# Deploy to Container Instances
az container create \
--resource-group agentflow-rg \
--name agentflow-backend \
--image agentflowregistry.azurecr.io/agentflow:latest \
--cpu 2 \
--memory 4 \
--ports 3001 \
--environment-variables NODE_ENV=production DEPLOYMENT_MODE=api
echo "✅ Azure deployment completed"
EOF
chmod +x deployment/*.sh
echo -e "${GREEN}✅ Cloud deployment scripts created${NC}"
}
# Function to create production environment file
create_production_env() {
echo -e "${CYAN}🔧 Creating production environment configuration...${NC}"
cat > .env.production << 'EOF'
# 🚀 AgentFlow Production Environment Configuration
# Application
NODE_ENV=production
DEPLOYMENT_MODE=api
PORT=3001
LOG_LEVEL=info
APP_URL=https://agentflow.com
# Database
DATABASE_URL=postgresql://agentflow:agentflow123@postgres:5432/agentflow
REDIS_URL=redis://redis:6379
# API Keys (SET THESE BEFORE DEPLOYMENT!)
OPENAI_API_KEY=your_openai_key_here
GEMINI_API_KEY=your_gemini_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here
# Security
JWT_SECRET=your_super_secret_jwt_key_here
ENCRYPTION_KEY=your_32_character_encryption_key
# Rate Limiting
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=100
# Monitoring
PROMETHEUS_ENABLED=true
METRICS_PORT=9090
HEALTH_CHECK_INTERVAL=30000
# Performance
CACHE_TTL=3600
MAX_CONCURRENT_REQUESTS=50
WORKER_POOL_SIZE=4
# Email (for notifications)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_app_password
# Cloud Storage (optional)
AWS_ACCESS_KEY_ID=your_aws_key
AWS_SECRET_ACCESS_KEY=your_aws_secret
S3_BUCKET=agentflow-storage
# Sentry Error Tracking
SENTRY_DSN=your_sentry_dsn_here
EOF
echo -e "${GREEN}✅ Production environment file created${NC}"
echo -e "${YELLOW}⚠️ Remember to update API keys and secrets in .env.production${NC}"
}
# Function to create deployment checklist
create_deployment_checklist() {
echo -e "${CYAN}📋 Creating deployment checklist...${NC}"
cat > DEPLOYMENT_CHECKLIST.md << 'EOF'
# 🚀 AgentFlow Production Deployment Checklist
## Pre-Deployment Checklist
### 1. Environment Setup
- [ ] Update API keys in `.env.production`
- [ ] Configure database credentials
- [ ] Set up SSL certificates
- [ ] Configure monitoring credentials
- [ ] Test all API integrations
### 2. Security Checklist
- [ ] Enable HTTPS everywhere
- [ ] Configure rate limiting
- [ ] Set up firewall rules
- [ ] Enable security headers
- [ ] Configure CORS properly
- [ ] Set strong passwords/secrets
### 3. Performance Optimization
- [ ] Configure Redis caching
- [ ] Set up CDN for static assets
- [ ] Enable gzip compression
- [ ] Configure load balancing
- [ ] Optimize database queries
### 4. Monitoring Setup
- [ ] Configure Prometheus metrics
- [ ] Set up Grafana dashboards
- [ ] Configure alerting rules
- [ ] Set up log aggregation
- [ ] Configure uptime monitoring
## Deployment Options
### Option 1: Docker Compose (Recommended for VPS)
```bash
# Start production stack
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f agentflow-backend
```
### Option 2: Kubernetes
```bash
# Apply configurations
kubectl apply -f k8s/
# Check deployment
kubectl get pods -n agentflow
# View logs
kubectl logs -f deployment/agentflow-backend -n agentflow
```
### Option 3: Cloud Deployment
```bash
# AWS
./deployment/deploy-aws.sh
# Google Cloud
./deployment/deploy-gcp.sh
# Azure
./deployment/deploy-azure.sh
```
## Post-Deployment Verification
### 1. Health Checks
- [ ] Backend health endpoint: `GET /health`
- [ ] Database connectivity test
- [ ] Redis connectivity test
- [ ] Model service availability
### 2. API Testing
- [ ] Test authentication endpoints
- [ ] Test agent creation/execution
- [ ] Test model routing
- [ ] Test WebSocket connections
### 3. Performance Testing
- [ ] Load test with 100 concurrent users
- [ ] Memory usage within limits
- [ ] Response times < 2 seconds
- [ ] Error rate < 1%
### 4. Monitoring Verification
- [ ] Metrics appearing in Prometheus
- [ ] Grafana dashboards working
- [ ] Alerts configured and firing
- [ ] Log aggregation working
## Rollback Plan
### Quick Rollback
```bash
# Docker Compose
docker-compose down
git checkout previous-stable-tag
docker-compose up -d
# Kubernetes
kubectl rollout undo deployment/agentflow-backend -n agentflow
```
## Maintenance
### Regular Tasks
- Monitor resource usage
- Update dependencies
- Backup database
- Rotate secrets
- Update SSL certificates
### Performance Monitoring
- API response times
- Model execution times
- Memory/CPU usage
- Database performance
- Error rates
### Security Updates
- Update base images monthly
- Patch security vulnerabilities
- Review access logs
- Update API keys quarterly
EOF
echo -e "${GREEN}✅ Deployment checklist created${NC}"
}
# Function to setup production monitoring
setup_monitoring() {
echo -e "${CYAN}📊 Setting up production monitoring...${NC}"
# Add monitoring endpoints to backend
cat >> backend/src/middleware/monitoring.js << 'EOF'
const prometheus = require('prom-client');
// Create metrics
const httpRequestDuration = new prometheus.Histogram({
name: 'agentflow_http_request_duration_seconds',
help: 'Duration of HTTP requests in seconds',
labelNames: ['method', 'route', 'status_code'],
buckets: [0.1, 0.5, 1, 2, 5]
});
const modelExecutions = new prometheus.Counter({
name: 'agentflow_model_executions_total',
help: 'Total number of model executions',
labelNames: ['model', 'status']
});
const activeConnections = new prometheus.Gauge({
name: 'agentflow_active_connections',
help: 'Number of active WebSocket connections'
});
// Collect default metrics
prometheus.collectDefaultMetrics();
module.exports = {
httpRequestDuration,
modelExecutions,
activeConnections,
register: prometheus.register
};
EOF
echo -e "${GREEN}✅ Monitoring setup completed${NC}"
}
# Main deployment function
main() {
echo -e "${MAGENTA}Starting Phase 3 Production Setup...${NC}"
check_prerequisites
create_docker_config
create_nginx_config
create_monitoring_config
create_kubernetes_config
create_cloud_deployment
create_production_env
create_deployment_checklist
setup_monitoring
echo ""
echo -e "${GREEN}🎉 Phase 3 Production Setup Complete!${NC}"
echo ""
echo -e "${CYAN}📋 Next Steps:${NC}"
echo -e "1. Update API keys in ${YELLOW}.env.production${NC}"
echo -e "2. Review ${YELLOW}DEPLOYMENT_CHECKLIST.md${NC}"
echo -e "3. Choose deployment method:"
echo -e " - Docker Compose: ${BLUE}docker-compose up -d${NC}"
echo -e " - Kubernetes: ${BLUE}kubectl apply -f k8s/${NC}"
echo -e " - Cloud: ${BLUE}./deployment/deploy-[aws|gcp|azure].sh${NC}"
echo ""
echo -e "${YELLOW}⚠️ Remember to configure your domain and SSL certificates!${NC}"
echo ""
echo -e "${MAGENTA}🚀 AgentFlow is ready for production deployment!${NC}"
}
# Run main function
main