159 lines
3.7 KiB
Markdown
159 lines
3.7 KiB
Markdown
# CI/CD Optimization Example
|
|
|
|
**Experiment**: bootstrap-007-cicd-pipeline
|
|
**Domain**: CI/CD Pipeline Optimization
|
|
**Iterations**: 5
|
|
**Build Time**: 8min → 3min (62.5% reduction)
|
|
**Reliability**: 75% → 100%
|
|
**Patterns**: 7
|
|
**Tools**: 2
|
|
|
|
Example of applying BAIME to optimize CI/CD pipelines.
|
|
|
|
---
|
|
|
|
## Baseline Metrics
|
|
|
|
**Initial Pipeline**:
|
|
- Build time: 8 min avg (range: 6-12 min)
|
|
- Failure rate: 25% (false positives)
|
|
- No caching
|
|
- Sequential execution
|
|
- Single pipeline for all branches
|
|
|
|
**Problems**:
|
|
1. Slow build times
|
|
2. Flaky tests causing false failures
|
|
3. No parallelization
|
|
4. Cache misses
|
|
5. Redundant steps
|
|
|
|
---
|
|
|
|
## Iteration 1-2: Pipeline Stages Pattern (2.5 hours)
|
|
|
|
**7 Pipeline Patterns Created**:
|
|
|
|
1. **Stage Parallelization**: Run lint/test/build concurrently
|
|
2. **Dependency Caching**: Cache Go modules, npm packages
|
|
3. **Fast-Fail Pattern**: Lint first (30 sec vs 8 min)
|
|
4. **Matrix Testing**: Test multiple Go versions in parallel
|
|
5. **Conditional Execution**: Skip tests if no code changes
|
|
6. **Artifact Reuse**: Build once, test many
|
|
7. **Branch-Specific Pipelines**: Different configs for main/feature branches
|
|
|
|
**Results**:
|
|
- Build time: 8 min → 5 min
|
|
- Failure rate: 25% → 15%
|
|
- V_instance = 0.65, V_meta = 0.58
|
|
|
|
---
|
|
|
|
## Iteration 3-4: Automation & Optimization (3 hours)
|
|
|
|
**Tool 1**: Pipeline Analyzer
|
|
```bash
|
|
# Analyzes GitHub Actions logs
|
|
./scripts/analyze-pipeline.sh
|
|
# Output: Stage durations, failure patterns, cache hit rates
|
|
```
|
|
|
|
**Tool 2**: Config Generator
|
|
```bash
|
|
# Generates optimized pipeline configs
|
|
./scripts/generate-pipeline-config.sh --cache --parallel --fast-fail
|
|
```
|
|
|
|
**Optimizations Applied**:
|
|
- Aggressive caching (modules, build cache)
|
|
- Parallel execution (3 stages concurrent)
|
|
- Smart test selection (only affected tests)
|
|
|
|
**Results**:
|
|
- Build time: 5 min → 3.2 min
|
|
- Reliability: 85% → 98%
|
|
- V_instance = 0.82 ✓, V_meta = 0.75
|
|
|
|
---
|
|
|
|
## Iteration 5: Convergence (1.5 hours)
|
|
|
|
**Final optimizations**:
|
|
- Fine-tuned cache keys
|
|
- Reduced artifact upload (only essentials)
|
|
- Optimized test ordering (fast tests first)
|
|
|
|
**Results**:
|
|
- Build time: 3.2 min → 3.0 min (stable)
|
|
- Reliability: 98% → 100% (10 consecutive green)
|
|
- **V_instance = 0.88** ✓ ✓
|
|
- **V_meta = 0.82** ✓ ✓
|
|
|
|
**CONVERGED** ✅
|
|
|
|
---
|
|
|
|
## Final Pipeline Architecture
|
|
|
|
```yaml
|
|
name: CI
|
|
on: [push, pull_request]
|
|
|
|
jobs:
|
|
fast-checks: # 30 seconds
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- name: Lint
|
|
run: golangci-lint run
|
|
|
|
test: # 2 min (parallel)
|
|
needs: fast-checks
|
|
strategy:
|
|
matrix:
|
|
go-version: [1.20, 1.21]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- uses: actions/setup-go@v2
|
|
with:
|
|
go-version: ${{ matrix.go-version }}
|
|
cache: true
|
|
- name: Test
|
|
run: go test -race ./...
|
|
|
|
build: # 1 min (parallel with test)
|
|
needs: fast-checks
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- uses: actions/setup-go@v2
|
|
with:
|
|
cache: true
|
|
- name: Build
|
|
run: go build ./...
|
|
- uses: actions/upload-artifact@v2
|
|
with:
|
|
name: binaries
|
|
path: bin/
|
|
```
|
|
|
|
**Total Time**: 3 min (fast-checks 0.5min + max(test 2min, build 1min))
|
|
|
|
---
|
|
|
|
## Key Learnings
|
|
|
|
1. **Caching is critical**: 60% time savings
|
|
2. **Fail fast**: Lint first saves 7.5 min on failures
|
|
3. **Parallel > Sequential**: 50% time reduction
|
|
4. **Matrix needs balance**: Too many variants slow down
|
|
5. **Measure everything**: Can't optimize without data
|
|
|
|
**Transferability**: 95% (applies to any CI/CD system)
|
|
|
|
---
|
|
|
|
**Source**: Bootstrap-007 CI/CD Pipeline Optimization
|
|
**Status**: Production-ready, 62.5% build time reduction
|