-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-deploy.sh.example
More file actions
55 lines (42 loc) · 1.91 KB
/
Copy pathauto-deploy.sh.example
File metadata and controls
55 lines (42 loc) · 1.91 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
#!/bin/bash
# auto-deploy.sh - Production deployment script for pr-review-checker
set -e # Exit on error
LOG_FILE="/home/aswin/pr-review-checker/deploy.log"
PROJECT_DIR="/home/aswin/pr-review-checker"
APP_NAME="pr-deploy"
echo "$(date): Starting production auto-deployment..." | tee -a "$LOG_FILE"
cd "$PROJECT_DIR"
echo "$(date): 📥 Pulling latest changes from Git..." | tee -a "$LOG_FILE"
git pull origin main 2>&1 | tee -a "$LOG_FILE"
echo "$(date): 📦 Installing root dependencies..." | tee -a "$LOG_FILE"
npm ci 2>&1 | tee -a "$LOG_FILE" || npm install 2>&1 | tee -a "$LOG_FILE"
echo "$(date): 🎨 Installing client dependencies..." | tee -a "$LOG_FILE"
cd client && npm ci 2>&1 | tee -a "$LOG_FILE" || npm install 2>&1 | tee -a "$LOG_FILE"
echo "$(date): 🔨 Building client app..." | tee -a "$LOG_FILE"
npm run build 2>&1 | tee -a "$LOG_FILE"
cd ..
echo "$(date): ⚙️ Installing server dependencies..." | tee -a "$LOG_FILE"
cd server && npm ci 2>&1 | tee -a "$LOG_FILE" || npm install 2>&1 | tee -a "$LOG_FILE"
cd ..
echo "$(date): 🔄 Restarting backend service..." | tee -a "$LOG_FILE"
sudo systemctl restart "$APP_NAME" 2>&1 | tee -a "$LOG_FILE"
echo "$(date): ✅ Deployment completed successfully!" | tee -a "$LOG_FILE"
# Optional: Add health check
echo "$(date): 🔍 Performing health check..." | tee -a "$LOG_FILE"
sleep 5
if curl -f http://localhost:3001/health > /dev/null 2>&1; then
echo "$(date): ✅ Health check passed" | tee -a "$LOG_FILE"
else
echo "❌ Application health check failed!"
echo "🔍 Checking logs..."
# Show recent logs if available
if command -v pm2 &> /dev/null; then
pm2 logs $PM2_APP_NAME --lines 20
fi
exit 1
fi
echo "$(date): ⚠️ Health check failed - service may still be starting" | tee -a "$LOG_FILE"
fi
echo "🎉 Auto-deploy completed successfully!"
echo "📅 Deployment time: $(date)"
echo "🌍 Environment: $DEPLOY_ENV"