CI/CD Pipeline¶
Tổng quan¶
CI/CD pipeline tự động hóa quá trình build, test, và deploy cho cả Frontend và Backend.
graph LR
A["Push Code"] --> B["CI: Lint & Test"]
B --> C{Branch?}
C -->|staging| D["Deploy Staging"]
C -->|main| E["Deploy Production"]
C -->|feature/*| F["Preview Only"] Auto-Deploy hiện tại¶
Frontend — Cloudflare Pages¶
| Trigger | Branch | Kết quả |
|---|---|---|
Push to main | main | Deploy lên chienle.dev |
Push to staging | staging | Deploy Preview lên test.chienle.dev |
Push to feature/* | any | Tạo Preview URL (tạm thời) |
Cloudflare Pages tự động build và deploy khi detect push mới trên GitHub.
Backend — Northflank¶
| Service | Branch | Domain |
|---|---|---|
| Production | main | api.chienle.dev |
| Staging | staging | api-test.chienle.dev |
Northflank auto-rebuild container khi có push mới.
GitHub Actions (Khuyến nghị)¶
Chưa triển khai
Phần này là khuyến nghị cho tương lai. Hiện tại deploy bằng auto-deploy của Cloudflare Pages + Northflank.
Recommended Workflow¶
# .github/workflows/ci.yml
name: CI Pipeline
on:
push:
branches: [develop, staging, main]
pull_request:
branches: [develop]
jobs:
# ─── Backend Tests ─────────────────────
backend-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: |
cd backend
pip install -r requirements.txt
pip install ruff pytest
ruff check .
backend-test:
runs-on: ubuntu-latest
needs: backend-lint
services:
postgres:
image: postgres:14
env:
POSTGRES_PASSWORD: test
POSTGRES_DB: test_db
ports: ['5432:5432']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: |
cd backend
pip install -r requirements.txt
pip install pytest
pytest
# ─── Frontend Tests ────────────────────
frontend-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
- run: |
cd frontend
npm ci
npm run lint
frontend-build:
runs-on: ubuntu-latest
needs: frontend-lint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
- run: |
cd frontend
npm ci
npm run build
Rollback¶
Frontend (Cloudflare Pages)¶
- Vào Cloudflare → Project → Deployments
- Tìm deployment trước đó (đang hoạt động tốt)
- Nhấn
...→ Rollback to this deploy
Backend (Northflank)¶
- Vào Northflank → Service → Deployments
- Chọn build trước đó
- Nhấn Redeploy
Rollback nhanh
Cả Cloudflare Pages và Northflank đều hỗ trợ rollback instant — không cần rebuild, chỉ switch sang container/build cũ.
Quy trình Deploy hoàn chỉnh¶
graph TD
A["Developer push<br/>feature branch"] --> B["Tạo PR → develop"]
B --> C["CI chạy<br/>lint + test"]
C --> D{CI Pass?}
D -->|❌ Fail| E["Fix & push lại"]
E --> C
D -->|✅ Pass| F["Code Review"]
F --> G["Merge vào develop"]
G --> H["Merge develop → staging"]
H --> I["Auto-deploy Staging"]
I --> J["QA Test trên staging"]
J --> K{Test OK?}
K -->|❌ Fail| L["Tạo bug fix PR"]
L --> B
K -->|✅ Pass| M["Merge staging → main"]
M --> N["Auto-deploy Production"]
N --> O["Verify trên prod"]