@hybridlabor-api/aos 4.8.0 → 4.10.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.
Files changed (186) hide show
  1. package/.agents/{agents.md → AGENTS.md} +3 -1
  2. package/.agents/nodes.json +3 -1
  3. package/.agents/vendor-manifest.json +23 -1
  4. package/.claude/agents/godmode-media-eventtech.md +1 -1
  5. package/.claude/hooks/conventional-commits.mjs +125 -0
  6. package/.claude/hooks/env-file-protection.mjs +105 -0
  7. package/.claude/hooks/go-gate.mjs +101 -81
  8. package/.claude/hooks/memb-inject.mjs +29 -1
  9. package/.claude/settings.json +13 -0
  10. package/.claude/workflows/startcycle-dispatch.mjs +23 -1
  11. package/.opencode/agents/godmode-media-eventtech.md +1 -1
  12. package/.opencode/plugins/bdb-aos.js +31 -4
  13. package/CLAUDE.md +0 -571
  14. package/README.de.md +1 -1
  15. package/README.md +1 -1
  16. package/README.pt.md +1 -1
  17. package/THIRD_PARTY_NOTICES.md +126 -0
  18. package/bin/aos-doctor.mjs +1 -1
  19. package/docs/skills_table.md +1 -1
  20. package/installer.js +187 -55
  21. package/package.json +7 -3
  22. package/packages/aos-cli/README.md +80 -0
  23. package/packages/aos-cli/bin/aos-cli.mjs +134 -0
  24. package/packages/aos-cli/core-skills.json +12 -0
  25. package/packages/aos-cli/extensions/aos.ts +321 -0
  26. package/packages/aos-cli/package-lock.json +1923 -0
  27. package/packages/aos-cli/package.json +29 -0
  28. package/packages/aos-cli/scripts/check-theme.mjs +63 -0
  29. package/packages/aos-cli/themes/aos.json +97 -0
  30. package/scripts/build-plugin-manifest.mjs +131 -0
  31. package/scripts/validate-skills.mjs +81 -6
  32. package/skills/basic/ao-orchestrator/SKILL.md +116 -0
  33. package/skills/basic/bdb-eventagency-skill/SKILL.md +252 -0
  34. package/skills/basic/bdb-shipping-skill/SKILL.md +161 -0
  35. package/skills/basic/godmode-eventtech/SKILL.md +4 -1
  36. package/skills/global_config/agenttrail/SKILL.md +6 -1
  37. package/skills/global_config/aos-project-init/SKILL.md +2 -0
  38. package/skills/global_config/aos-project-init/assets/AGENTS.template.md +1 -1
  39. package/skills/global_config/aos-project-init/scripts/aos-project-doctor.mjs +1 -1
  40. package/skills/global_config/aos-setup/SKILL.md +1 -1
  41. package/skills/global_config/aos-setup/scripts/aos-doctor.mjs +1 -1
  42. package/skills/global_config/ask-tim/SKILL.md +7 -7
  43. package/skills/global_config/bash-script-generator/SKILL.md +201 -0
  44. package/skills/global_config/bash-script-generator/assets/templates/standard-template.sh +96 -0
  45. package/skills/global_config/bash-script-generator/docs/bash-scripting-guide.md +729 -0
  46. package/skills/global_config/bash-script-generator/docs/generation-best-practices.md +193 -0
  47. package/skills/global_config/bash-script-generator/docs/script-patterns.md +566 -0
  48. package/skills/global_config/bash-script-generator/docs/text-processing-guide.md +437 -0
  49. package/skills/global_config/bash-script-generator/examples/log-analyzer.sh +92 -0
  50. package/skills/global_config/bash-script-generator/scripts/generate_script_template.sh +123 -0
  51. package/skills/global_config/bash-script-generator/scripts/run_ci_checks.sh +172 -0
  52. package/skills/global_config/bash-script-generator/scripts/test_generator.sh +413 -0
  53. package/skills/global_config/bash-script-validator/SKILL.md +249 -0
  54. package/skills/global_config/bash-script-validator/docs/awk-reference.md +449 -0
  55. package/skills/global_config/bash-script-validator/docs/bash-reference.md +468 -0
  56. package/skills/global_config/bash-script-validator/docs/common-mistakes.md +623 -0
  57. package/skills/global_config/bash-script-validator/docs/grep-reference.md +395 -0
  58. package/skills/global_config/bash-script-validator/docs/regex-reference.md +391 -0
  59. package/skills/global_config/bash-script-validator/docs/sed-reference.md +454 -0
  60. package/skills/global_config/bash-script-validator/docs/shell-reference.md +463 -0
  61. package/skills/global_config/bash-script-validator/docs/shellcheck-reference.md +399 -0
  62. package/skills/global_config/bash-script-validator/examples/bad-bash.sh +55 -0
  63. package/skills/global_config/bash-script-validator/examples/bad-shell.sh +54 -0
  64. package/skills/global_config/bash-script-validator/examples/good-bash.sh +71 -0
  65. package/skills/global_config/bash-script-validator/examples/good-shell.sh +69 -0
  66. package/skills/global_config/bash-script-validator/scripts/run_ci_checks.sh +23 -0
  67. package/skills/global_config/bash-script-validator/scripts/shellcheck_wrapper.sh +174 -0
  68. package/skills/global_config/bash-script-validator/scripts/test_validate.sh +446 -0
  69. package/skills/global_config/bash-script-validator/scripts/validate.sh +512 -0
  70. package/skills/global_config/ci-pipeline/SKILL.md +135 -0
  71. package/skills/global_config/deja-memory/SKILL.md +3 -1
  72. package/skills/global_config/dispatching-parallel-agents/SKILL.md +170 -0
  73. package/skills/global_config/dockerfile-generator/SKILL.md +1038 -0
  74. package/skills/global_config/dockerfile-generator/examples/example.dockerignore +95 -0
  75. package/skills/global_config/dockerfile-generator/examples/golang-distroless.Dockerfile +34 -0
  76. package/skills/global_config/dockerfile-generator/examples/java-springboot.Dockerfile +45 -0
  77. package/skills/global_config/dockerfile-generator/examples/nextjs-production.Dockerfile +49 -0
  78. package/skills/global_config/dockerfile-generator/examples/nodejs-multistage.Dockerfile +55 -0
  79. package/skills/global_config/dockerfile-generator/examples/python-fastapi.Dockerfile +48 -0
  80. package/skills/global_config/dockerfile-generator/references/language_specific_guides.md +510 -0
  81. package/skills/global_config/dockerfile-generator/references/multistage_builds.md +570 -0
  82. package/skills/global_config/dockerfile-generator/references/optimization_patterns.md +492 -0
  83. package/skills/global_config/dockerfile-generator/references/security_best_practices.md +375 -0
  84. package/skills/global_config/dockerfile-generator/scripts/generate_dockerignore.sh +199 -0
  85. package/skills/global_config/dockerfile-generator/scripts/generate_golang.sh +172 -0
  86. package/skills/global_config/dockerfile-generator/scripts/generate_java.sh +185 -0
  87. package/skills/global_config/dockerfile-generator/scripts/generate_nodejs.sh +279 -0
  88. package/skills/global_config/dockerfile-generator/scripts/generate_python.sh +218 -0
  89. package/skills/global_config/dockerfile-generator/scripts/test_generator.sh +210 -0
  90. package/skills/global_config/dockerfile-validator/SKILL.md +300 -0
  91. package/skills/global_config/dockerfile-validator/examples/.dockerignore.example +34 -0
  92. package/skills/global_config/dockerfile-validator/examples/bad-example.Dockerfile +37 -0
  93. package/skills/global_config/dockerfile-validator/examples/golang-distroless.Dockerfile +50 -0
  94. package/skills/global_config/dockerfile-validator/examples/good-example.Dockerfile +52 -0
  95. package/skills/global_config/dockerfile-validator/examples/python-optimized.Dockerfile +53 -0
  96. package/skills/global_config/dockerfile-validator/examples/security-issues.Dockerfile +42 -0
  97. package/skills/global_config/dockerfile-validator/references/docker_best_practices.md +348 -0
  98. package/skills/global_config/dockerfile-validator/references/optimization_guide.md +473 -0
  99. package/skills/global_config/dockerfile-validator/references/security_checklist.md +208 -0
  100. package/skills/global_config/dockerfile-validator/scripts/dockerfile-validate.sh +699 -0
  101. package/skills/global_config/dockerfile-validator/scripts/test_validate.sh +35 -0
  102. package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn-lock-read.Dockerfile +6 -0
  103. package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn.Dockerfile +6 -0
  104. package/skills/global_config/dockerfile-validator/tests/fixtures/from-platform-nonroot.Dockerfile +7 -0
  105. package/skills/global_config/dockerfile-validator/tests/test_regression.sh +164 -0
  106. package/skills/global_config/finishing-a-development-branch/SKILL.md +228 -0
  107. package/skills/global_config/github-actions-generator/SKILL.md +353 -0
  108. package/skills/global_config/github-actions-generator/assets/templates/action/composite/action.yml +82 -0
  109. package/skills/global_config/github-actions-generator/assets/templates/action/docker/Dockerfile +25 -0
  110. package/skills/global_config/github-actions-generator/assets/templates/action/docker/action.yml +42 -0
  111. package/skills/global_config/github-actions-generator/assets/templates/action/docker/entrypoint.sh +27 -0
  112. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/action.yml +33 -0
  113. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/index.js +50 -0
  114. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/package.json +27 -0
  115. package/skills/global_config/github-actions-generator/assets/templates/workflow/basic_workflow.yml +242 -0
  116. package/skills/global_config/github-actions-generator/assets/templates/workflow/reusable_workflow.yml +106 -0
  117. package/skills/global_config/github-actions-generator/examples/README.md +147 -0
  118. package/skills/global_config/github-actions-generator/examples/actions/setup-node-cached/action.yml +93 -0
  119. package/skills/global_config/github-actions-generator/examples/caching/docker-buildkit.yml +256 -0
  120. package/skills/global_config/github-actions-generator/examples/security/dependency-review.yml +62 -0
  121. package/skills/global_config/github-actions-generator/examples/security/sbom-attestation.yml +119 -0
  122. package/skills/global_config/github-actions-generator/examples/triggers/chatops-commands.yml +475 -0
  123. package/skills/global_config/github-actions-generator/examples/triggers/repository-dispatch.yml +418 -0
  124. package/skills/global_config/github-actions-generator/examples/triggers/workflow-orchestration.yml +404 -0
  125. package/skills/global_config/github-actions-generator/examples/workflows/docker-build-push.yml +68 -0
  126. package/skills/global_config/github-actions-generator/examples/workflows/go-ci.yml +161 -0
  127. package/skills/global_config/github-actions-generator/examples/workflows/monorepo-ci.yml +340 -0
  128. package/skills/global_config/github-actions-generator/examples/workflows/multi-environment-deploy.yml +406 -0
  129. package/skills/global_config/github-actions-generator/examples/workflows/nodejs-ci.yml +122 -0
  130. package/skills/global_config/github-actions-generator/examples/workflows/python-ci.yml +157 -0
  131. package/skills/global_config/github-actions-generator/examples/workflows/scheduled-tasks.yml +376 -0
  132. package/skills/global_config/github-actions-generator/references/advanced-triggers.md +917 -0
  133. package/skills/global_config/github-actions-generator/references/best-practices.md +755 -0
  134. package/skills/global_config/github-actions-generator/references/common-actions.md +715 -0
  135. package/skills/global_config/github-actions-generator/references/custom-actions.md +320 -0
  136. package/skills/global_config/github-actions-generator/references/expressions-and-contexts.md +688 -0
  137. package/skills/global_config/github-actions-generator/references/modern-features.md +421 -0
  138. package/skills/global_config/github-actions-generator/scripts/test_generator.sh +344 -0
  139. package/skills/global_config/github-actions-templates/SKILL.md +7 -0
  140. package/skills/global_config/github-actions-validator/SKILL.md +576 -0
  141. package/skills/global_config/github-actions-validator/examples/README.md +88 -0
  142. package/skills/global_config/github-actions-validator/examples/outdated-versions.yml +76 -0
  143. package/skills/global_config/github-actions-validator/examples/valid-ci.yml +79 -0
  144. package/skills/global_config/github-actions-validator/examples/with-errors.yml +47 -0
  145. package/skills/global_config/github-actions-validator/references/act_usage.md +233 -0
  146. package/skills/global_config/github-actions-validator/references/action_versions.md +122 -0
  147. package/skills/global_config/github-actions-validator/references/actionlint_usage.md +343 -0
  148. package/skills/global_config/github-actions-validator/references/common_errors.md +512 -0
  149. package/skills/global_config/github-actions-validator/references/modern_features.md +384 -0
  150. package/skills/global_config/github-actions-validator/references/runners.md +317 -0
  151. package/skills/global_config/github-actions-validator/scripts/install_tools.sh +113 -0
  152. package/skills/global_config/github-actions-validator/scripts/validate_workflow.sh +910 -0
  153. package/skills/global_config/github-actions-validator/tests/test_validate_workflow.sh +237 -0
  154. package/skills/global_config/makefile-generator/SKILL.md +614 -0
  155. package/skills/global_config/makefile-generator/assets/templates/.gitkeep +1 -0
  156. package/skills/global_config/makefile-generator/docs/makefile-structure.md +530 -0
  157. package/skills/global_config/makefile-generator/docs/optimization-guide.md +784 -0
  158. package/skills/global_config/makefile-generator/docs/patterns-guide.md +642 -0
  159. package/skills/global_config/makefile-generator/docs/security-guide.md +361 -0
  160. package/skills/global_config/makefile-generator/docs/targets-guide.md +642 -0
  161. package/skills/global_config/makefile-generator/docs/variables-guide.md +596 -0
  162. package/skills/global_config/makefile-generator/scripts/add_standard_targets.sh +539 -0
  163. package/skills/global_config/makefile-generator/scripts/generate_makefile_template.sh +690 -0
  164. package/skills/global_config/makefile-generator/test/test_helper_scripts.sh +190 -0
  165. package/skills/global_config/makefile-validator/SKILL.md +244 -0
  166. package/skills/global_config/makefile-validator/docs/bake-tool.md +1000 -0
  167. package/skills/global_config/makefile-validator/docs/best-practices.md +858 -0
  168. package/skills/global_config/makefile-validator/docs/common-mistakes.md +944 -0
  169. package/skills/global_config/makefile-validator/examples/bad-makefile.mk +77 -0
  170. package/skills/global_config/makefile-validator/examples/good-makefile.mk +103 -0
  171. package/skills/global_config/makefile-validator/scripts/test_validate.sh +382 -0
  172. package/skills/global_config/makefile-validator/scripts/validate_makefile.sh +712 -0
  173. package/skills/global_config/{MCP_Manage → mcp-manage}/SKILL.md +3 -3
  174. package/skills/global_config/plan-canvas/SKILL.md +9 -2
  175. package/skills/global_config/plan-canvas/scripts/lib/plan-canvas/ui.js +10 -2
  176. package/skills/global_config/plan-canvas/scripts/plan-canvas.js +1 -1
  177. package/skills/global_config/read-the-damn-docs/SKILL.md +175 -0
  178. package/skills/global_config/requesting-code-review/SKILL.md +98 -0
  179. package/skills/global_config/requesting-code-review/code-reviewer.md +198 -0
  180. package/skills/global_config/using-git-worktrees/SKILL.md +170 -0
  181. package/skills/global_config/verification-before-completion/SKILL.md +123 -0
  182. package/skills/global_config/writing-plans/SKILL.md +126 -46
  183. package/skills/global_config/writing-plans-legacy/SKILL.md +152 -0
  184. package/.claude/CLAUDE.md +0 -12
  185. package/mcps/RhinoMCP/docs/content/docs/getting-started/gemini.md +0 -61
  186. /package/{GEMINI.md → RULES.md} +0 -0
@@ -0,0 +1,473 @@
1
+ # Dockerfile Optimization Guide
2
+
3
+ Comprehensive guide for optimizing Docker images for size, build time, and runtime performance.
4
+
5
+ ## Image Size Optimization
6
+
7
+ ### 1. Choose Minimal Base Images
8
+
9
+ **Size Comparison:**
10
+ ```
11
+ ubuntu:22.04 ~80 MB
12
+ alpine:3.21 ~5 MB
13
+ distroless/base ~20 MB
14
+ scratch ~0 MB (empty)
15
+ ```
16
+
17
+ **When to use each:**
18
+
19
+ **Alpine** - General purpose minimal Linux
20
+ ```dockerfile
21
+ FROM alpine:3.21
22
+ RUN apk add --no-cache python3
23
+ ```
24
+ - ✅ Very small (5 MB)
25
+ - ✅ Has package manager
26
+ - ✅ Good for interpreted languages
27
+ - ⚠️ Uses musl libc (compatibility issues with some C libraries)
28
+
29
+ **Distroless** - Production containers
30
+ ```dockerfile
31
+ FROM gcr.io/distroless/python3
32
+ COPY --from=builder /app /app
33
+ ```
34
+ - ✅ No shell, package manager (secure)
35
+ - ✅ Minimal attack surface
36
+ - ✅ Small size
37
+ - ⚠️ Cannot exec into container for debugging
38
+ - ⚠️ Must use multi-stage builds
39
+
40
+ **Scratch** - Static binaries only
41
+ ```dockerfile
42
+ FROM scratch
43
+ COPY --from=builder /app/binary /
44
+ ```
45
+ - ✅ Absolutely minimal
46
+ - ✅ Perfect for Go, Rust static binaries
47
+ - ⚠️ No OS utilities
48
+ - ⚠️ No debug capabilities
49
+
50
+ ### 2. Multi-Stage Builds
51
+
52
+ **Problem: Build tools bloat production images**
53
+
54
+ **Single-stage (bloated):**
55
+ ```dockerfile
56
+ FROM golang:1.21
57
+ WORKDIR /app
58
+ COPY . .
59
+ RUN go build -o server
60
+ CMD ["./server"]
61
+
62
+ # Result: ~1 GB (includes Go toolchain)
63
+ ```
64
+
65
+ **Multi-stage (optimized):**
66
+ ```dockerfile
67
+ # Build stage
68
+ FROM golang:1.21 AS builder
69
+ WORKDIR /app
70
+ COPY . .
71
+ RUN go build -o server
72
+
73
+ # Production stage
74
+ FROM alpine:3.21
75
+ COPY --from=builder /app/server /server
76
+ CMD ["/server"]
77
+
78
+ # Result: ~10 MB (100x smaller!)
79
+ ```
80
+
81
+ ### 3. Layer Optimization
82
+
83
+ **Combine RUN commands:**
84
+
85
+ ```dockerfile
86
+ # Bad - 4 layers, poor caching
87
+ RUN apt-get update
88
+ RUN apt-get install -y curl
89
+ RUN curl -O https://example.com/file
90
+ RUN rm -f file
91
+
92
+ # Good - 1 layer, cache cleaned
93
+ RUN apt-get update && apt-get install -y --no-install-recommends \
94
+ curl \
95
+ && curl -O https://example.com/file \
96
+ && rm -rf /var/lib/apt/lists/*
97
+ ```
98
+
99
+ ### 4. Package Manager Cache Cleanup
100
+
101
+ **APT (Debian/Ubuntu):**
102
+ ```dockerfile
103
+ RUN apt-get update && apt-get install -y --no-install-recommends \
104
+ package1 \
105
+ package2 \
106
+ && rm -rf /var/lib/apt/lists/*
107
+ ```
108
+ - Saves ~100-200 MB per layer
109
+ - Must be in same RUN command
110
+
111
+ **APK (Alpine):**
112
+ ```dockerfile
113
+ RUN apk add --no-cache package1 package2
114
+ ```
115
+ - Doesn't create cache at all
116
+ - Or: `apk add package && rm -rf /var/cache/apk/*`
117
+
118
+ **YUM/DNF (RHEL/Fedora):**
119
+ ```dockerfile
120
+ RUN yum install -y package \
121
+ && yum clean all \
122
+ && rm -rf /var/cache/yum
123
+ ```
124
+
125
+ **Pip (Python):**
126
+ ```dockerfile
127
+ RUN pip install --no-cache-dir package
128
+ ```
129
+
130
+ **NPM (Node.js):**
131
+ ```dockerfile
132
+ RUN npm ci --only=production
133
+ # Or with cache mount:
134
+ RUN --mount=type=cache,target=/root/.npm \
135
+ npm ci --only=production
136
+ ```
137
+
138
+ ### 5. Use .dockerignore
139
+
140
+ **Problem: Entire project copied into image**
141
+
142
+ ```
143
+ .dockerignore contents:
144
+ .git/
145
+ node_modules/
146
+ *.log
147
+ .env
148
+ tests/
149
+ docs/
150
+ README.md
151
+ ```
152
+
153
+ **Impact:**
154
+ - Faster builds (smaller context)
155
+ - Smaller images (fewer files)
156
+ - Prevents accidental secret leaks
157
+
158
+ ## Build Time Optimization
159
+
160
+ ### 1. Leverage Build Cache
161
+
162
+ **Order matters - least to most frequently changing:**
163
+
164
+ ```dockerfile
165
+ # 1. Base image (rarely changes)
166
+ FROM node:21-alpine
167
+
168
+ # 2. System dependencies (rarely change)
169
+ RUN apk add --no-cache curl
170
+
171
+ # 3. Application dependencies (change occasionally)
172
+ COPY package*.json ./
173
+ RUN npm ci
174
+
175
+ # 4. Application code (changes frequently)
176
+ COPY . .
177
+ RUN npm run build
178
+ ```
179
+
180
+ **Why this works:**
181
+ - Docker caches each layer
182
+ - Layers rebuild when files change
183
+ - Putting frequently-changing files last preserves cache for earlier layers
184
+
185
+ ### 2. BuildKit Cache Mounts
186
+
187
+ **Enable BuildKit:**
188
+ ```bash
189
+ export DOCKER_BUILDKIT=1
190
+ ```
191
+
192
+ **Use cache mounts:**
193
+ ```dockerfile
194
+ # syntax=docker/dockerfile:1
195
+
196
+ # Python with pip cache
197
+ RUN --mount=type=cache,target=/root/.cache/pip \
198
+ pip install -r requirements.txt
199
+
200
+ # Node.js with npm cache
201
+ RUN --mount=type=cache,target=/root/.npm \
202
+ npm ci
203
+
204
+ # Go with module cache
205
+ RUN --mount=type=cache,target=/go/pkg/mod \
206
+ go build -o app
207
+ ```
208
+
209
+ **Benefits:**
210
+ - Persistent cache across builds
211
+ - Dramatically faster dependency installation
212
+ - Shared cache between projects
213
+
214
+ ### 3. Parallel Multi-Stage Builds
215
+
216
+ ```dockerfile
217
+ # These stages run in parallel
218
+ FROM alpine AS fetch-1
219
+ RUN wget https://example.com/file1
220
+
221
+ FROM alpine AS fetch-2
222
+ RUN wget https://example.com/file2
223
+
224
+ # This stage waits for both
225
+ FROM alpine
226
+ COPY --from=fetch-1 /file1 .
227
+ COPY --from=fetch-2 /file2 .
228
+ ```
229
+
230
+ ## Runtime Performance Optimization
231
+
232
+ ### 1. Exec Form for CMD/ENTRYPOINT
233
+
234
+ ```dockerfile
235
+ # Bad - shell form (extra shell process)
236
+ CMD python app.py
237
+
238
+ # Good - exec form (direct execution)
239
+ CMD ["python", "app.py"]
240
+ ```
241
+
242
+ **Benefits:**
243
+ - Faster startup (no shell)
244
+ - Proper signal handling (SIGTERM)
245
+ - Lower memory usage
246
+
247
+ ### 2. Health Checks
248
+
249
+ ```dockerfile
250
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \
251
+ CMD curl -f http://localhost:8080/health || exit 1
252
+ ```
253
+
254
+ **Benefits:**
255
+ - Container orchestrators can detect unhealthy containers
256
+ - Automatic restarts
257
+ - Better uptime
258
+
259
+ ### 3. Resource Awareness
260
+
261
+ ```dockerfile
262
+ # Use all available CPUs
263
+ ENV GOMAXPROCS=0
264
+
265
+ # Or limit to specific count
266
+ ENV GOMAXPROCS=4
267
+ ```
268
+
269
+ ## Language-Specific Optimizations
270
+
271
+ ### Node.js
272
+
273
+ ```dockerfile
274
+ FROM node:21-alpine AS builder
275
+ WORKDIR /app
276
+ COPY package*.json ./
277
+ RUN npm ci --only=production
278
+
279
+ FROM node:21-alpine
280
+ COPY --from=builder /app/node_modules ./node_modules
281
+ COPY . .
282
+ USER node
283
+ CMD ["node", "server.js"]
284
+ ```
285
+
286
+ **Tips:**
287
+ - Use `npm ci` instead of `npm install`
288
+ - Install only production dependencies
289
+ - Use Alpine variant (node:21-alpine vs node:21 = 150MB vs 900MB)
290
+
291
+ ### Python
292
+
293
+ ```dockerfile
294
+ FROM python:3.12-slim AS builder
295
+ WORKDIR /app
296
+ COPY requirements.txt .
297
+ RUN pip install --user --no-cache-dir -r requirements.txt
298
+
299
+ FROM python:3.12-slim
300
+ COPY --from=builder /root/.local /root/.local
301
+ ENV PATH=/root/.local/bin:$PATH
302
+ COPY . .
303
+ USER nobody
304
+ CMD ["python", "app.py"]
305
+ ```
306
+
307
+ **Tips:**
308
+ - Use slim variant (python:3.12-slim vs python:3.12 = 50MB vs 1GB)
309
+ - Install to --user to copy to final stage
310
+ - Use --no-cache-dir to avoid pip cache
311
+
312
+ ### Go
313
+
314
+ ```dockerfile
315
+ FROM golang:1.21-alpine AS builder
316
+ WORKDIR /src
317
+ COPY go.* ./
318
+ RUN go mod download
319
+ COPY . .
320
+ RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app
321
+
322
+ FROM scratch
323
+ COPY --from=builder /app /app
324
+ ENTRYPOINT ["/app"]
325
+ ```
326
+
327
+ **Tips:**
328
+ - Use scratch for static binaries
329
+ - Disable CGO for static linking
330
+ - Use `-ldflags="-s -w"` to strip debug info (smaller binary)
331
+
332
+ ### Java
333
+
334
+ ```dockerfile
335
+ FROM eclipse-temurin:21-jdk AS builder
336
+ WORKDIR /app
337
+ COPY pom.xml .
338
+ RUN mvn dependency:go-offline
339
+ COPY src ./src
340
+ RUN mvn package
341
+
342
+ FROM eclipse-temurin:21-jre-alpine
343
+ COPY --from=builder /app/target/*.jar /app.jar
344
+ CMD ["java", "-jar", "/app.jar"]
345
+ ```
346
+
347
+ **Tips:**
348
+ - Use JRE instead of JDK for runtime (smaller)
349
+ - Download dependencies separately for caching
350
+ - Consider custom JRE with jlink for minimal image
351
+
352
+ ## Advanced Techniques
353
+
354
+ ### 1. Multi-Architecture Builds
355
+
356
+ ```bash
357
+ docker buildx build --platform linux/amd64,linux/arm64 -t myapp .
358
+ ```
359
+
360
+ ### 2. Build Secrets
361
+
362
+ ```dockerfile
363
+ # syntax=docker/dockerfile:1
364
+ RUN --mount=type=secret,id=npmrc,target=/root/.npmrc \
365
+ npm ci
366
+ ```
367
+
368
+ ```bash
369
+ docker build --secret id=npmrc,src=$HOME/.npmrc .
370
+ ```
371
+
372
+ **Benefits:**
373
+ - Secrets not in final image
374
+ - Not in build history
375
+ - Secure credential usage
376
+
377
+ ### 3. SSH Mounts
378
+
379
+ ```dockerfile
380
+ RUN --mount=type=ssh \
381
+ git clone git@github.com:private/repo.git
382
+ ```
383
+
384
+ ```bash
385
+ docker build --ssh default .
386
+ ```
387
+
388
+ ### 4. Layer Squashing
389
+
390
+ ```bash
391
+ docker build --squash -t myapp .
392
+ ```
393
+
394
+ **Benefits:**
395
+ - Single layer in final image
396
+ - Smaller size if cleanup commands are separate
397
+
398
+ **Drawbacks:**
399
+ - Loses layer caching benefits
400
+ - Slower rebuilds
401
+
402
+ ## Optimization Checklist
403
+
404
+ - [ ] Use minimal base image (Alpine, distroless, scratch)
405
+ - [ ] Implement multi-stage builds
406
+ - [ ] Combine RUN commands
407
+ - [ ] Clean package manager cache
408
+ - [ ] Order layers by change frequency
409
+ - [ ] Use BuildKit cache mounts
410
+ - [ ] Create .dockerignore file
411
+ - [ ] Use exec form for CMD/ENTRYPOINT
412
+ - [ ] Add HEALTHCHECK for services
413
+ - [ ] Pin dependency versions
414
+ - [ ] Remove development dependencies
415
+ - [ ] Use --no-install-recommends for apt
416
+ - [ ] Consider language-specific optimizations
417
+ - [ ] Enable BuildKit features
418
+
419
+ ## Measuring Optimization
420
+
421
+ ### Before Optimization
422
+ ```bash
423
+ docker images myapp
424
+ # REPOSITORY TAG SIZE
425
+ # myapp latest 1.2GB
426
+ ```
427
+
428
+ ### After Optimization
429
+ ```bash
430
+ docker images myapp-optimized
431
+ # REPOSITORY TAG SIZE
432
+ # myapp-optimized latest 50MB
433
+ ```
434
+
435
+ ### Build Time Comparison
436
+ ```bash
437
+ time docker build -t myapp .
438
+ # real 5m30s
439
+
440
+ time docker build -t myapp-optimized .
441
+ # real 0m45s (with cache)
442
+ ```
443
+
444
+ ## Tools for Analysis
445
+
446
+ ### dive - Layer Analysis
447
+ ```bash
448
+ dive myapp:latest
449
+ ```
450
+ - Shows layer-by-layer size
451
+ - Identifies wasted space
452
+ - Suggests optimizations
453
+
454
+ ### docker history
455
+ ```bash
456
+ docker history myapp:latest
457
+ ```
458
+ - Shows each layer's size
459
+ - Identifies large layers
460
+
461
+ ### docker scout
462
+ ```bash
463
+ docker scout cves myapp:latest
464
+ ```
465
+ - Scans for vulnerabilities
466
+ - Recommends base image updates
467
+
468
+ ## Resources
469
+
470
+ - [Docker Best Practices](https://docs.docker.com/build/building/best-practices/)
471
+ - [BuildKit Documentation](https://docs.docker.com/build/buildkit/)
472
+ - [Multi-Stage Builds](https://docs.docker.com/build/building/multi-stage/)
473
+ - [dive - Layer Explorer](https://github.com/wagoodman/dive)
@@ -0,0 +1,208 @@
1
+ # Container Security Checklist
2
+
3
+ A comprehensive security checklist for Dockerfiles and container images.
4
+
5
+ ## Build-Time Security
6
+
7
+ ### Base Image Security
8
+
9
+ - [ ] Use official or verified base images
10
+ - [ ] Pin base image to specific tag (not :latest)
11
+ - [ ] Consider digest pinning for critical applications
12
+ - [ ] Prefer minimal base images (Alpine, distroless, scratch)
13
+ - [ ] Scan base images for known vulnerabilities
14
+ - [ ] Keep base images updated regularly
15
+
16
+ ### Secrets Management
17
+
18
+ - [ ] Never hardcode secrets in Dockerfile
19
+ - [ ] Don't use ENV or ARG for sensitive data
20
+ - [ ] Use Docker build secrets (--secret flag)
21
+ - [ ] Use runtime configuration for secrets
22
+ - [ ] Scan for accidentally committed secrets
23
+ - [ ] Use .dockerignore to exclude secret files
24
+
25
+ ### Package Management
26
+
27
+ - [ ] Pin package versions for reproducibility
28
+ - [ ] Only install necessary packages (--no-install-recommends)
29
+ - [ ] Clean package manager cache in same layer
30
+ - [ ] Verify package signatures when possible
31
+ - [ ] Use official package repositories
32
+ - [ ] Audit dependencies for known vulnerabilities
33
+
34
+ ### User and Permissions
35
+
36
+ - [ ] Create and use non-root user
37
+ - [ ] Set USER directive before CMD/ENTRYPOINT
38
+ - [ ] Use high UID (>10000) for better isolation
39
+ - [ ] Set proper file ownership with COPY --chown
40
+ - [ ] Don't use sudo in containers
41
+ - [ ] Avoid privileged operations
42
+
43
+ ### Layer and File Security
44
+
45
+ - [ ] Use .dockerignore to exclude sensitive files
46
+ - [ ] Don't copy unnecessary files (use specific COPY)
47
+ - [ ] Remove secrets after use in same layer
48
+ - [ ] Don't log sensitive information
49
+ - [ ] Minimize number of layers
50
+ - [ ] Use multi-stage builds to exclude build secrets
51
+
52
+ ## Common Vulnerabilities
53
+
54
+ ### SSH/Remote Access
55
+
56
+ - [ ] Don't install or expose SSH (port 22)
57
+ - [ ] Don't install telnet, FTP, or other insecure protocols
58
+ - [ ] Use `docker exec` for debugging instead of SSH
59
+ - [ ] Don't run sshd in containers
60
+
61
+ ### Network Exposure
62
+
63
+ - [ ] Only EXPOSE necessary ports
64
+ - [ ] Don't bind to 0.0.0.0 in development images
65
+ - [ ] Use internal networks for inter-container communication
66
+ - [ ] Implement proper firewall rules
67
+ - [ ] Use TLS for network communications
68
+
69
+ ### File System Security
70
+
71
+ - [ ] Consider read-only root filesystem
72
+ - [ ] Use tmpfs for temporary files
73
+ - [ ] Set proper file permissions
74
+ - [ ] Don't store secrets in environment variables
75
+ - [ ] Use volume mounts for sensitive data
76
+
77
+ ## Runtime Security
78
+
79
+ ### Container Configuration
80
+
81
+ - [ ] Run with --read-only flag when possible
82
+ - [ ] Drop unnecessary capabilities (--cap-drop)
83
+ - [ ] Use security profiles (AppArmor, SELinux)
84
+ - [ ] Set resource limits (CPU, memory)
85
+ - [ ] Use user namespaces
86
+ - [ ] Enable content trust (DOCKER_CONTENT_TRUST)
87
+
88
+ ### Health and Monitoring
89
+
90
+ - [ ] Implement HEALTHCHECK in Dockerfile
91
+ - [ ] Monitor container logs
92
+ - [ ] Set up security scanning in CI/CD
93
+ - [ ] Use runtime security tools
94
+ - [ ] Monitor for anomalous behavior
95
+ - [ ] Implement proper logging without secrets
96
+
97
+ ### Network Security
98
+
99
+ - [ ] Use custom bridge networks
100
+ - [ ] Implement network segmentation
101
+ - [ ] Use encrypted overlays for swarm
102
+ - [ ] Configure DNS properly
103
+ - [ ] Use service mesh for microservices
104
+ - [ ] Implement network policies
105
+
106
+ ## Image Registry Security
107
+
108
+ ### Registry Configuration
109
+
110
+ - [ ] Use private registries for internal images
111
+ - [ ] Enable image scanning in registry
112
+ - [ ] Implement access controls
113
+ - [ ] Use image signing (Docker Content Trust)
114
+ - [ ] Scan for vulnerabilities before pull
115
+ - [ ] Regularly update registry software
116
+
117
+ ### Image Distribution
118
+
119
+ - [ ] Sign images before distribution
120
+ - [ ] Verify image signatures on pull
121
+ - [ ] Use TLS for registry communication
122
+ - [ ] Implement role-based access control
123
+ - [ ] Audit image pull/push events
124
+ - [ ] Use image provenance metadata
125
+
126
+ ## Security Scanning Tools
127
+
128
+ ### Static Analysis
129
+ - **hadolint** - Dockerfile linting
130
+ - **Checkov** - Policy-as-code scanning
131
+ - **dockerfilelint** - Best practices checker
132
+
133
+ ### Vulnerability Scanning
134
+ - **Trivy** - Comprehensive vulnerability scanner
135
+ - **Snyk** - Dependency vulnerability scanner
136
+ - **Clair** - Container vulnerability analysis
137
+ - **Anchore** - Deep image inspection
138
+
139
+ ### Runtime Security
140
+ - **Falco** - Runtime threat detection
141
+ - **Aqua Security** - Container security platform
142
+ - **Sysdig** - Container monitoring and security
143
+
144
+ ## Compliance and Standards
145
+
146
+ ### Industry Standards
147
+
148
+ - [ ] Follow CIS Docker Benchmark
149
+ - [ ] Comply with NIST guidelines
150
+ - [ ] Adhere to OWASP Container Security
151
+ - [ ] Meet PCI DSS requirements (if applicable)
152
+ - [ ] Follow SOC 2 controls (if applicable)
153
+
154
+ ### Security Policies
155
+
156
+ - [ ] Document security requirements
157
+ - [ ] Implement security review process
158
+ - [ ] Define incident response procedures
159
+ - [ ] Regular security audits
160
+ - [ ] Security training for developers
161
+ - [ ] Maintain security documentation
162
+
163
+ ## Quick Security Wins
164
+
165
+ ### Easy Fixes
166
+
167
+ 1. **Use specific base image tags**
168
+ ```dockerfile
169
+ FROM alpine:3.21 # Not alpine:latest
170
+ ```
171
+
172
+ 2. **Run as non-root**
173
+ ```dockerfile
174
+ USER app
175
+ ```
176
+
177
+ 3. **Clean package cache**
178
+ ```dockerfile
179
+ RUN apk add --no-cache package
180
+ ```
181
+
182
+ 4. **Don't expose unnecessary ports**
183
+ ```dockerfile
184
+ # Only expose what's needed
185
+ EXPOSE 8080
186
+ ```
187
+
188
+ 5. **Add health checks**
189
+ ```dockerfile
190
+ HEALTHCHECK CMD curl -f http://localhost/ || exit 1
191
+ ```
192
+
193
+ ## Security Checklist Summary
194
+
195
+ | Category | Critical | High | Medium |
196
+ |----------|----------|------|--------|
197
+ | Base Image | Use official, pin version | Scan for CVEs | Update regularly |
198
+ | Secrets | Never in code | Use secrets mgmt | Scan commits |
199
+ | Users | Run as non-root | High UID | Proper permissions |
200
+ | Network | TLS only | Minimal exposure | Firewall rules |
201
+ | Runtime | Drop capabilities | Read-only FS | Resource limits |
202
+
203
+ ## Resources
204
+
205
+ - [CIS Docker Benchmark](https://www.cisecurity.org/benchmark/docker)
206
+ - [OWASP Docker Security](https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html)
207
+ - [NIST Container Security Guide](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-190.pdf)
208
+ - [Docker Security Best Practices](https://docs.docker.com/develop/security-best-practices/)