實戰:GitOps 部署流水線
Vibe Prompt
「幫我建立一個完整的 GitOps 部署流程:GitHub 推送 → CI 建置 Image → Image Updater → ArgoCD 同步 → K8s 部署。」
完整 GitHub Actions
name: Build & Push
on:
push:
branches: [main]
paths-ignore:
- 'k8s/**' # 避免無限循環
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ github.sha }}
ghcr.io/${{ github.repository }}:latest
目錄結構
myapp/
├── .github/workflows/build.yml
├── src/
├── Dockerfile
└── k8s/
├── base/
│ ├── deployment.yaml # image: ghcr.io/myorg/myapp:latest
│ ├── service.yaml
│ └── kustomization.yaml
└── overlays/
└── production/
└── kustomization.yaml
課程總結
GitOps 課程完成!
- ✅ GitOps 核心思想
- ✅ ArgoCD 安裝與管理
- ✅ Kustomize 多環境
- ✅ Image Updater
- ✅ 完整 GitOps 流水線