-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
76 lines (57 loc) · 1.82 KB
/
deploy.sh
File metadata and controls
76 lines (57 loc) · 1.82 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
#!/bin/bash
chmod +x deploy.sh
# Deployment Configuration
SERVER_USER="root"
SERVER_IP="68.183.91.119" # Replace with your server IP
TARGET_DIR="/var/www/inspectra" # Remote deployment directory
LOCAL_DIR="." # Local project directory
# Install dependencies and build project
echo "🔧 Building Next.js project..."
yarn install --frozen-lockfile
yarn build
if [ $? -ne 0 ]; then
echo "❌ Build failed! Exiting..."
rm $ENV_FILE
exit 1
fi
# Prompt the user for a commit message
read -p "Enter commit message: " commitMessage
# Stage all the files
git add .
# Commit the changes with the provided message
git commit -m "$commitMessage"
# Push the commit to the origin remote repository and HEAD branch
git push origin HEAD
# Create deployment package
echo "📦 Packaging deployment files..."
DEPLOY_FILES=(".next" "public" "package.json" "yarn.lock" $ENV_FILE)
tar -czf deployment.tar.gz "${DEPLOY_FILES[@]}"
# Upload to server
echo "🚀 Uploading to server..."
scp deployment.tar.gz $SERVER_USER@$SERVER_IP:$TARGET_DIR
if [ $? -ne 0 ]; then
echo "❌ Upload failed! Exiting..."
rm deployment.tar.gz
exit 1
fi
# Remote deployment commands
echo "🎛 Executing remote deployment steps..."
ssh $SERVER_USER@$SERVER_IP << SSHCOMMANDS
cd $TARGET_DIR
echo "📦 Extracting deployment files..."
tar -xzf deployment.tar.gz
rm deployment.tar.gz
echo "🔧 Installing dependencies..."
yarn install --production --frozen-lockfile
echo "♻ Restarting application..."
pm2 restart whatsapi
echo "♻ Restarting application..."
pm2 delete inspectra || true
pm2 start yarn --name inspectra -- start
echo "📝 PM2 Logs:"
pm2 logs inspectra --lines 50
SSHCOMMANDS
# Cleanup
echo "🧹 Cleaning up..."
rm deployment.tar.gz
echo "✅ Deployment completed successfully!"