Major Changes: - Create PROMPT_BLUEPRINT_V2.md (Claude Code-driven development guide) - Add Argo CD Application configurations (GitOps deployment) - Update CI/CD workflow to comply with GitOps requirements - Create blueprint-checker skill for compliance validation - Add migration-job template for database migrations - Add comprehensive deployment documentation New Files: - PROMPT_BLUEPRINT_V2.md - Production-grade development blueprint - argocd/ - Argo CD Application configurations (dev/prod) - .claude/skills/blueprint-checker/ - Compliance checking tool - deployment/helm/gold-template/templates/migration-job.yaml - PreSync migration job - deployment/helm/gold-template/values-infra-db.yaml - Infra database integration - docs/deployment/ - Deployment guides and best practices - OPTIMIZATION-SUMMARY.md - Optimization work summary Updated Files: - .github/workflows/complete-cicd.yml - GitOps-compliant deployment - backend/main.py - Enhanced observability (metrics, structured logs) - requirements.txt - Add prometheus-client - deployment/helm/gold-template/values-orbstack.yaml - Metrics configuration Blueprint Compliance: 83% (19/23 checks passed) Related Issues: - #26 Configure Alembic database migration - #27 Integrate OpenTelemetry tracing - #28 Create Grafana Dashboard 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Argo CD Applications
本目录包含 Gold Template 项目的 Argo CD Application 配置。
📁 文件说明
| 文件 | 用途 | 环境 | 自动同步 | 自动修复 |
|---|---|---|---|---|
application.yaml |
通用配置(本地开发) | local | ✅ | ✅ |
application-dev.yaml |
开发环境 | development | ✅ | ✅ |
application-prod.yaml |
生产环境 | production | ✅ | ❌ |
🚀 快速开始
前提条件
-
Argo CD 已安装
# 检查 Argo CD 状态 kubectl get pods -n argocd -
配置 Argo CD CLI
# 安装 CLI brew install argocd # macOS # 或 curl -sSL -o argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64 # 登录 argocd login localhost:8080 --insecure # 用户名: admin # 密码: kubectl get secret -n argocd argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 --decode
部署应用
方法 1:kubectl apply
# 部署本地开发环境
kubectl apply -f argocd/application.yaml
# 部署开发环境
kubectl apply -f argocd/application-dev.yaml
# 部署生产环境
kubectl apply -f argocd/application-prod.yaml
方法 2:argocd CLI
# 从文件创建
argocd app create -f argocd/application-prod.yaml
# 直接创建(不使用文件)
argocd app create gold-template-prod \
--repo https://github.com/yourusername/gold-template.git \
--path deployment/helm/gold-template \
--dest-server https://kubernetes.default.svc \
--dest-namespace gold-template-prod \
--helm-set image.tag=v1.0.0 \
--sync-policy automated \
--auto-prune \
--self-heal
方法 3:Argo CD UI
- 访问 Argo CD UI:
kubectl port-forward -n argocd svc/argocd-server 8080:443 - 打开
https://localhost:8080 - 点击 "New App"
- 填写配置或上传 YAML 文件
🔄 常用操作
查看应用状态
# 列出所有应用
argocd app list
# 查看详细信息
argocd app get gold-template-prod
# 查看同步历史
argocd app history gold-template-prod
同步应用
# 手动同步
argocd app sync gold-template-prod
# 强制同步(忽略差异)
argocd app sync gold-template-prod --force
# 仅同步特定资源
argocd app sync gold-template-prod --resource Deployment:gold-template-prod
# Dry run(预览变更)
argocd app sync gold-template-prod --dry-run --prune
回滚应用
# 查看历史版本
argocd app history gold-template-prod
# 回滚到指定版本
argocd app rollback gold-template-prod <revision-id>
# 或通过 Git revert
git revert <commit-hash>
git push
# Argo CD 会自动检测并同步
删除应用
# 删除应用(保留资源)
argocd app delete gold-template-prod --cascade=false
# 删除应用和资源
argocd app delete gold-template-prod
# 使用 kubectl
kubectl delete -f argocd/application-prod.yaml
⚙️ 配置说明
自动同步策略
开发环境(application-dev.yaml):
syncPolicy:
automated:
prune: true # 自动删除多余资源
selfHeal: true # 自动修复手动变更
生产环境(application-prod.yaml):
syncPolicy:
automated:
prune: true
selfHeal: false # 禁用自动修复,需人工审查
同步波次(Sync Waves)
PreSync Hook(数据库迁移)在应用部署之前执行:
# migration-job.yaml
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
argocd.argoproj.io/sync-wave: "1"
执行顺序:
Wave 1: PreSync Hook (数据库迁移)
↓
Wave 2: 应用部署 (Deployment, Service, etc.)
↓
Wave 3: PostSync Hook (健康检查、通知)
参数覆盖
方法 1:通过 values 文件(推荐)
# application-prod.yaml
helm:
valueFiles:
- values.yaml
- values-prod.yaml
方法 2:通过 parameters
helm:
parameters:
- name: image.tag
value: "v1.0.0"
- name: replicaCount
value: "3"
方法 3:通过 CLI
argocd app set gold-template-prod --helm-set image.tag=v1.0.1
🔧 故障排查
应用无法同步
# 查看详细错误
argocd app get gold-template-prod
# 查看事件
kubectl get events -n gold-template-prod --sort-by='.lastTimestamp'
# 查看 Pod 日志
kubectl logs -n gold-template-prod -l app.kubernetes.io/name=gold-template
资源冲突
# 查看差异
argocd app diff gold-template-prod
# 强制覆盖
argocd app sync gold-template-prod --force
# 刷新缓存
argocd app get gold-template-prod --refresh --hard-refresh
PreSync Hook 失败
# 查看 migration job 日志
kubectl logs -n gold-template-prod job/gold-template-prod-migration
# 手动运行迁移(调试)
kubectl run -it --rm migration-debug \
--image=localhost:5000/gold-template:latest \
--restart=Never \
-n gold-template-prod \
-- alembic upgrade head
🔒 安全最佳实践
1. Git 仓库访问
如果使用私有仓库,配置 Git 凭证:
# 通过 HTTPS + Token
argocd repo add https://github.com/yourusername/gold-template.git \
--username <username> \
--password <token>
# 通过 SSH Key
argocd repo add [email protected]:yourusername/gold-template.git \
--ssh-private-key-path ~/.ssh/id_rsa
2. Secret 管理
禁止在 Git 中存储敏感信息。使用以下方案:
- 方案 1:Sealed Secrets
- 方案 2:External Secrets Operator
- 方案 3:Vault
3. RBAC 配置
限制 Argo CD 的访问权限:
# AppProject 配置
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: gold-template-project
namespace: argocd
spec:
destinations:
- namespace: gold-template-*
server: https://kubernetes.default.svc
sourceRepos:
- https://github.com/yourusername/gold-template.git
📊 监控与告警
1. Prometheus Metrics
Argo CD 自动暴露 Prometheus metrics:
# 应用同步状态
argocd_app_info{name="gold-template-prod"}
# 同步失败次数
argocd_app_sync_total{phase="Failed",name="gold-template-prod"}
2. Notifications
配置 Slack 通知(已在 application-prod.yaml 中配置):
annotations:
notifications.argoproj.io/subscribe.on-sync-succeeded.slack: "gold-template-notifications"
notifications.argoproj.io/subscribe.on-sync-failed.slack: "gold-template-alerts"
📚 相关文档
🤝 贡献指南
如需修改 Argo CD 配置:
- 修改
argocd/*.yaml文件 - 提交 PR
- Code Review
- 合并后,Argo CD 会自动检测并应用变更
维护者:DevOps Team 最后更新:2025-12-30