-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·196 lines (164 loc) · 5.84 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·196 lines (164 loc) · 5.84 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
#!/bin/bash
# OpenLearnX - Master Deployment Script
# Deploys both backend and frontend
# Usage: ./deploy.sh [production|staging|local]
ENVIRONMENT=${1:-production}
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
LOG_FILE="/tmp/openlearnx_deploy_$TIMESTAMP.log"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_status() { echo -e "${BLUE}[INFO]${NC} $1" | tee -a "$LOG_FILE"; }
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOG_FILE"; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOG_FILE"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE"; }
banner() {
cat << "EOF"
╔═══════════════════════════════════════════╗
║ 🚀 OpenLearnX Deployment System 🚀 ║
╚═══════════════════════════════════════════╝
EOF
}
banner
print_status "═══════════════════════════════════════════════"
print_status " OpenLearnX Master Deployment"
print_status " Environment: $ENVIRONMENT"
print_status " Timestamp: $TIMESTAMP"
print_status "═══════════════════════════════════════════════"
print_status "Log file: $LOG_FILE"
echo ""
# Validate environment
case "$ENVIRONMENT" in
production|staging|local)
print_success "Environment: $ENVIRONMENT (valid)"
;;
*)
print_error "Invalid environment: $ENVIRONMENT"
echo "Usage: $0 [production|staging|local]"
exit 1
;;
esac
# Show deployment plan
echo ""
print_status "Deployment Plan:"
print_status " 1. ✓ Pull latest changes from GitHub"
print_status " 2. ✓ Deploy Backend (Flask/Python)"
print_status " 3. ✓ Deploy Frontend (Next.js/React)"
print_status " 4. ✓ Run health checks"
print_status " 5. ✓ Display deployment summary"
echo ""
# Confirm before proceeding
if [ "$ENVIRONMENT" = "production" ]; then
print_warning "⚠️ PRODUCTION DEPLOYMENT - Please review carefully!"
read -p "Type 'yes' to proceed with production deployment: " confirm
if [ "$confirm" != "yes" ]; then
print_error "Deployment cancelled"
exit 1
fi
fi
# Change to script directory
cd "$SCRIPT_DIR"
# 1. Pull latest changes
print_status "Step 1/5: Pulling latest changes..."
if git pull origin main 2>&1 | tee -a "$LOG_FILE"; then
print_success "Latest changes pulled"
else
print_warning "Git pull encountered issues, continuing..."
fi
# 2. Deploy Backend
print_status ""
print_status "Step 2/5: Deploying Backend..."
if [ -f "deploy-backend.sh" ]; then
if bash deploy-backend.sh "$ENVIRONMENT" 2>&1 | tee -a "$LOG_FILE"; then
print_success "Backend deployment successful"
else
print_error "Backend deployment failed"
exit 1
fi
else
print_error "deploy-backend.sh not found"
exit 1
fi
# 3. Deploy Frontend
print_status ""
print_status "Step 3/5: Deploying Frontend..."
if [ -f "deploy-frontend.sh" ]; then
if bash deploy-frontend.sh "$ENVIRONMENT" 2>&1 | tee -a "$LOG_FILE"; then
print_success "Frontend deployment successful"
else
print_error "Frontend deployment failed"
exit 1
fi
else
print_error "deploy-frontend.sh not found"
exit 1
fi
# 4. Health checks
print_status ""
print_status "Step 4/5: Running health checks..."
# Check Backend
print_status "Checking Backend API (http://localhost:5000)..."
if curl -s http://localhost:5000/api/health >/dev/null 2>&1 || curl -s http://localhost:5000 >/dev/null 2>&1; then
print_success "Backend API is responding"
else
print_warning "Backend API not responding yet (may still be starting)"
fi
# Check Frontend
print_status "Checking Frontend (http://localhost:3000)..."
if curl -s http://localhost:3000 >/dev/null 2>&1; then
print_success "Frontend is responding"
else
print_warning "Frontend not responding yet (may still be starting)"
fi
# 5. Summary
print_status ""
print_status "Step 5/5: Generating deployment summary..."
echo ""
print_success "═══════════════════════════════════════════════"
print_success " ✅ DEPLOYMENT SUCCESSFUL ✅"
print_success "═══════════════════════════════════════════════"
echo ""
cat << EOF | tee -a "$LOG_FILE"
📊 Deployment Summary
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🌐 Frontend
URL: http://localhost:3000
Build: .next (optimized production build)
Status: ✅ Running
🔌 Backend API
URL: http://localhost:5000/api
Framework: Flask (Python 3)
Status: ✅ Running
📦 Database
Type: MongoDB
Port: 27017
Status: ✅ Ready
⛓️ Blockchain
Network: Ethereum Mainnet
RPC: Configured in .env
Status: ✅ Ready
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📋 Environment: $ENVIRONMENT
🕐 Deployment Time: $TIMESTAMP
📁 Log File: $LOG_FILE
🎯 Next Steps:
1. Verify both services are accessible
2. Test core functionality
3. Monitor logs for errors
4. Configure domain/DNS if needed
5. Enable SSL/HTTPS if on production
EOF
echo ""
print_status "View detailed logs with:"
print_status " tail -f $LOG_FILE"
echo ""
if command -v pm2 >/dev/null 2>&1; then
print_status "PM2 Status:"
pm2 status
echo ""
fi
print_success "Deployment completed! 🎉"