-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (40 loc) · 1.39 KB
/
deploy.yml
File metadata and controls
50 lines (40 loc) · 1.39 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
# .github/workflows/deploy.yml
name: Auto Deploy to Production VPS
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository Code
uses: actions/checkout@v4
- name: Deploy and Restart Service via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Starting deployment on VPS..."
DEPLOY_DIR=/var/www/sdn-be
APP_NAME="My_Node_API"
PM2_PATH="/usr/local/bin/pm2"
cd $DEPLOY_DIR
# 1. Kéo code mới nhất từ Git
git pull origin main
# 2. Cài đặt dependencies
npm install --omit=dev
# 3. Khởi động lại ứng dụng
if $PM2_PATH list | grep -q $APP_NAME; then
$PM2_PATH reload $APP_NAME --update-env
else
$PM2_PATH start index.js --name $APP_NAME --update-env
fi
# 4. Lưu trạng thái PM2 và KHÔNG DÙNG pm2 logs
echo "Deployment finished and service restarted successfully."
$PM2_PATH save
# 🔥 BUỘC PHIÊN SSH PHẢI KẾT THÚC
exit