@codeharbor/agent-playbook 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/package.json +5 -2
- package/skills/api-designer/README.md +36 -0
- package/skills/api-designer/SKILL.md +232 -0
- package/skills/api-designer/references/graphql-patterns.md +12 -0
- package/skills/api-designer/references/rest-patterns.md +17 -0
- package/skills/api-designer/scripts/generate_api.py +87 -0
- package/skills/api-designer/scripts/validate_api.py +48 -0
- package/skills/api-documenter/README.md +41 -0
- package/skills/api-documenter/SKILL.md +209 -0
- package/skills/api-documenter/references/examples/README.md +3 -0
- package/skills/api-documenter/references/examples/openapi-example.yaml +10 -0
- package/skills/api-documenter/references/openapi-template.yaml +5 -0
- package/skills/api-documenter/scripts/generate_openapi.py +84 -0
- package/skills/api-documenter/scripts/validate_openapi.py +45 -0
- package/skills/architecting-solutions/README.md +22 -0
- package/skills/architecting-solutions/SKILL.md +459 -0
- package/skills/auto-trigger/README.md +23 -0
- package/skills/auto-trigger/SKILL.md +183 -0
- package/skills/code-reviewer/README.md +59 -0
- package/skills/code-reviewer/SKILL.md +220 -0
- package/skills/code-reviewer/references/checklist.md +80 -0
- package/skills/code-reviewer/references/patterns.md +226 -0
- package/skills/code-reviewer/references/security.md +88 -0
- package/skills/code-reviewer/scripts/review_checklist.py +191 -0
- package/skills/commit-helper/README.md +58 -0
- package/skills/commit-helper/SKILL.md +159 -0
- package/skills/commit-helper/references/conventional-commits.md +68 -0
- package/skills/commit-helper/references/examples.md +125 -0
- package/skills/commit-helper/references/scopes.md +49 -0
- package/skills/commit-helper/scripts/validate_commit.py +70 -0
- package/skills/create-pr/README.md +182 -0
- package/skills/create-pr/SKILL.md +340 -0
- package/skills/debugger/README.md +53 -0
- package/skills/debugger/SKILL.md +239 -0
- package/skills/debugger/references/checklist.md +7 -0
- package/skills/debugger/references/errors.md +6 -0
- package/skills/debugger/references/patterns.md +5 -0
- package/skills/debugger/scripts/debug_report.py +77 -0
- package/skills/deployment-engineer/README.md +40 -0
- package/skills/deployment-engineer/SKILL.md +242 -0
- package/skills/deployment-engineer/references/kubernetes.md +23 -0
- package/skills/deployment-engineer/references/monitoring.md +14 -0
- package/skills/deployment-engineer/references/pipelines.md +12 -0
- package/skills/deployment-engineer/scripts/generate_deploy.py +72 -0
- package/skills/deployment-engineer/scripts/validate_deploy.py +46 -0
- package/skills/documentation-engineer/README.md +41 -0
- package/skills/documentation-engineer/SKILL.md +164 -0
- package/skills/documentation-engineer/references/api-template.md +22 -0
- package/skills/documentation-engineer/references/readme-template.md +25 -0
- package/skills/documentation-engineer/references/style-guide.md +13 -0
- package/skills/documentation-engineer/scripts/generate_docs.py +68 -0
- package/skills/documentation-engineer/scripts/validate_docs.py +46 -0
- package/skills/figma-designer/README.md +222 -0
- package/skills/figma-designer/SKILL.md +407 -0
- package/skills/figma-designer/references/example-output.md +86 -0
- package/skills/performance-engineer/README.md +42 -0
- package/skills/performance-engineer/SKILL.md +236 -0
- package/skills/performance-engineer/references/checklist.md +6 -0
- package/skills/performance-engineer/references/monitoring.md +5 -0
- package/skills/performance-engineer/references/optimization.md +7 -0
- package/skills/performance-engineer/scripts/perf_report.py +64 -0
- package/skills/performance-engineer/scripts/profile.py +63 -0
- package/skills/planning-with-files/README.md +27 -0
- package/skills/planning-with-files/SKILL.md +103 -0
- package/skills/prd-implementation-precheck/README.md +97 -0
- package/skills/prd-implementation-precheck/SKILL.md +112 -0
- package/skills/prd-planner/README.md +102 -0
- package/skills/prd-planner/SKILL.md +449 -0
- package/skills/prd-planner/references/edge-case-analysis.md +111 -0
- package/skills/qa-expert/README.md +37 -0
- package/skills/qa-expert/SKILL.md +225 -0
- package/skills/qa-expert/references/gates.md +11 -0
- package/skills/qa-expert/references/metrics.md +6 -0
- package/skills/qa-expert/references/strategy.md +11 -0
- package/skills/qa-expert/scripts/coverage_analysis.py +61 -0
- package/skills/qa-expert/scripts/generate_test_plan.py +68 -0
- package/skills/refactoring-specialist/README.md +37 -0
- package/skills/refactoring-specialist/SKILL.md +283 -0
- package/skills/refactoring-specialist/references/checklist.md +6 -0
- package/skills/refactoring-specialist/references/smells.md +6 -0
- package/skills/refactoring-specialist/references/techniques.md +6 -0
- package/skills/security-auditor/README.md +48 -0
- package/skills/security-auditor/SKILL.md +256 -0
- package/skills/security-auditor/references/checklist.md +7 -0
- package/skills/security-auditor/references/owasp.md +12 -0
- package/skills/security-auditor/references/remediation.md +7 -0
- package/skills/security-auditor/scripts/find_secrets.py +58 -0
- package/skills/security-auditor/scripts/security_audit.py +64 -0
- package/skills/self-improving-agent/README.md +136 -0
- package/skills/self-improving-agent/SKILL.md +407 -0
- package/skills/self-improving-agent/hooks/post-bash.sh +10 -0
- package/skills/self-improving-agent/hooks/pre-tool.sh +10 -0
- package/skills/self-improving-agent/hooks/session-end.sh +4 -0
- package/skills/self-improving-agent/memory/semantic-patterns.json +288 -0
- package/skills/self-improving-agent/references/appendix.md +131 -0
- package/skills/self-improving-agent/templates/correction-template.md +11 -0
- package/skills/self-improving-agent/templates/pattern-template.md +15 -0
- package/skills/self-improving-agent/templates/validation-template.md +14 -0
- package/skills/session-logger/README.md +50 -0
- package/skills/session-logger/SKILL.md +156 -0
- package/skills/skill-router/README.md +155 -0
- package/skills/skill-router/SKILL.md +215 -0
- package/skills/test-automator/README.md +41 -0
- package/skills/test-automator/SKILL.md +202 -0
- package/skills/test-automator/references/best-practices.md +6 -0
- package/skills/test-automator/references/examples/README.md +3 -0
- package/skills/test-automator/references/examples/unit-test-example.md +8 -0
- package/skills/test-automator/references/mocking.md +5 -0
- package/skills/test-automator/scripts/coverage_report.py +59 -0
- package/skills/test-automator/scripts/generate_test.py +66 -0
- package/skills/workflow-orchestrator/README.md +20 -0
- package/skills/workflow-orchestrator/SKILL.md +342 -0
- package/src/cli.js +107 -20
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: debugger
|
|
3
|
+
description: Advanced debugging specialist for diagnosing and resolving code issues. Use when user encounters bugs, errors, unexpected behavior, or mentions debugging.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Bash, Grep, Glob
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Debugger
|
|
8
|
+
|
|
9
|
+
An advanced debugging specialist that helps diagnose and resolve code issues systematically.
|
|
10
|
+
|
|
11
|
+
## When This Skill Activates
|
|
12
|
+
|
|
13
|
+
Activates when you:
|
|
14
|
+
- Report an error or bug
|
|
15
|
+
- Mention "debug this" or "help debug"
|
|
16
|
+
- Describe unexpected behavior
|
|
17
|
+
- Ask why something isn't working
|
|
18
|
+
|
|
19
|
+
## Debugging Process
|
|
20
|
+
|
|
21
|
+
### Phase 1: Understand the Problem
|
|
22
|
+
|
|
23
|
+
1. **Reproduce the issue**
|
|
24
|
+
- What are the exact steps to reproduce?
|
|
25
|
+
- What is the expected behavior?
|
|
26
|
+
- What is the actual behavior?
|
|
27
|
+
- What error messages appear?
|
|
28
|
+
|
|
29
|
+
2. **Gather context**
|
|
30
|
+
```bash
|
|
31
|
+
# Check recent changes
|
|
32
|
+
git log --oneline -10
|
|
33
|
+
|
|
34
|
+
# Check error logs
|
|
35
|
+
tail -f logs/error.log
|
|
36
|
+
|
|
37
|
+
# Check environment
|
|
38
|
+
env | grep -i debug
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Phase 2: Isolate the Issue
|
|
42
|
+
|
|
43
|
+
1. **Locate the error source**
|
|
44
|
+
- Stack trace analysis
|
|
45
|
+
- Error code lookup
|
|
46
|
+
- Log correlation
|
|
47
|
+
|
|
48
|
+
2. **Narrow down scope**
|
|
49
|
+
- Binary search (comment out half)
|
|
50
|
+
- Minimize reproduction case
|
|
51
|
+
- Identify affected components
|
|
52
|
+
|
|
53
|
+
### Phase 3: Analyze the Root Cause
|
|
54
|
+
|
|
55
|
+
#### Common Error Categories
|
|
56
|
+
|
|
57
|
+
| Category | Symptoms | Investigation Steps |
|
|
58
|
+
|----------|----------|---------------------|
|
|
59
|
+
| **Null/Undefined** | "Cannot read X of undefined" | Trace the variable origin |
|
|
60
|
+
| **Type Errors** | "X is not a function" | Check actual vs expected type |
|
|
61
|
+
| **Async Issues** | Race conditions, timing | Check promise handling, async/await |
|
|
62
|
+
| **State Issues** | Stale data, wrong state | Trace state mutations |
|
|
63
|
+
| **Network** | Timeouts, connection refused | Check endpoints, CORS, auth |
|
|
64
|
+
| **Environment** | Works locally, not in prod | Compare env vars, versions |
|
|
65
|
+
| **Memory** | Leaks, OOM | Profile memory usage |
|
|
66
|
+
| **Concurrency** | Deadlocks, race conditions | Check locks, shared state |
|
|
67
|
+
|
|
68
|
+
### Phase 4: Form Hypotheses
|
|
69
|
+
|
|
70
|
+
For each potential cause:
|
|
71
|
+
1. Form a hypothesis
|
|
72
|
+
2. Create a test to validate
|
|
73
|
+
3. Run the test
|
|
74
|
+
4. Confirm or reject
|
|
75
|
+
|
|
76
|
+
### Phase 5: Fix and Verify
|
|
77
|
+
|
|
78
|
+
1. **Implement the fix**
|
|
79
|
+
2. **Add logging if needed**
|
|
80
|
+
3. **Test the fix**
|
|
81
|
+
4. **Add regression test**
|
|
82
|
+
|
|
83
|
+
## Debugging Commands
|
|
84
|
+
|
|
85
|
+
### General Debugging
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Find recently modified files
|
|
89
|
+
find . -type f -mtime -1 -name "*.js" -o -name "*.ts" -o -name "*.py"
|
|
90
|
+
|
|
91
|
+
# Grep for error patterns
|
|
92
|
+
grep -r "ERROR\|FATAL\|Exception" logs/
|
|
93
|
+
|
|
94
|
+
# Search for suspicious patterns
|
|
95
|
+
grep -r "TODO\|FIXME\|XXX" src/
|
|
96
|
+
|
|
97
|
+
# Check for console.log left in code
|
|
98
|
+
grep -r "console\.log\|debugger" src/
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Language-Specific
|
|
102
|
+
|
|
103
|
+
**JavaScript/TypeScript:**
|
|
104
|
+
```bash
|
|
105
|
+
# Run with debug output
|
|
106
|
+
NODE_DEBUG=* node app.js
|
|
107
|
+
|
|
108
|
+
# Check syntax
|
|
109
|
+
node -c file.js
|
|
110
|
+
|
|
111
|
+
# Run tests in debug mode
|
|
112
|
+
npm test -- --inspect-brk
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Python:**
|
|
116
|
+
```bash
|
|
117
|
+
# Run with pdb
|
|
118
|
+
python -m pdb script.py
|
|
119
|
+
|
|
120
|
+
# Check syntax
|
|
121
|
+
python -m py_compile script.py
|
|
122
|
+
|
|
123
|
+
# Verbose mode
|
|
124
|
+
python -v script.py
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Go:**
|
|
128
|
+
```bash
|
|
129
|
+
# Race detection
|
|
130
|
+
go run -race main.go
|
|
131
|
+
|
|
132
|
+
# Debug build
|
|
133
|
+
go build -gcflags="-N -l"
|
|
134
|
+
|
|
135
|
+
# Profile
|
|
136
|
+
go test -cpuprofile=cpu.prof
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Common Debugging Patterns
|
|
140
|
+
|
|
141
|
+
### Pattern 1: Divide and Conquer
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
# When you don't know where the bug is:
|
|
145
|
+
def process():
|
|
146
|
+
step1()
|
|
147
|
+
step2()
|
|
148
|
+
step3()
|
|
149
|
+
step4()
|
|
150
|
+
|
|
151
|
+
# Comment out half:
|
|
152
|
+
def process():
|
|
153
|
+
step1()
|
|
154
|
+
# step2()
|
|
155
|
+
# step3()
|
|
156
|
+
# step4()
|
|
157
|
+
|
|
158
|
+
# If bug disappears, uncomment half of commented:
|
|
159
|
+
def process():
|
|
160
|
+
step1()
|
|
161
|
+
step2()
|
|
162
|
+
# step3()
|
|
163
|
+
# step4()
|
|
164
|
+
|
|
165
|
+
# Continue until you isolate the bug
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Pattern 2: Add Logging
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// Before (mysterious failure):
|
|
172
|
+
async function getUser(id: string) {
|
|
173
|
+
const user = await db.find(id);
|
|
174
|
+
return transform(user);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// After (with logging):
|
|
178
|
+
async function getUser(id: string) {
|
|
179
|
+
console.log('[DEBUG] getUser called with id:', id);
|
|
180
|
+
const user = await db.find(id);
|
|
181
|
+
console.log('[DEBUG] db.find returned:', user);
|
|
182
|
+
const result = transform(user);
|
|
183
|
+
console.log('[DEBUG] transform returned:', result);
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Pattern 3: Minimal Reproduction
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// Complex code with bug:
|
|
192
|
+
function processBatch(items, options) {
|
|
193
|
+
// 100 lines of complex logic
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Create minimal reproduction:
|
|
197
|
+
function processBatch(items, options) {
|
|
198
|
+
console.log('Items:', items.length);
|
|
199
|
+
console.log('Options:', options);
|
|
200
|
+
// Test with minimal data
|
|
201
|
+
return processBatch([items[0]], options);
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Error Message Analysis
|
|
206
|
+
|
|
207
|
+
### Common Error Messages
|
|
208
|
+
|
|
209
|
+
| Error | Likely Cause | Solution |
|
|
210
|
+
|-------|--------------|----------|
|
|
211
|
+
| `Cannot read property 'X' of undefined` | Accessing property on null/undefined | Add null check, use optional chaining |
|
|
212
|
+
| `X is not a function` | Wrong type, shadowing | Check typeof, verify import |
|
|
213
|
+
| `Unexpected token` | Syntax error | Check line before error, validate syntax |
|
|
214
|
+
| `Module not found` | Import path wrong | Check relative path, verify file exists |
|
|
215
|
+
| `EADDRINUSE` | Port already in use | Kill existing process, use different port |
|
|
216
|
+
| `Connection refused` | Service not running | Start service, check port |
|
|
217
|
+
| `Timeout` | Request too slow | Increase timeout, check network |
|
|
218
|
+
|
|
219
|
+
## Debugging Checklist
|
|
220
|
+
|
|
221
|
+
- [ ] I can reproduce the issue consistently
|
|
222
|
+
- [ ] I have identified the exact error location
|
|
223
|
+
- [ ] I understand the root cause
|
|
224
|
+
- [ ] I have a proposed fix
|
|
225
|
+
- [ ] The fix doesn't break existing functionality
|
|
226
|
+
- [ ] I've added a test to prevent regression
|
|
227
|
+
|
|
228
|
+
## Scripts
|
|
229
|
+
|
|
230
|
+
Generate a debug report:
|
|
231
|
+
```bash
|
|
232
|
+
python scripts/debug_report.py <error-message>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## References
|
|
236
|
+
|
|
237
|
+
- `references/checklist.md` - Debugging checklist
|
|
238
|
+
- `references/patterns.md` - Common debugging patterns
|
|
239
|
+
- `references/errors.md` - Error message reference
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# Template generator for debug report.
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import argparse
|
|
6
|
+
import textwrap
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def write_output(path: Path, content: str, force: bool) -> bool:
|
|
10
|
+
if path.exists() and not force:
|
|
11
|
+
print(f"{path} already exists (use --force to overwrite)")
|
|
12
|
+
return False
|
|
13
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
14
|
+
path.write_text(content, encoding="utf-8")
|
|
15
|
+
return True
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> int:
|
|
19
|
+
parser = argparse.ArgumentParser(description="Generate a debug report.")
|
|
20
|
+
parser.add_argument("--output", default="debug-report.md", help="Output file path")
|
|
21
|
+
parser.add_argument("--name", default="example", help="Issue summary")
|
|
22
|
+
parser.add_argument("--owner", default="team", help="Owning team")
|
|
23
|
+
parser.add_argument("--force", action="store_true", help="Overwrite existing file")
|
|
24
|
+
args = parser.parse_args()
|
|
25
|
+
|
|
26
|
+
content = textwrap.dedent(
|
|
27
|
+
f"""\
|
|
28
|
+
# Debug Report
|
|
29
|
+
|
|
30
|
+
## Summary
|
|
31
|
+
{args.name}
|
|
32
|
+
|
|
33
|
+
## Ownership
|
|
34
|
+
- Owner: {args.owner}
|
|
35
|
+
- On-call: TBD
|
|
36
|
+
|
|
37
|
+
## Environment
|
|
38
|
+
- Service version:
|
|
39
|
+
- Region:
|
|
40
|
+
- Traffic level:
|
|
41
|
+
|
|
42
|
+
## Steps to Reproduce
|
|
43
|
+
1. Step one
|
|
44
|
+
2. Step two
|
|
45
|
+
|
|
46
|
+
## Expected vs Actual
|
|
47
|
+
- Expected:
|
|
48
|
+
- Actual:
|
|
49
|
+
|
|
50
|
+
## Logs and Evidence
|
|
51
|
+
- Attach logs, screenshots, traces
|
|
52
|
+
|
|
53
|
+
## Root Cause
|
|
54
|
+
TBD
|
|
55
|
+
|
|
56
|
+
## Fix
|
|
57
|
+
- Code changes
|
|
58
|
+
- Configuration changes
|
|
59
|
+
|
|
60
|
+
## Regression Tests
|
|
61
|
+
- Add or update tests
|
|
62
|
+
|
|
63
|
+
## Follow-ups
|
|
64
|
+
- Monitoring improvements
|
|
65
|
+
- Runbook updates
|
|
66
|
+
"""
|
|
67
|
+
).strip() + "\n"
|
|
68
|
+
|
|
69
|
+
output = Path(args.output)
|
|
70
|
+
if not write_output(output, content, args.force):
|
|
71
|
+
return 1
|
|
72
|
+
print(f"Wrote {output}")
|
|
73
|
+
return 0
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Deployment Engineer
|
|
2
|
+
|
|
3
|
+
> A Claude Code skill for CI/CD pipelines and deployment automation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
This skill is part of the [agent-playbook](https://github.com/Charon-Fan/agent-playbook) collection.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
You: Set up CI/CD
|
|
13
|
+
You: Create deployment pipeline
|
|
14
|
+
You: Configure GitHub Actions
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Deployment Strategies
|
|
18
|
+
|
|
19
|
+
| Strategy | Description |
|
|
20
|
+
|----------|-------------|
|
|
21
|
+
| **Blue-Green** | Zero downtime, instant rollback |
|
|
22
|
+
| **Rolling** | Gradual replacement |
|
|
23
|
+
| **Canary** | Test with small traffic first |
|
|
24
|
+
|
|
25
|
+
## Scripts
|
|
26
|
+
|
|
27
|
+
Generate deployment config:
|
|
28
|
+
```bash
|
|
29
|
+
python scripts/generate_deploy.py <environment>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Validate deployment:
|
|
33
|
+
```bash
|
|
34
|
+
python scripts/validate_deploy.py
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Resources
|
|
38
|
+
|
|
39
|
+
- [GitHub Actions Docs](https://docs.github.com/en/actions)
|
|
40
|
+
- [CI/CD Best Practices](https://www.atlassian.com/continuous-delivery/principles/continuous-integration-vs-delivery-vs-deployment)
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deployment-engineer
|
|
3
|
+
description: Deployment automation specialist for CI/CD pipelines and infrastructure. Use when setting up deployment, configuring CI/CD, or managing releases.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Bash, Grep, Glob
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Deployment Engineer
|
|
8
|
+
|
|
9
|
+
Specialist in deployment automation, CI/CD pipelines, and infrastructure management.
|
|
10
|
+
|
|
11
|
+
## When This Skill Activates
|
|
12
|
+
|
|
13
|
+
Activates when you:
|
|
14
|
+
- Set up deployment pipeline
|
|
15
|
+
- Configure CI/CD
|
|
16
|
+
- Manage releases
|
|
17
|
+
- Automate infrastructure
|
|
18
|
+
|
|
19
|
+
## CI/CD Pipeline
|
|
20
|
+
|
|
21
|
+
### Pipeline Stages
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
stages:
|
|
25
|
+
- lint
|
|
26
|
+
- test
|
|
27
|
+
- build
|
|
28
|
+
- security
|
|
29
|
+
- deploy-dev
|
|
30
|
+
- deploy-staging
|
|
31
|
+
- deploy-production
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### GitHub Actions Example
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
name: CI/CD
|
|
38
|
+
|
|
39
|
+
on:
|
|
40
|
+
push:
|
|
41
|
+
branches: [main, develop]
|
|
42
|
+
pull_request:
|
|
43
|
+
branches: [main]
|
|
44
|
+
|
|
45
|
+
jobs:
|
|
46
|
+
lint:
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v4
|
|
50
|
+
- uses: actions/setup-node@v4
|
|
51
|
+
with:
|
|
52
|
+
node-version: '20'
|
|
53
|
+
- run: npm ci
|
|
54
|
+
- run: npm run lint
|
|
55
|
+
|
|
56
|
+
test:
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
needs: lint
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v4
|
|
61
|
+
- uses: actions/setup-node@v4
|
|
62
|
+
- run: npm ci
|
|
63
|
+
- run: npm test
|
|
64
|
+
|
|
65
|
+
build:
|
|
66
|
+
runs-on: ubuntu-latest
|
|
67
|
+
needs: test
|
|
68
|
+
steps:
|
|
69
|
+
- uses: actions/checkout@v4
|
|
70
|
+
- uses: actions/setup-node@v4
|
|
71
|
+
- run: npm ci
|
|
72
|
+
- run: npm run build
|
|
73
|
+
- uses: actions/upload-artifact@v4
|
|
74
|
+
with:
|
|
75
|
+
name: build
|
|
76
|
+
path: dist/
|
|
77
|
+
|
|
78
|
+
deploy-production:
|
|
79
|
+
runs-on: ubuntu-latest
|
|
80
|
+
needs: build
|
|
81
|
+
if: github.ref == 'refs/heads/main'
|
|
82
|
+
environment: production
|
|
83
|
+
steps:
|
|
84
|
+
- uses: actions/checkout@v4
|
|
85
|
+
- uses: actions/download-artifact@v4
|
|
86
|
+
with:
|
|
87
|
+
name: build
|
|
88
|
+
path: dist/
|
|
89
|
+
- run: npm run deploy
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Deployment Strategies
|
|
93
|
+
|
|
94
|
+
### 1. Blue-Green Deployment
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
┌─────────┐
|
|
98
|
+
│ Load │
|
|
99
|
+
│ Balancer│
|
|
100
|
+
└────┬────┘
|
|
101
|
+
│
|
|
102
|
+
┌────────┴────────┐
|
|
103
|
+
│ Switch │
|
|
104
|
+
├────────┬────────┤
|
|
105
|
+
▼ ▼ ▼
|
|
106
|
+
┌─────┐ ┌─────┐ ┌─────┐
|
|
107
|
+
│Blue │ │Green│ │ │
|
|
108
|
+
└─────┘ └─────┘ └─────┘
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 2. Rolling Deployment
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
┌─────────────────────────────────────┐
|
|
115
|
+
│ v1 v1 v1 v1 v1 v1 v1 v1 v1 │ → Old
|
|
116
|
+
│ v2 v2 v2 v2 v2 v2 v2 v2 v2 │ → New
|
|
117
|
+
└─────────────────────────────────────┘
|
|
118
|
+
▲ ▲
|
|
119
|
+
│ │
|
|
120
|
+
Start End
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 3. Canary Deployment
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
┌──────────────────────────────────────┐
|
|
127
|
+
│ v1 v1 v1 v1 v1 v1 v1 v1 v1 v1 │ → Old
|
|
128
|
+
│ v2 v2 v2 v2 │ → Canary (5%)
|
|
129
|
+
└──────────────────────────────────────┘
|
|
130
|
+
|
|
131
|
+
Monitor metrics, then:
|
|
132
|
+
│ v1 v1 v1 v1 │ → Old (50%)
|
|
133
|
+
│ v2 v2 v2 v2 v2 v2 v2 v2 v2 v2 │ → New (50%)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Environment Configuration
|
|
137
|
+
|
|
138
|
+
### Environment Variables
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Production
|
|
142
|
+
NODE_ENV=production
|
|
143
|
+
DATABASE_URL=postgresql://...
|
|
144
|
+
API_KEY=sk-...
|
|
145
|
+
SENTRY_DSN=https://example.com/123
|
|
146
|
+
|
|
147
|
+
# Development
|
|
148
|
+
NODE_ENV=development
|
|
149
|
+
DATABASE_URL=postgresql://localhost:5432/dev
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Configuration Management
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// config/production.ts
|
|
156
|
+
export default {
|
|
157
|
+
database: {
|
|
158
|
+
url: process.env.DATABASE_URL,
|
|
159
|
+
poolSize: 20,
|
|
160
|
+
},
|
|
161
|
+
redis: {
|
|
162
|
+
url: process.env.REDIS_URL,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Health Checks
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// GET /health
|
|
171
|
+
app.get('/health', (req, res) => {
|
|
172
|
+
const health = {
|
|
173
|
+
status: 'ok',
|
|
174
|
+
timestamp: new Date().toISOString(),
|
|
175
|
+
checks: {
|
|
176
|
+
database: 'ok',
|
|
177
|
+
redis: 'ok',
|
|
178
|
+
external_api: 'ok',
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
if (Object.values(health.checks).some(v => v !== 'ok')) {
|
|
183
|
+
health.status = 'degraded';
|
|
184
|
+
return res.status(503).json(health);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
res.json(health);
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Rollback Strategy
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
# Kubernetes
|
|
195
|
+
kubectl rollout undo deployment/app
|
|
196
|
+
|
|
197
|
+
# Docker
|
|
198
|
+
docker-compose down
|
|
199
|
+
docker-compose up -d --scale app=<previous-version>
|
|
200
|
+
|
|
201
|
+
# Git
|
|
202
|
+
git revert HEAD
|
|
203
|
+
git push
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Monitoring & Logging
|
|
207
|
+
|
|
208
|
+
### Metrics to Track
|
|
209
|
+
|
|
210
|
+
- Deployment frequency
|
|
211
|
+
- Lead time for changes
|
|
212
|
+
- Mean time to recovery (MTTR)
|
|
213
|
+
- Change failure rate
|
|
214
|
+
|
|
215
|
+
### Logging
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
// Structured logging
|
|
219
|
+
logger.info('Deployment started', {
|
|
220
|
+
version: process.env.VERSION,
|
|
221
|
+
environment: process.env.NODE_ENV,
|
|
222
|
+
timestamp: new Date().toISOString(),
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Scripts
|
|
227
|
+
|
|
228
|
+
Generate deployment config:
|
|
229
|
+
```bash
|
|
230
|
+
python scripts/generate_deploy.py <environment>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Validate deployment:
|
|
234
|
+
```bash
|
|
235
|
+
python scripts/validate_deploy.py
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## References
|
|
239
|
+
|
|
240
|
+
- `references/pipelines.md` - CI/CD pipeline examples
|
|
241
|
+
- `references/kubernetes.md` - K8s deployment configs
|
|
242
|
+
- `references/monitoring.md` - Monitoring setup
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Kubernetes Deployment Skeleton
|
|
2
|
+
|
|
3
|
+
```yaml
|
|
4
|
+
apiVersion: apps/v1
|
|
5
|
+
kind: Deployment
|
|
6
|
+
metadata:
|
|
7
|
+
name: app
|
|
8
|
+
spec:
|
|
9
|
+
replicas: 2
|
|
10
|
+
selector:
|
|
11
|
+
matchLabels:
|
|
12
|
+
app: app
|
|
13
|
+
template:
|
|
14
|
+
metadata:
|
|
15
|
+
labels:
|
|
16
|
+
app: app
|
|
17
|
+
spec:
|
|
18
|
+
containers:
|
|
19
|
+
- name: app
|
|
20
|
+
image: example/app:latest
|
|
21
|
+
ports:
|
|
22
|
+
- containerPort: 8080
|
|
23
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Monitoring Checklist
|
|
2
|
+
|
|
3
|
+
## Metrics
|
|
4
|
+
- Request rate
|
|
5
|
+
- Error rate
|
|
6
|
+
- Latency (p50/p95/p99)
|
|
7
|
+
|
|
8
|
+
## Logs
|
|
9
|
+
- Structured logs with request IDs
|
|
10
|
+
- Include error context and stack traces
|
|
11
|
+
|
|
12
|
+
## Alerts
|
|
13
|
+
- Define SLO-based alerts
|
|
14
|
+
- Avoid noisy, low-signal alerts
|