Repository navigation
Expand file tree
/
Copy pathcicd.yml
More file actions
54 lines (40 loc) Β· 1.53 KB
/
Copy pathcicd.yml
File metadata and controls
54 lines (40 loc) Β· 1.53 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
# note : dont forget to change node-app with your app name
name: Deploy to Azure VM (node-app)
on:
push:
branches:
- main # Trigger deployment only when code is pushed to 'main'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: π§Ύ Checkout Repository
uses: actions/checkout@v3
with:
ref: main
- name: π Setup SSH Agent
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.AZURE_VM_PRIVATE_KEY }}
- name: π Deploy to Azure VM
run: |
ssh -o StrictHostKeyChecking=no azureuser@${{ secrets.AZURE_VM_IP }} << 'EOF'
set -e
echo "[INFO] π Starting deployment on Azure VM at $(date)"
# Move to project directory
cd /home/azureuser/node-app
echo "[INFO] π Pulling latest code from 'main'..."
git fetch origin main
git reset --hard origin/main
echo "[INFO] π¦ Installing dependencies..."
npm ci --legacy-peer-deps || npm install --legacy-peer-deps
echo "[INFO] π οΈ Building TypeScript..."
npx tsc || npm run build
echo "[INFO] π Restarting app using PM2..."
pm2 delete node-app || true
pm2 start dist/index.js --name "node-app"
pm2 save
echo "[INFO] π Reloading Nginx..."
sudo systemctl reload nginx || true
echo "[SUCCESS] β
Deployment completed successfully at $(date)"
EOF