-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathdeploy-server.sh
More file actions
executable file
·36 lines (31 loc) · 1.16 KB
/
deploy-server.sh
File metadata and controls
executable file
·36 lines (31 loc) · 1.16 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
#!/bin/sh
set -e # Exit immediately if a command fails.
# Load environment variables: .env (defaults) followed by .env.local (overrides)
[ -f .env ] && set -a && source .env && set +a
[ -f .env.local ] && set -a && source .env.local && set +a
echo "🚀 Deploying server to ${REMOTE_HOST}..."
# 1. Use rsync to sync the current directory (.) to the remote destination.
rsync -avz --delete \
--exclude '/node_modules' \
--exclude '.env' \
--exclude '._*' \
--exclude '.DS_Store' \
--exclude '*.local' \
--exclude 'users.*' \
--exclude '.git' \
./server/ "${REMOTE_SSH_HOST}:${REMOTE_SERVER_DIR}/"
# 2. SSH into the server to install dependencies and reload the app.
LC_ALL=C ssh "${REMOTE_SSH_HOST}" "
set -e
# Load NVM
export NVM_DIR=\"\$HOME/.nvm\"
[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\"
echo 'Connected to server, running post-deploy commands...'
cd ${REMOTE_SERVER_DIR}
echo 'Installing/updating production dependencies...'
npm install --omit=dev --no-fund
echo 'Reloading pm2 process...'
pm2 reload ecosystem.config.js
echo '✅ Deployment finished on server.'
"
echo "✅ Server deployment script finished."