@h1dr0n/skill-pool 0.1.0
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/LICENSE +21 -0
- package/README.md +296 -0
- package/bin/cli.js +157 -0
- package/package.json +41 -0
- package/skills/api/agents/backend-specialist.md +69 -0
- package/skills/api/agents/database-optimizer.md +176 -0
- package/skills/api/manifest.yaml +20 -0
- package/skills/api/rules/auth-security.md +45 -0
- package/skills/api/skills/api-patterns/SKILL.md +81 -0
- package/skills/api/skills/api-patterns/api-style.md +42 -0
- package/skills/api/skills/api-patterns/auth.md +24 -0
- package/skills/api/skills/api-patterns/documentation.md +26 -0
- package/skills/api/skills/api-patterns/graphql.md +41 -0
- package/skills/api/skills/api-patterns/rate-limiting.md +31 -0
- package/skills/api/skills/api-patterns/response.md +37 -0
- package/skills/api/skills/api-patterns/rest.md +40 -0
- package/skills/api/skills/api-patterns/scripts/api_validator.py +211 -0
- package/skills/api/skills/api-patterns/security-testing.md +122 -0
- package/skills/api/skills/api-patterns/trpc.md +41 -0
- package/skills/api/skills/api-patterns/versioning.md +22 -0
- package/skills/api/skills/database-patterns.md +126 -0
- package/skills/api/skills/deployment-patterns.md +105 -0
- package/skills/api/skills/docker-patterns.md +135 -0
- package/skills/common/agents/code-reviewer.md +78 -0
- package/skills/common/agents/planner.md +80 -0
- package/skills/common/agents/security-reviewer.md +82 -0
- package/skills/common/agents/software-architect.md +81 -0
- package/skills/common/manifest.yaml +25 -0
- package/skills/common/rules/coding-style.md +39 -0
- package/skills/common/rules/git-workflow.md +33 -0
- package/skills/common/rules/security.md +25 -0
- package/skills/common/skills/architecture/SKILL.md +55 -0
- package/skills/common/skills/architecture/context-discovery.md +43 -0
- package/skills/common/skills/architecture/examples.md +94 -0
- package/skills/common/skills/architecture/pattern-selection.md +68 -0
- package/skills/common/skills/architecture/patterns-reference.md +50 -0
- package/skills/common/skills/architecture/trade-off-analysis.md +77 -0
- package/skills/common/skills/brainstorming/SKILL.md +163 -0
- package/skills/common/skills/brainstorming/dynamic-questioning.md +350 -0
- package/skills/common/skills/clean-code.md +99 -0
- package/skills/common/skills/code-review-checklist.md +86 -0
- package/skills/common/skills/plan-writing/SKILL.md +152 -0
- package/skills/common/skills/skill-feedback.md +94 -0
- package/skills/common/skills/tdd-workflow.md +130 -0
- package/skills/common/skills/verification-loop.md +112 -0
- package/skills/cpp/agents/cpp-build-resolver.md +90 -0
- package/skills/cpp/agents/cpp-reviewer.md +72 -0
- package/skills/cpp/manifest.yaml +15 -0
- package/skills/cpp/skills/cpp-coding-standards.md +722 -0
- package/skills/cpp/skills/cpp-testing.md +323 -0
- package/skills/devops/agents/devops-automator.md +376 -0
- package/skills/devops/agents/sre.md +90 -0
- package/skills/devops/manifest.yaml +20 -0
- package/skills/devops/skills/deployment-patterns.md +427 -0
- package/skills/devops/skills/deployment-procedures/SKILL.md +241 -0
- package/skills/devops/skills/docker-patterns.md +364 -0
- package/skills/devops/skills/e2e-testing.md +326 -0
- package/skills/devops/skills/github-ops.md +144 -0
- package/skills/django/manifest.yaml +16 -0
- package/skills/django/skills/django-patterns.md +734 -0
- package/skills/django/skills/django-security.md +593 -0
- package/skills/django/skills/django-tdd.md +729 -0
- package/skills/django/skills/django-verification.md +469 -0
- package/skills/dotnet/agents/csharp-reviewer.md +101 -0
- package/skills/dotnet/manifest.yaml +14 -0
- package/skills/dotnet/skills/csharp-testing.md +321 -0
- package/skills/dotnet/skills/dotnet-patterns.md +321 -0
- package/skills/go/agents/code-reviewer.md +76 -0
- package/skills/go/agents/go-build-resolver.md +94 -0
- package/skills/go/agents/go-reviewer.md +76 -0
- package/skills/go/manifest.yaml +17 -0
- package/skills/go/rules/go-style.md +55 -0
- package/skills/go/skills/golang-patterns.md +674 -0
- package/skills/go/skills/golang-testing.md +720 -0
- package/skills/java/agents/java-build-resolver.md +153 -0
- package/skills/java/agents/java-reviewer.md +92 -0
- package/skills/java/manifest.yaml +18 -0
- package/skills/java/skills/java-coding-standards.md +147 -0
- package/skills/java/skills/jpa-patterns.md +151 -0
- package/skills/java/skills/springboot-patterns.md +314 -0
- package/skills/java/skills/springboot-security.md +272 -0
- package/skills/kotlin/agents/kotlin-build-resolver.md +118 -0
- package/skills/kotlin/agents/kotlin-reviewer.md +159 -0
- package/skills/kotlin/manifest.yaml +17 -0
- package/skills/kotlin/skills/kotlin-coroutines-flows.md +284 -0
- package/skills/kotlin/skills/kotlin-patterns.md +711 -0
- package/skills/kotlin/skills/kotlin-testing.md +824 -0
- package/skills/laravel/manifest.yaml +15 -0
- package/skills/laravel/skills/laravel-patterns.md +409 -0
- package/skills/laravel/skills/laravel-security.md +279 -0
- package/skills/laravel/skills/laravel-tdd.md +277 -0
- package/skills/laravel/skills/laravel-verification.md +173 -0
- package/skills/mobile/agents/dart-build-resolver.md +201 -0
- package/skills/mobile/agents/flutter-reviewer.md +243 -0
- package/skills/mobile/manifest.yaml +19 -0
- package/skills/mobile/skills/android-clean-architecture.md +339 -0
- package/skills/mobile/skills/dart-flutter-patterns.md +563 -0
- package/skills/mobile/skills/swiftui-patterns.md +259 -0
- package/skills/nestjs/manifest.yaml +13 -0
- package/skills/nestjs/skills/nestjs-patterns.md +230 -0
- package/skills/perl/manifest.yaml +13 -0
- package/skills/perl/skills/perl-patterns.md +504 -0
- package/skills/perl/skills/perl-security.md +503 -0
- package/skills/perl/skills/perl-testing.md +475 -0
- package/skills/python/agents/python-reviewer.md +98 -0
- package/skills/python/manifest.yaml +18 -0
- package/skills/python/rules/python-style.md +69 -0
- package/skills/python/skills/python-patterns/SKILL.md +441 -0
- package/skills/python/skills/python-patterns.md +90 -0
- package/skills/python/skills/python-testing.md +81 -0
- package/skills/rust/agents/rust-build-resolver.md +148 -0
- package/skills/rust/agents/rust-reviewer.md +94 -0
- package/skills/rust/manifest.yaml +16 -0
- package/skills/rust/rules/rust-style.md +107 -0
- package/skills/rust/skills/rust-patterns.md +499 -0
- package/skills/rust/skills/rust-testing.md +500 -0
- package/skills/security/agents/accessibility-auditor.md +316 -0
- package/skills/security/agents/security-reviewer.md +108 -0
- package/skills/security/manifest.yaml +19 -0
- package/skills/security/skills/red-team-tactics/SKILL.md +199 -0
- package/skills/security/skills/security-bounty-hunter.md +99 -0
- package/skills/security/skills/security-review.md +495 -0
- package/skills/security/skills/security-scan.md +165 -0
- package/skills/security/skills/vulnerability-scanner/SKILL.md +276 -0
- package/skills/security/skills/vulnerability-scanner/checklists.md +121 -0
- package/skills/security/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
- package/skills/swift/manifest.yaml +16 -0
- package/skills/swift/skills/swift-actor-persistence.md +142 -0
- package/skills/swift/skills/swift-concurrency.md +216 -0
- package/skills/swift/skills/swift-protocol-di-testing.md +190 -0
- package/skills/swift/skills/swiftui-patterns.md +259 -0
- package/skills/unity/agents/game-designer.md +167 -0
- package/skills/unity/agents/unity-architect.md +52 -0
- package/skills/unity/agents/unity-editor-tool-developer.md +310 -0
- package/skills/unity/agents/unity-multiplayer-engineer.md +321 -0
- package/skills/unity/agents/unity-shader-graph-artist.md +269 -0
- package/skills/unity/manifest.yaml +21 -0
- package/skills/unity/rules/csharp-patterns.md +48 -0
- package/skills/unity/rules/unity-specific.md +53 -0
- package/skills/unity/skills/systematic-debugging.md +92 -0
- package/skills/unity/skills/unity-architecture.md +173 -0
- package/skills/unreal/agents/level-designer.md +208 -0
- package/skills/unreal/agents/technical-artist.md +229 -0
- package/skills/unreal/agents/unreal-multiplayer-architect.md +313 -0
- package/skills/unreal/agents/unreal-systems-engineer.md +310 -0
- package/skills/unreal/agents/unreal-technical-artist.md +256 -0
- package/skills/unreal/agents/unreal-world-builder.md +273 -0
- package/skills/unreal/manifest.yaml +21 -0
- package/skills/unreal/skills/unreal-patterns.md +183 -0
- package/skills/web/agents/frontend-specialist.md +71 -0
- package/skills/web/agents/ui-designer.md +383 -0
- package/skills/web/agents/ux-architect.md +469 -0
- package/skills/web/manifest.yaml +22 -0
- package/skills/web/rules/accessibility.md +54 -0
- package/skills/web/rules/css-performance.md +52 -0
- package/skills/web/skills/e2e-testing.md +132 -0
- package/skills/web/skills/frontend-design/SKILL.md +452 -0
- package/skills/web/skills/frontend-design/animation-guide.md +331 -0
- package/skills/web/skills/frontend-design/color-system.md +311 -0
- package/skills/web/skills/frontend-design/decision-trees.md +418 -0
- package/skills/web/skills/frontend-design/motion-graphics.md +306 -0
- package/skills/web/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/skills/web/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/skills/web/skills/frontend-design/typography-system.md +345 -0
- package/skills/web/skills/frontend-design/ux-psychology.md +1116 -0
- package/skills/web/skills/frontend-design/visual-effects.md +383 -0
- package/skills/web/skills/react-nextjs.md +135 -0
- package/skills/web/skills/tailwind-patterns/SKILL.md +269 -0
- package/src/adapters/antigravity.js +164 -0
- package/src/adapters/claude.js +188 -0
- package/src/adapters/cursor.js +161 -0
- package/src/adapters/index.js +67 -0
- package/src/adapters/windsurf.js +158 -0
- package/src/commands/add.js +266 -0
- package/src/commands/create.js +127 -0
- package/src/commands/diff.js +78 -0
- package/src/commands/info.js +88 -0
- package/src/commands/init.js +224 -0
- package/src/commands/install.js +90 -0
- package/src/commands/list.js +54 -0
- package/src/commands/remove.js +101 -0
- package/src/commands/targets.js +32 -0
- package/src/commands/update.js +57 -0
- package/src/core/manifest.js +57 -0
- package/src/core/plugins.js +86 -0
- package/src/core/resolver.js +84 -0
- package/src/core/tracker.js +49 -0
- package/src/utils/fs.js +80 -0
- package/src/utils/git.js +52 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deployment-procedures
|
|
3
|
+
description: Production deployment principles and decision-making. Safe deployment workflows, rollback strategies, and verification. Teaches thinking, not scripts.
|
|
4
|
+
allowed-tools: Read, Glob, Grep, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Deployment Procedures
|
|
8
|
+
|
|
9
|
+
> Deployment principles and decision-making for safe production releases.
|
|
10
|
+
> **Learn to THINK, not memorize scripts.**
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## ⚠️ How to Use This Skill
|
|
15
|
+
|
|
16
|
+
This skill teaches **deployment principles**, not bash scripts to copy.
|
|
17
|
+
|
|
18
|
+
- Every deployment is unique
|
|
19
|
+
- Understand the WHY behind each step
|
|
20
|
+
- Adapt procedures to your platform
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 1. Platform Selection
|
|
25
|
+
|
|
26
|
+
### Decision Tree
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
What are you deploying?
|
|
30
|
+
│
|
|
31
|
+
├── Static site / JAMstack
|
|
32
|
+
│ └── Vercel, Netlify, Cloudflare Pages
|
|
33
|
+
│
|
|
34
|
+
├── Simple web app
|
|
35
|
+
│ ├── Managed → Railway, Render, Fly.io
|
|
36
|
+
│ └── Control → VPS + PM2/Docker
|
|
37
|
+
│
|
|
38
|
+
├── Microservices
|
|
39
|
+
│ └── Container orchestration
|
|
40
|
+
│
|
|
41
|
+
└── Serverless
|
|
42
|
+
└── Edge functions, Lambda
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Each Platform Has Different Procedures
|
|
46
|
+
|
|
47
|
+
| Platform | Deployment Method |
|
|
48
|
+
|----------|------------------|
|
|
49
|
+
| **Vercel/Netlify** | Git push, auto-deploy |
|
|
50
|
+
| **Railway/Render** | Git push or CLI |
|
|
51
|
+
| **VPS + PM2** | SSH + manual steps |
|
|
52
|
+
| **Docker** | Image push + orchestration |
|
|
53
|
+
| **Kubernetes** | kubectl apply |
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 2. Pre-Deployment Principles
|
|
58
|
+
|
|
59
|
+
### The 4 Verification Categories
|
|
60
|
+
|
|
61
|
+
| Category | What to Check |
|
|
62
|
+
|----------|--------------|
|
|
63
|
+
| **Code Quality** | Tests passing, linting clean, reviewed |
|
|
64
|
+
| **Build** | Production build works, no warnings |
|
|
65
|
+
| **Environment** | Env vars set, secrets current |
|
|
66
|
+
| **Safety** | Backup done, rollback plan ready |
|
|
67
|
+
|
|
68
|
+
### Pre-Deployment Checklist
|
|
69
|
+
|
|
70
|
+
- [ ] All tests passing
|
|
71
|
+
- [ ] Code reviewed and approved
|
|
72
|
+
- [ ] Production build successful
|
|
73
|
+
- [ ] Environment variables verified
|
|
74
|
+
- [ ] Database migrations ready (if any)
|
|
75
|
+
- [ ] Rollback plan documented
|
|
76
|
+
- [ ] Team notified
|
|
77
|
+
- [ ] Monitoring ready
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 3. Deployment Workflow Principles
|
|
82
|
+
|
|
83
|
+
### The 5-Phase Process
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
1. PREPARE
|
|
87
|
+
└── Verify code, build, env vars
|
|
88
|
+
|
|
89
|
+
2. BACKUP
|
|
90
|
+
└── Save current state before changing
|
|
91
|
+
|
|
92
|
+
3. DEPLOY
|
|
93
|
+
└── Execute with monitoring open
|
|
94
|
+
|
|
95
|
+
4. VERIFY
|
|
96
|
+
└── Health check, logs, key flows
|
|
97
|
+
|
|
98
|
+
5. CONFIRM or ROLLBACK
|
|
99
|
+
└── All good? Confirm. Issues? Rollback.
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Phase Principles
|
|
103
|
+
|
|
104
|
+
| Phase | Principle |
|
|
105
|
+
|-------|-----------|
|
|
106
|
+
| **Prepare** | Never deploy untested code |
|
|
107
|
+
| **Backup** | Can't rollback without backup |
|
|
108
|
+
| **Deploy** | Watch it happen, don't walk away |
|
|
109
|
+
| **Verify** | Trust but verify |
|
|
110
|
+
| **Confirm** | Have rollback trigger ready |
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 4. Post-Deployment Verification
|
|
115
|
+
|
|
116
|
+
### What to Verify
|
|
117
|
+
|
|
118
|
+
| Check | Why |
|
|
119
|
+
|-------|-----|
|
|
120
|
+
| **Health endpoint** | Service is running |
|
|
121
|
+
| **Error logs** | No new errors |
|
|
122
|
+
| **Key user flows** | Critical features work |
|
|
123
|
+
| **Performance** | Response times acceptable |
|
|
124
|
+
|
|
125
|
+
### Verification Window
|
|
126
|
+
|
|
127
|
+
- **First 5 minutes**: Active monitoring
|
|
128
|
+
- **15 minutes**: Confirm stable
|
|
129
|
+
- **1 hour**: Final verification
|
|
130
|
+
- **Next day**: Review metrics
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 5. Rollback Principles
|
|
135
|
+
|
|
136
|
+
### When to Rollback
|
|
137
|
+
|
|
138
|
+
| Symptom | Action |
|
|
139
|
+
|---------|--------|
|
|
140
|
+
| Service down | Rollback immediately |
|
|
141
|
+
| Critical errors | Rollback |
|
|
142
|
+
| Performance >50% degraded | Consider rollback |
|
|
143
|
+
| Minor issues | Fix forward if quick |
|
|
144
|
+
|
|
145
|
+
### Rollback Strategy by Platform
|
|
146
|
+
|
|
147
|
+
| Platform | Rollback Method |
|
|
148
|
+
|----------|----------------|
|
|
149
|
+
| **Vercel/Netlify** | Redeploy previous commit |
|
|
150
|
+
| **Railway/Render** | Rollback in dashboard |
|
|
151
|
+
| **VPS + PM2** | Restore backup, restart |
|
|
152
|
+
| **Docker** | Previous image tag |
|
|
153
|
+
| **K8s** | kubectl rollout undo |
|
|
154
|
+
|
|
155
|
+
### Rollback Principles
|
|
156
|
+
|
|
157
|
+
1. **Speed over perfection**: Rollback first, debug later
|
|
158
|
+
2. **Don't compound errors**: One rollback, not multiple changes
|
|
159
|
+
3. **Communicate**: Tell team what happened
|
|
160
|
+
4. **Post-mortem**: Understand why after stable
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 6. Zero-Downtime Deployment
|
|
165
|
+
|
|
166
|
+
### Strategies
|
|
167
|
+
|
|
168
|
+
| Strategy | How It Works |
|
|
169
|
+
|----------|--------------|
|
|
170
|
+
| **Rolling** | Replace instances one by one |
|
|
171
|
+
| **Blue-Green** | Switch traffic between environments |
|
|
172
|
+
| **Canary** | Gradual traffic shift |
|
|
173
|
+
|
|
174
|
+
### Selection Principles
|
|
175
|
+
|
|
176
|
+
| Scenario | Strategy |
|
|
177
|
+
|----------|----------|
|
|
178
|
+
| Standard release | Rolling |
|
|
179
|
+
| High-risk change | Blue-green (easy rollback) |
|
|
180
|
+
| Need validation | Canary (test with real traffic) |
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## 7. Emergency Procedures
|
|
185
|
+
|
|
186
|
+
### Service Down Priority
|
|
187
|
+
|
|
188
|
+
1. **Assess**: What's the symptom?
|
|
189
|
+
2. **Quick fix**: Restart if unclear
|
|
190
|
+
3. **Rollback**: If restart doesn't help
|
|
191
|
+
4. **Investigate**: After stable
|
|
192
|
+
|
|
193
|
+
### Investigation Order
|
|
194
|
+
|
|
195
|
+
| Check | Common Issues |
|
|
196
|
+
|-------|--------------|
|
|
197
|
+
| **Logs** | Errors, exceptions |
|
|
198
|
+
| **Resources** | Disk full, memory |
|
|
199
|
+
| **Network** | DNS, firewall |
|
|
200
|
+
| **Dependencies** | Database, APIs |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 8. Anti-Patterns
|
|
205
|
+
|
|
206
|
+
| ❌ Don't | ✅ Do |
|
|
207
|
+
|----------|-------|
|
|
208
|
+
| Deploy on Friday | Deploy early in week |
|
|
209
|
+
| Rush deployment | Follow the process |
|
|
210
|
+
| Skip staging | Always test first |
|
|
211
|
+
| Deploy without backup | Backup before deploy |
|
|
212
|
+
| Walk away after deploy | Monitor for 15+ min |
|
|
213
|
+
| Multiple changes at once | One change at a time |
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 9. Decision Checklist
|
|
218
|
+
|
|
219
|
+
Before deploying:
|
|
220
|
+
|
|
221
|
+
- [ ] **Platform-appropriate procedure?**
|
|
222
|
+
- [ ] **Backup strategy ready?**
|
|
223
|
+
- [ ] **Rollback plan documented?**
|
|
224
|
+
- [ ] **Monitoring configured?**
|
|
225
|
+
- [ ] **Team notified?**
|
|
226
|
+
- [ ] **Time to monitor after?**
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 10. Best Practices
|
|
231
|
+
|
|
232
|
+
1. **Small, frequent deploys** over big releases
|
|
233
|
+
2. **Feature flags** for risky changes
|
|
234
|
+
3. **Automate** repetitive steps
|
|
235
|
+
4. **Document** every deployment
|
|
236
|
+
5. **Review** what went wrong after issues
|
|
237
|
+
6. **Test rollback** before you need it
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
> **Remember:** Every deployment is a risk. Minimize risk through preparation, not speed.
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: docker-patterns
|
|
3
|
+
description: Docker and Docker Compose patterns for local development, container security, networking, volume strategies, and multi-service orchestration.
|
|
4
|
+
origin: ECC
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Docker Patterns
|
|
8
|
+
|
|
9
|
+
Docker and Docker Compose best practices for containerized development.
|
|
10
|
+
|
|
11
|
+
## When to Activate
|
|
12
|
+
|
|
13
|
+
- Setting up Docker Compose for local development
|
|
14
|
+
- Designing multi-container architectures
|
|
15
|
+
- Troubleshooting container networking or volume issues
|
|
16
|
+
- Reviewing Dockerfiles for security and size
|
|
17
|
+
- Migrating from local dev to containerized workflow
|
|
18
|
+
|
|
19
|
+
## Docker Compose for Local Development
|
|
20
|
+
|
|
21
|
+
### Standard Web App Stack
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
# docker-compose.yml
|
|
25
|
+
services:
|
|
26
|
+
app:
|
|
27
|
+
build:
|
|
28
|
+
context: .
|
|
29
|
+
target: dev # Use dev stage of multi-stage Dockerfile
|
|
30
|
+
ports:
|
|
31
|
+
- "3000:3000"
|
|
32
|
+
volumes:
|
|
33
|
+
- .:/app # Bind mount for hot reload
|
|
34
|
+
- /app/node_modules # Anonymous volume -- preserves container deps
|
|
35
|
+
environment:
|
|
36
|
+
- DATABASE_URL=postgres://postgres:postgres@db:5432/app_dev
|
|
37
|
+
- REDIS_URL=redis://redis:6379/0
|
|
38
|
+
- NODE_ENV=development
|
|
39
|
+
depends_on:
|
|
40
|
+
db:
|
|
41
|
+
condition: service_healthy
|
|
42
|
+
redis:
|
|
43
|
+
condition: service_started
|
|
44
|
+
command: npm run dev
|
|
45
|
+
|
|
46
|
+
db:
|
|
47
|
+
image: postgres:16-alpine
|
|
48
|
+
ports:
|
|
49
|
+
- "5432:5432"
|
|
50
|
+
environment:
|
|
51
|
+
POSTGRES_USER: postgres
|
|
52
|
+
POSTGRES_PASSWORD: postgres
|
|
53
|
+
POSTGRES_DB: app_dev
|
|
54
|
+
volumes:
|
|
55
|
+
- pgdata:/var/lib/postgresql/data
|
|
56
|
+
- ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init.sql
|
|
57
|
+
healthcheck:
|
|
58
|
+
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
59
|
+
interval: 5s
|
|
60
|
+
timeout: 3s
|
|
61
|
+
retries: 5
|
|
62
|
+
|
|
63
|
+
redis:
|
|
64
|
+
image: redis:7-alpine
|
|
65
|
+
ports:
|
|
66
|
+
- "6379:6379"
|
|
67
|
+
volumes:
|
|
68
|
+
- redisdata:/data
|
|
69
|
+
|
|
70
|
+
mailpit: # Local email testing
|
|
71
|
+
image: axllent/mailpit
|
|
72
|
+
ports:
|
|
73
|
+
- "8025:8025" # Web UI
|
|
74
|
+
- "1025:1025" # SMTP
|
|
75
|
+
|
|
76
|
+
volumes:
|
|
77
|
+
pgdata:
|
|
78
|
+
redisdata:
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Development vs Production Dockerfile
|
|
82
|
+
|
|
83
|
+
```dockerfile
|
|
84
|
+
# Stage: dependencies
|
|
85
|
+
FROM node:22-alpine AS deps
|
|
86
|
+
WORKDIR /app
|
|
87
|
+
COPY package.json package-lock.json ./
|
|
88
|
+
RUN npm ci
|
|
89
|
+
|
|
90
|
+
# Stage: dev (hot reload, debug tools)
|
|
91
|
+
FROM node:22-alpine AS dev
|
|
92
|
+
WORKDIR /app
|
|
93
|
+
COPY --from=deps /app/node_modules ./node_modules
|
|
94
|
+
COPY . .
|
|
95
|
+
EXPOSE 3000
|
|
96
|
+
CMD ["npm", "run", "dev"]
|
|
97
|
+
|
|
98
|
+
# Stage: build
|
|
99
|
+
FROM node:22-alpine AS build
|
|
100
|
+
WORKDIR /app
|
|
101
|
+
COPY --from=deps /app/node_modules ./node_modules
|
|
102
|
+
COPY . .
|
|
103
|
+
RUN npm run build && npm prune --production
|
|
104
|
+
|
|
105
|
+
# Stage: production (minimal image)
|
|
106
|
+
FROM node:22-alpine AS production
|
|
107
|
+
WORKDIR /app
|
|
108
|
+
RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001
|
|
109
|
+
USER appuser
|
|
110
|
+
COPY --from=build --chown=appuser:appgroup /app/dist ./dist
|
|
111
|
+
COPY --from=build --chown=appuser:appgroup /app/node_modules ./node_modules
|
|
112
|
+
COPY --from=build --chown=appuser:appgroup /app/package.json ./
|
|
113
|
+
ENV NODE_ENV=production
|
|
114
|
+
EXPOSE 3000
|
|
115
|
+
HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost:3000/health || exit 1
|
|
116
|
+
CMD ["node", "dist/server.js"]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Override Files
|
|
120
|
+
|
|
121
|
+
```yaml
|
|
122
|
+
# docker-compose.override.yml (auto-loaded, dev-only settings)
|
|
123
|
+
services:
|
|
124
|
+
app:
|
|
125
|
+
environment:
|
|
126
|
+
- DEBUG=app:*
|
|
127
|
+
- LOG_LEVEL=debug
|
|
128
|
+
ports:
|
|
129
|
+
- "9229:9229" # Node.js debugger
|
|
130
|
+
|
|
131
|
+
# docker-compose.prod.yml (explicit for production)
|
|
132
|
+
services:
|
|
133
|
+
app:
|
|
134
|
+
build:
|
|
135
|
+
target: production
|
|
136
|
+
restart: always
|
|
137
|
+
deploy:
|
|
138
|
+
resources:
|
|
139
|
+
limits:
|
|
140
|
+
cpus: "1.0"
|
|
141
|
+
memory: 512M
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# Development (auto-loads override)
|
|
146
|
+
docker compose up
|
|
147
|
+
|
|
148
|
+
# Production
|
|
149
|
+
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Networking
|
|
153
|
+
|
|
154
|
+
### Service Discovery
|
|
155
|
+
|
|
156
|
+
Services in the same Compose network resolve by service name:
|
|
157
|
+
```
|
|
158
|
+
# From "app" container:
|
|
159
|
+
postgres://postgres:postgres@db:5432/app_dev # "db" resolves to the db container
|
|
160
|
+
redis://redis:6379/0 # "redis" resolves to the redis container
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Custom Networks
|
|
164
|
+
|
|
165
|
+
```yaml
|
|
166
|
+
services:
|
|
167
|
+
frontend:
|
|
168
|
+
networks:
|
|
169
|
+
- frontend-net
|
|
170
|
+
|
|
171
|
+
api:
|
|
172
|
+
networks:
|
|
173
|
+
- frontend-net
|
|
174
|
+
- backend-net
|
|
175
|
+
|
|
176
|
+
db:
|
|
177
|
+
networks:
|
|
178
|
+
- backend-net # Only reachable from api, not frontend
|
|
179
|
+
|
|
180
|
+
networks:
|
|
181
|
+
frontend-net:
|
|
182
|
+
backend-net:
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Exposing Only What's Needed
|
|
186
|
+
|
|
187
|
+
```yaml
|
|
188
|
+
services:
|
|
189
|
+
db:
|
|
190
|
+
ports:
|
|
191
|
+
- "127.0.0.1:5432:5432" # Only accessible from host, not network
|
|
192
|
+
# Omit ports entirely in production -- accessible only within Docker network
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Volume Strategies
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
volumes:
|
|
199
|
+
# Named volume: persists across container restarts, managed by Docker
|
|
200
|
+
pgdata:
|
|
201
|
+
|
|
202
|
+
# Bind mount: maps host directory into container (for development)
|
|
203
|
+
# - ./src:/app/src
|
|
204
|
+
|
|
205
|
+
# Anonymous volume: preserves container-generated content from bind mount override
|
|
206
|
+
# - /app/node_modules
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Common Patterns
|
|
210
|
+
|
|
211
|
+
```yaml
|
|
212
|
+
services:
|
|
213
|
+
app:
|
|
214
|
+
volumes:
|
|
215
|
+
- .:/app # Source code (bind mount for hot reload)
|
|
216
|
+
- /app/node_modules # Protect container's node_modules from host
|
|
217
|
+
- /app/.next # Protect build cache
|
|
218
|
+
|
|
219
|
+
db:
|
|
220
|
+
volumes:
|
|
221
|
+
- pgdata:/var/lib/postgresql/data # Persistent data
|
|
222
|
+
- ./scripts/init.sql:/docker-entrypoint-initdb.d/init.sql # Init scripts
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Container Security
|
|
226
|
+
|
|
227
|
+
### Dockerfile Hardening
|
|
228
|
+
|
|
229
|
+
```dockerfile
|
|
230
|
+
# 1. Use specific tags (never :latest)
|
|
231
|
+
FROM node:22.12-alpine3.20
|
|
232
|
+
|
|
233
|
+
# 2. Run as non-root
|
|
234
|
+
RUN addgroup -g 1001 -S app && adduser -S app -u 1001
|
|
235
|
+
USER app
|
|
236
|
+
|
|
237
|
+
# 3. Drop capabilities (in compose)
|
|
238
|
+
# 4. Read-only root filesystem where possible
|
|
239
|
+
# 5. No secrets in image layers
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Compose Security
|
|
243
|
+
|
|
244
|
+
```yaml
|
|
245
|
+
services:
|
|
246
|
+
app:
|
|
247
|
+
security_opt:
|
|
248
|
+
- no-new-privileges:true
|
|
249
|
+
read_only: true
|
|
250
|
+
tmpfs:
|
|
251
|
+
- /tmp
|
|
252
|
+
- /app/.cache
|
|
253
|
+
cap_drop:
|
|
254
|
+
- ALL
|
|
255
|
+
cap_add:
|
|
256
|
+
- NET_BIND_SERVICE # Only if binding to ports < 1024
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Secret Management
|
|
260
|
+
|
|
261
|
+
```yaml
|
|
262
|
+
# GOOD: Use environment variables (injected at runtime)
|
|
263
|
+
services:
|
|
264
|
+
app:
|
|
265
|
+
env_file:
|
|
266
|
+
- .env # Never commit .env to git
|
|
267
|
+
environment:
|
|
268
|
+
- API_KEY # Inherits from host environment
|
|
269
|
+
|
|
270
|
+
# GOOD: Docker secrets (Swarm mode)
|
|
271
|
+
secrets:
|
|
272
|
+
db_password:
|
|
273
|
+
file: ./secrets/db_password.txt
|
|
274
|
+
|
|
275
|
+
services:
|
|
276
|
+
db:
|
|
277
|
+
secrets:
|
|
278
|
+
- db_password
|
|
279
|
+
|
|
280
|
+
# BAD: Hardcoded in image
|
|
281
|
+
# ENV API_KEY=sk-proj-xxxxx # NEVER DO THIS
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## .dockerignore
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
node_modules
|
|
288
|
+
.git
|
|
289
|
+
.env
|
|
290
|
+
.env.*
|
|
291
|
+
dist
|
|
292
|
+
coverage
|
|
293
|
+
*.log
|
|
294
|
+
.next
|
|
295
|
+
.cache
|
|
296
|
+
docker-compose*.yml
|
|
297
|
+
Dockerfile*
|
|
298
|
+
README.md
|
|
299
|
+
tests/
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Debugging
|
|
303
|
+
|
|
304
|
+
### Common Commands
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
# View logs
|
|
308
|
+
docker compose logs -f app # Follow app logs
|
|
309
|
+
docker compose logs --tail=50 db # Last 50 lines from db
|
|
310
|
+
|
|
311
|
+
# Execute commands in running container
|
|
312
|
+
docker compose exec app sh # Shell into app
|
|
313
|
+
docker compose exec db psql -U postgres # Connect to postgres
|
|
314
|
+
|
|
315
|
+
# Inspect
|
|
316
|
+
docker compose ps # Running services
|
|
317
|
+
docker compose top # Processes in each container
|
|
318
|
+
docker stats # Resource usage
|
|
319
|
+
|
|
320
|
+
# Rebuild
|
|
321
|
+
docker compose up --build # Rebuild images
|
|
322
|
+
docker compose build --no-cache app # Force full rebuild
|
|
323
|
+
|
|
324
|
+
# Clean up
|
|
325
|
+
docker compose down # Stop and remove containers
|
|
326
|
+
docker compose down -v # Also remove volumes (DESTRUCTIVE)
|
|
327
|
+
docker system prune # Remove unused images/containers
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Debugging Network Issues
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# Check DNS resolution inside container
|
|
334
|
+
docker compose exec app nslookup db
|
|
335
|
+
|
|
336
|
+
# Check connectivity
|
|
337
|
+
docker compose exec app wget -qO- http://api:3000/health
|
|
338
|
+
|
|
339
|
+
# Inspect network
|
|
340
|
+
docker network ls
|
|
341
|
+
docker network inspect <project>_default
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Anti-Patterns
|
|
345
|
+
|
|
346
|
+
```
|
|
347
|
+
# BAD: Using docker compose in production without orchestration
|
|
348
|
+
# Use Kubernetes, ECS, or Docker Swarm for production multi-container workloads
|
|
349
|
+
|
|
350
|
+
# BAD: Storing data in containers without volumes
|
|
351
|
+
# Containers are ephemeral -- all data lost on restart without volumes
|
|
352
|
+
|
|
353
|
+
# BAD: Running as root
|
|
354
|
+
# Always create and use a non-root user
|
|
355
|
+
|
|
356
|
+
# BAD: Using :latest tag
|
|
357
|
+
# Pin to specific versions for reproducible builds
|
|
358
|
+
|
|
359
|
+
# BAD: One giant container with all services
|
|
360
|
+
# Separate concerns: one process per container
|
|
361
|
+
|
|
362
|
+
# BAD: Putting secrets in docker-compose.yml
|
|
363
|
+
# Use .env files (gitignored) or Docker secrets
|
|
364
|
+
```
|