CI/CDパイプライン
24.1. CircleCI設定
24.1.1. .circleci/config.yml 全体例
yaml
version: 2.1
orbs:
node: circleci/node@6.3
maven: circleci/maven@1.4
executors:
java-executor:
docker:
- image: cimg/openjdk:21.0
working_directory: ~/project/backend
node-executor:
docker:
- image: cimg/node:22.0
working_directory: ~/project/frontend
jobs:
# ===== バックエンド =====
backend-lint:
executor: java-executor
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- maven-{{ checksum "pom.xml" }}
- run:
name: フォーマット検証
command: mvn spotless:check
- save_cache:
key: maven-{{ checksum "pom.xml" }}
paths:
- ~/.m2
backend-test:
executor: java-executor
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- maven-{{ checksum "pom.xml" }}
- run:
name: テスト実行
command: mvn test
- run:
name: カバレッジレポート
command: mvn jacoco:report
- store_test_results:
path: target/surefire-reports
- store_artifacts:
path: target/site/jacoco
backend-build:
executor: java-executor
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- maven-{{ checksum "pom.xml" }}
- run:
name: ビルド
command: mvn package -DskipTests
- persist_to_workspace:
root: ~/project
paths:
- backend/target/*.jar
backend-security-scan:
executor: java-executor
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- maven-{{ checksum "pom.xml" }}
- run:
name: OWASP依存関係スキャン
command: mvn dependency-check:check
- store_artifacts:
path: target/dependency-check-report.html
# ===== フロントエンド =====
frontend-lint:
executor: node-executor
steps:
- checkout:
path: ~/project
- run:
name: 依存関係インストール
command: yarn install --frozen-lockfile
- run:
name: ESLint検証
command: yarn lint
- run:
name: Prettier検証
command: yarn format:check
frontend-build:
executor: node-executor
steps:
- checkout:
path: ~/project
- run:
name: 依存関係インストール
command: yarn install --frozen-lockfile
- run:
name: 型チェック
command: yarn type-check
- run:
name: ビルド
command: yarn build
- persist_to_workspace:
root: ~/project
paths:
- frontend/dist
# ===== デプロイ =====
deploy:
docker:
- image: cimg/base:current
steps:
- attach_workspace:
at: ~/project
- run:
name: デプロイ
command: echo "デプロイスクリプト実行"
workflows:
build-and-deploy:
jobs:
# リント(並列)
- backend-lint
- frontend-lint
# テスト(リント通過後)
- backend-test:
requires:
- backend-lint
# ビルド(リント通過後、並列)
- backend-build:
requires:
- backend-test
- frontend-build:
requires:
- frontend-lint
# セキュリティスキャン(週1回または手動)
- backend-security-scan:
requires:
- backend-lint
filters:
branches:
only: main
# デプロイ(mainブランチのみ)
- deploy:
requires:
- backend-build
- frontend-build
filters:
branches:
only: main24.2. パイプラインステージ
24.2.1. 実行フロー
┌─────────────────────────────────────────────────┐
│ Push / PR │
└──────────────────────┬──────────────────────────┘
│
┌───────────┴───────────┐
▼ ▼
backend-lint frontend-lint
│ │
▼ │
backend-test │
│ │
▼ ▼
backend-build frontend-build
│ │
└───────────┬───────────┘
│
▼
deploy
(main only)24.2.2. ステージ別役割
| ステージ | 役割 | 失敗時 |
|---|---|---|
| リント | コードフォーマット、ESLintルール検証 | PRマージブロック |
| テスト | 単体/統合テスト実行、カバレッジ測定 | PRマージブロック |
| ビルド | コンパイル、バンドリング | PRマージブロック |
| セキュリティスキャン | 依存関係の脆弱性検査 | 警告レポート生成 |
| デプロイ | ビルド成果物のデプロイ | ロールバック手順実行 |
24.3. 環境別デプロイ戦略
24.3.1. デプロイ条件
| 環境 | トリガー | 自動/手動 |
|---|---|---|
| dev | main マージ時 | 自動 |
| staging | main マージ + 手動承認 | 手動 |
| production | リリースタグ(v*)作成時 | 手動承認後に自動 |
24.3.2. ロールバック手順
プロダクションデプロイ後に問題が発生した場合、以下の手順に従います。
- 問題確認および影響範囲の把握
- 前バージョンのタグで再デプロイ
- ホットフィックスブランチの作成および修正
- 緊急PRレビュー → マージ → 再デプロイ
24.3.3. 必須スクリプト
フロントエンドの package.json に以下のスクリプトを含めます。
json
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"format:check": "prettier --check .",
"type-check": "vue-tsc --noEmit"
}
}