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`) ကို အလိုအလျောက် လုပ်ဆောင်ပေးပါသည်။
name: Production Deploy to VPS
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Deploy to VPS via SSH Action
uses: appleboy/[email protected]
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
script: |
cd /home/deployer/my-web-app
git pull origin main
npm ci --production
npm run build
pm2 reload ecosystem.config.cjs --env production
Command ရှင်းလင်းချက် (ဖတ်ရှုရန် နှိပ်ပါ)
ဤ GitHub Actions pipeline သည် စက္ကန့်ပိုင်းအတွင်း Zero-Downtime ဖြင့် Code အသစ်ကို production သို့ အလိုအလျောက် လွှင့်တင်ပေးပါသည်။
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 ထဲတွင် ထည့်သွင်းသိမ်းဆည်းရသည့် အဓိက အကြောင်းရင်းမှာ အဘယ်နည်း?