CI/CDパイプライン
Bazbiiシステムの継続的インテグレーション・継続的デプロイメントの仕組みを説明します。
CI/CDの概要
パイプラインの構成
コード変更
↓
┌──────────┐
│ Push │
└──────────┘
↓
┌──────────┐
│ Lint │ ← コード品質チェック
└──────────┘
↓
┌──────────┐
│ Build │ ← ビルド
└──────────┘
↓
┌──────────┐
│ Test │ ← テスト実行
└──────────┘
↓
┌──────────┐
│ Deploy │ ← デプロイ(条件付き)
└──────────┘
現在のCI/CD構成
- プラットフォーム: GitHub Actions
- トリガー: Push、Pull Request、手動実行
- デプロイ先: Cloudflare Pages(ドキュメント)
GitHub Actionsワークフロー
ドキュメントデプロイ
ファイル: .github/workflows/deploy-docs.yaml
# トリガー条件
on:
push:
branches: [mvp]
paths:
- 'docs/**'
pull_request:
branches: [mvp]
paths:
- 'docs/**'
workflow_dispatch:
# 実行内容
jobs:
build-and-deploy:
- pnpm install
- pnpm build
- Deploy to Cloudflare Pages
実行タイミング
- Push:
mvpブランチへのpush時(docs変更時のみ) - Pull Request: PR作成・更新時(docs変更時のみ)
- 手動実行:
workflow_dispatchで手動実行可能
パイプラインの拡張予定
バックエンドCI/CD
以下のワークフローを追加予定:
1. Lint & Format
name: Lint and Format
on: [push, pull_request]
jobs:
go-lint:
- go fmt
- go vet
- golangci-lint
proto-lint:
- buf lint
frontend-lint:
- eslint
- prettier --check
2. Build
name: Build
on: [push, pull_request]
jobs:
build:
- Build Go binaries
- Build Docker images
- Build frontend apps
3. Test
name: Test
on: [push, pull_request]
jobs:
test:
- Setup test database
- Run Go tests
- Run frontend tests
- Generate coverage report
4. Deploy (Staging)
name: Deploy to Staging
on:
push:
branches: [develop]
jobs:
deploy:
- Deploy to staging environment
- Run smoke tests
5. Deploy (Production)
name: Deploy to Production
on:
push:
branches: [main]
workflow_dispatch:
jobs:
deploy:
- Deploy to production
- Run smoke tests
- Notify deployment status
ブランチ戦略との連携
ブランチ構成(予定)
main ← 本番環境
↑
develop ← ステージング環境
↑
feature/* ← 機能開発
↑
hotfix/* ← 緊急修正
デプロイタイミング
- feature/*: CI/CD実行(デプロイなし)
- develop: ステージング環境に自動デプロイ
- main: 本番環境に自動デプロイ(承認後)
テスト実行戦略
テストの段階的実行
- 高速テスト: Lint、Unit Tests(すべてのPR)
- 統合テスト: Integration Tests(main/developブランチ)
- E2Eテスト: E2E Tests(本番デプロイ前)
テスト環境
- CI環境: GitHub Actionsランナー
- テストDB: Docker Composeで起動
- テストデータ: 各テストで独立してセットアップ
セキュリティチェック
セキュリティスキャン(予定)
name: Security Scan
on: [push, pull_request]
jobs:
security:
- Dependency vulnerability scan
- Container image scan
- Secret scanning
セキュリティチェック項目
- 依存関係の脆弱性スキャン
- コンテナイメージのスキャン
- シークレットの漏洩チェック
- コードのセキュリティ脆弱性チェック
デプロイメント自動化
Kubernetesデプロイ(予定)
name: Deploy to Kubernetes
on:
push:
branches: [main]
jobs:
deploy:
- Build Docker images
- Push to container registry
- Update Kubernetes manifests
- kubectl apply
- Health check
ロールバック
- デプロイ失敗時の自動ロールバック
- 手動ロールバックコマンド
kubectl rollout undo deployment/gateway
kubectl rollout undo deployment/api
通知・アラート
デプロイ通知(予定)
- 成功時: Slack/メール通知
- 失敗時: エラーログとともに通知
- ロールバック時: ロールバック理由とともに通知
メトリクス連携
- デプロイ後のメトリクス監視
- 異常値検出時のアラート
環境変数とシークレット
シークレット管理
- GitHub Secrets: CI/CDで使用するシークレット
- 環境変数: 環境ごとの設定値
シークレットの使用例
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
KUBECONFIG: ${{ secrets.KUBECONFIG }}
ベストプラクティス
1. 高速なフィードバック
- 軽量なチェックを先に実行
- 並列実行で全体の時間を短縮
2. 失敗時の迅速な対応
- エラー原因を明確に
- 再実行可能なジョブ
3. デプロイの安全性
- 段階的デプロイ
- ヘルスチェックで検証
- ロールバックの容易さ
4. 可視性の確保
- デプロイ状況の可視化
- メトリクス・ログの確認