#10 of 11Automated CI/CD with GitHub Actions to VPS
AdvancedDevOps & CI/CD⏱️ 12 min

Automated CI/CD with GitHub Actions to VPS

GitHub Actions ဖြင့် Git Push လုပ်ရုံဖြင့် VPS ပေါ် အလိုအလျောက် Deploy နည်း

Build a production CI/CD pipeline using GitHub Actions, SSH Secrets, and automated PM2 / Docker reloads on git push.

Developer များအနေဖြင့် Server ထဲသို့ manual SSH ဝင်စရာမလိုတော့ဘဲ main branch သို့ git push လုပ်လိုက်သည်နှင့် Test စစ်ကာ ဆာဗာပေါ် auto-deploy ဖြစ်စေမည့် pipeline။

1. Continuous Deployment Pipeline Architecture

Git Push မှ Production သို့ ရောက်ရှိသွားပုံ အဆင့်ဆင့်

Developer က `git push origin main` ပြုလုပ်သည်နှင့် GitHub Actions Runner စက်ကလေး ပွင့်လာပြီး Unit Tests များကို စစ်ဆေးပါမည်။

Tests အားလုံး အောင်မြင်ပါက GitHub Secrets တွင် သိမ်းဆည်းထားသော SSH Private Key ကို အသုံးပြုကာ VPS သို့ လုံခြုံစွာ ဝင်ရောက်ပြီး `git pull`, `npm install`, `npm run build` နှင့် `pm2 reload` (သို့မဟုတ် `docker compose up -d`) ကို အလိုအလျောက် လုပ်ဆောင်ပေးပါသည်။

.github/workflows/deploy.yml
yaml
1 $ name: Production Deploy to VPS
2 $
3 $ on:
4 $ push:
5 $ branches: [ main ]
6 $
7 $ jobs:
8 $ deploy:
9 $ runs-on: ubuntu-latest
10 $ steps:
11 $ - name: Checkout Code
12 $ uses: actions/checkout@v4
13 $
14 $ - name: Deploy to VPS via SSH Action
15 $ uses: appleboy/[email protected]
16 $ with:
17 $ host: ${{ secrets.VPS_HOST }}
18 $ username: ${{ secrets.VPS_USERNAME }}
19 $ key: ${{ secrets.VPS_SSH_KEY }}
20 $ port: ${{ secrets.VPS_PORT }}
21 $ script: |
22 $ cd /home/deployer/my-web-app
23 $ git pull origin main
24 $ npm ci --production
25 $ npm run build
26 $ pm2 reload ecosystem.config.cjs --env production
💡Command ရှင်းလင်းချက် (ဖတ်ရှုရန် နှိပ်ပါ)

ဤ GitHub Actions pipeline သည် စက္ကန့်ပိုင်းအတွင်း Zero-Downtime ဖြင့် Code အသစ်ကို production သို့ အလိုအလျောက် လွှင့်တင်ပေးပါသည်။

Knowledge Check

Why should production server credentials (SSH Private Keys, IPs, DB passwords) be stored in GitHub Secrets rather than committed into git repository?

ဆာဗာ၏ SSH Private Key, IP Address နှင့် လျှို့ဝှက် passwords များကို git repository ထဲတွင် မရေးဘဲ GitHub Secrets ထဲတွင် ထည့်သွင်းသိမ်းဆည်းရသည့် အဓိက အကြောင်းရင်းမှာ အဘယ်နည်း?