@hybridlabor-api/aos 4.8.0 → 4.9.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/.agents/agents.md +1 -1
- package/.agents/nodes.json +1 -1
- package/.agents/vendor-manifest.json +23 -1
- package/.claude/agents/godmode-media-eventtech.md +1 -1
- package/.claude/hooks/conventional-commits.mjs +125 -0
- package/.claude/hooks/env-file-protection.mjs +105 -0
- package/.claude/hooks/go-gate.mjs +101 -81
- package/.claude/settings.json +13 -0
- package/.opencode/agents/godmode-media-eventtech.md +1 -1
- package/.opencode/plugins/bdb-aos.js +31 -4
- package/README.de.md +1 -1
- package/README.md +1 -1
- package/README.pt.md +1 -1
- package/THIRD_PARTY_NOTICES.md +88 -0
- package/docs/skills_table.md +1 -1
- package/installer.js +174 -46
- package/package.json +6 -2
- package/packages/aos-cli/README.md +80 -0
- package/packages/aos-cli/bin/aos-cli.mjs +134 -0
- package/packages/aos-cli/core-skills.json +12 -0
- package/packages/aos-cli/extensions/aos.ts +321 -0
- package/packages/aos-cli/package-lock.json +1923 -0
- package/packages/aos-cli/package.json +29 -0
- package/packages/aos-cli/scripts/check-theme.mjs +63 -0
- package/packages/aos-cli/themes/aos.json +97 -0
- package/scripts/build-plugin-manifest.mjs +131 -0
- package/scripts/validate-skills.mjs +81 -6
- package/skills/basic/ao-orchestrator/SKILL.md +116 -0
- package/skills/global_config/agenttrail/SKILL.md +6 -1
- package/skills/global_config/ask-tim/SKILL.md +4 -4
- package/skills/global_config/bash-script-generator/SKILL.md +201 -0
- package/skills/global_config/bash-script-generator/assets/templates/standard-template.sh +96 -0
- package/skills/global_config/bash-script-generator/docs/bash-scripting-guide.md +729 -0
- package/skills/global_config/bash-script-generator/docs/generation-best-practices.md +193 -0
- package/skills/global_config/bash-script-generator/docs/script-patterns.md +566 -0
- package/skills/global_config/bash-script-generator/docs/text-processing-guide.md +437 -0
- package/skills/global_config/bash-script-generator/examples/log-analyzer.sh +92 -0
- package/skills/global_config/bash-script-generator/scripts/generate_script_template.sh +123 -0
- package/skills/global_config/bash-script-generator/scripts/run_ci_checks.sh +172 -0
- package/skills/global_config/bash-script-generator/scripts/test_generator.sh +413 -0
- package/skills/global_config/bash-script-validator/SKILL.md +249 -0
- package/skills/global_config/bash-script-validator/docs/awk-reference.md +449 -0
- package/skills/global_config/bash-script-validator/docs/bash-reference.md +468 -0
- package/skills/global_config/bash-script-validator/docs/common-mistakes.md +623 -0
- package/skills/global_config/bash-script-validator/docs/grep-reference.md +395 -0
- package/skills/global_config/bash-script-validator/docs/regex-reference.md +391 -0
- package/skills/global_config/bash-script-validator/docs/sed-reference.md +454 -0
- package/skills/global_config/bash-script-validator/docs/shell-reference.md +463 -0
- package/skills/global_config/bash-script-validator/docs/shellcheck-reference.md +399 -0
- package/skills/global_config/bash-script-validator/examples/bad-bash.sh +55 -0
- package/skills/global_config/bash-script-validator/examples/bad-shell.sh +54 -0
- package/skills/global_config/bash-script-validator/examples/good-bash.sh +71 -0
- package/skills/global_config/bash-script-validator/examples/good-shell.sh +69 -0
- package/skills/global_config/bash-script-validator/scripts/run_ci_checks.sh +23 -0
- package/skills/global_config/bash-script-validator/scripts/shellcheck_wrapper.sh +174 -0
- package/skills/global_config/bash-script-validator/scripts/test_validate.sh +446 -0
- package/skills/global_config/bash-script-validator/scripts/validate.sh +512 -0
- package/skills/global_config/ci-pipeline/SKILL.md +135 -0
- package/skills/global_config/dispatching-parallel-agents/SKILL.md +170 -0
- package/skills/global_config/dockerfile-generator/SKILL.md +1038 -0
- package/skills/global_config/dockerfile-generator/examples/example.dockerignore +95 -0
- package/skills/global_config/dockerfile-generator/examples/golang-distroless.Dockerfile +34 -0
- package/skills/global_config/dockerfile-generator/examples/java-springboot.Dockerfile +45 -0
- package/skills/global_config/dockerfile-generator/examples/nextjs-production.Dockerfile +49 -0
- package/skills/global_config/dockerfile-generator/examples/nodejs-multistage.Dockerfile +55 -0
- package/skills/global_config/dockerfile-generator/examples/python-fastapi.Dockerfile +48 -0
- package/skills/global_config/dockerfile-generator/references/language_specific_guides.md +510 -0
- package/skills/global_config/dockerfile-generator/references/multistage_builds.md +570 -0
- package/skills/global_config/dockerfile-generator/references/optimization_patterns.md +492 -0
- package/skills/global_config/dockerfile-generator/references/security_best_practices.md +375 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_dockerignore.sh +199 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_golang.sh +172 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_java.sh +185 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_nodejs.sh +279 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_python.sh +218 -0
- package/skills/global_config/dockerfile-generator/scripts/test_generator.sh +210 -0
- package/skills/global_config/dockerfile-validator/SKILL.md +300 -0
- package/skills/global_config/dockerfile-validator/examples/.dockerignore.example +34 -0
- package/skills/global_config/dockerfile-validator/examples/bad-example.Dockerfile +37 -0
- package/skills/global_config/dockerfile-validator/examples/golang-distroless.Dockerfile +50 -0
- package/skills/global_config/dockerfile-validator/examples/good-example.Dockerfile +52 -0
- package/skills/global_config/dockerfile-validator/examples/python-optimized.Dockerfile +53 -0
- package/skills/global_config/dockerfile-validator/examples/security-issues.Dockerfile +42 -0
- package/skills/global_config/dockerfile-validator/references/docker_best_practices.md +348 -0
- package/skills/global_config/dockerfile-validator/references/optimization_guide.md +473 -0
- package/skills/global_config/dockerfile-validator/references/security_checklist.md +208 -0
- package/skills/global_config/dockerfile-validator/scripts/dockerfile-validate.sh +699 -0
- package/skills/global_config/dockerfile-validator/scripts/test_validate.sh +35 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn-lock-read.Dockerfile +6 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn.Dockerfile +6 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/from-platform-nonroot.Dockerfile +7 -0
- package/skills/global_config/dockerfile-validator/tests/test_regression.sh +164 -0
- package/skills/global_config/finishing-a-development-branch/SKILL.md +228 -0
- package/skills/global_config/github-actions-generator/SKILL.md +353 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/composite/action.yml +82 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/Dockerfile +25 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/action.yml +42 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/entrypoint.sh +27 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/action.yml +33 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/index.js +50 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/package.json +27 -0
- package/skills/global_config/github-actions-generator/assets/templates/workflow/basic_workflow.yml +242 -0
- package/skills/global_config/github-actions-generator/assets/templates/workflow/reusable_workflow.yml +106 -0
- package/skills/global_config/github-actions-generator/examples/README.md +147 -0
- package/skills/global_config/github-actions-generator/examples/actions/setup-node-cached/action.yml +93 -0
- package/skills/global_config/github-actions-generator/examples/caching/docker-buildkit.yml +256 -0
- package/skills/global_config/github-actions-generator/examples/security/dependency-review.yml +62 -0
- package/skills/global_config/github-actions-generator/examples/security/sbom-attestation.yml +119 -0
- package/skills/global_config/github-actions-generator/examples/triggers/chatops-commands.yml +475 -0
- package/skills/global_config/github-actions-generator/examples/triggers/repository-dispatch.yml +418 -0
- package/skills/global_config/github-actions-generator/examples/triggers/workflow-orchestration.yml +404 -0
- package/skills/global_config/github-actions-generator/examples/workflows/docker-build-push.yml +68 -0
- package/skills/global_config/github-actions-generator/examples/workflows/go-ci.yml +161 -0
- package/skills/global_config/github-actions-generator/examples/workflows/monorepo-ci.yml +340 -0
- package/skills/global_config/github-actions-generator/examples/workflows/multi-environment-deploy.yml +406 -0
- package/skills/global_config/github-actions-generator/examples/workflows/nodejs-ci.yml +122 -0
- package/skills/global_config/github-actions-generator/examples/workflows/python-ci.yml +157 -0
- package/skills/global_config/github-actions-generator/examples/workflows/scheduled-tasks.yml +376 -0
- package/skills/global_config/github-actions-generator/references/advanced-triggers.md +917 -0
- package/skills/global_config/github-actions-generator/references/best-practices.md +755 -0
- package/skills/global_config/github-actions-generator/references/common-actions.md +715 -0
- package/skills/global_config/github-actions-generator/references/custom-actions.md +320 -0
- package/skills/global_config/github-actions-generator/references/expressions-and-contexts.md +688 -0
- package/skills/global_config/github-actions-generator/references/modern-features.md +421 -0
- package/skills/global_config/github-actions-generator/scripts/test_generator.sh +344 -0
- package/skills/global_config/github-actions-templates/SKILL.md +7 -0
- package/skills/global_config/github-actions-validator/SKILL.md +576 -0
- package/skills/global_config/github-actions-validator/examples/README.md +88 -0
- package/skills/global_config/github-actions-validator/examples/outdated-versions.yml +76 -0
- package/skills/global_config/github-actions-validator/examples/valid-ci.yml +79 -0
- package/skills/global_config/github-actions-validator/examples/with-errors.yml +47 -0
- package/skills/global_config/github-actions-validator/references/act_usage.md +233 -0
- package/skills/global_config/github-actions-validator/references/action_versions.md +122 -0
- package/skills/global_config/github-actions-validator/references/actionlint_usage.md +343 -0
- package/skills/global_config/github-actions-validator/references/common_errors.md +512 -0
- package/skills/global_config/github-actions-validator/references/modern_features.md +384 -0
- package/skills/global_config/github-actions-validator/references/runners.md +317 -0
- package/skills/global_config/github-actions-validator/scripts/install_tools.sh +113 -0
- package/skills/global_config/github-actions-validator/scripts/validate_workflow.sh +910 -0
- package/skills/global_config/github-actions-validator/tests/test_validate_workflow.sh +237 -0
- package/skills/global_config/makefile-generator/SKILL.md +614 -0
- package/skills/global_config/makefile-generator/assets/templates/.gitkeep +1 -0
- package/skills/global_config/makefile-generator/docs/makefile-structure.md +530 -0
- package/skills/global_config/makefile-generator/docs/optimization-guide.md +784 -0
- package/skills/global_config/makefile-generator/docs/patterns-guide.md +642 -0
- package/skills/global_config/makefile-generator/docs/security-guide.md +361 -0
- package/skills/global_config/makefile-generator/docs/targets-guide.md +642 -0
- package/skills/global_config/makefile-generator/docs/variables-guide.md +596 -0
- package/skills/global_config/makefile-generator/scripts/add_standard_targets.sh +539 -0
- package/skills/global_config/makefile-generator/scripts/generate_makefile_template.sh +690 -0
- package/skills/global_config/makefile-generator/test/test_helper_scripts.sh +190 -0
- package/skills/global_config/makefile-validator/SKILL.md +244 -0
- package/skills/global_config/makefile-validator/docs/bake-tool.md +1000 -0
- package/skills/global_config/makefile-validator/docs/best-practices.md +858 -0
- package/skills/global_config/makefile-validator/docs/common-mistakes.md +944 -0
- package/skills/global_config/makefile-validator/examples/bad-makefile.mk +77 -0
- package/skills/global_config/makefile-validator/examples/good-makefile.mk +103 -0
- package/skills/global_config/makefile-validator/scripts/test_validate.sh +382 -0
- package/skills/global_config/makefile-validator/scripts/validate_makefile.sh +712 -0
- package/skills/global_config/{MCP_Manage → mcp-manage}/SKILL.md +3 -3
- package/skills/global_config/requesting-code-review/SKILL.md +98 -0
- package/skills/global_config/requesting-code-review/code-reviewer.md +198 -0
- package/skills/global_config/using-git-worktrees/SKILL.md +170 -0
- package/skills/global_config/verification-before-completion/SKILL.md +123 -0
- package/skills/global_config/writing-plans/SKILL.md +126 -46
- package/skills/global_config/writing-plans-legacy/SKILL.md +139 -0
|
@@ -0,0 +1,1038 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dockerfile-generator
|
|
3
|
+
description: Create, generate, or write Dockerfiles and multi-stage Docker images. Containerize apps.
|
|
4
|
+
category: engineering-method
|
|
5
|
+
source: cc-devops-skills
|
|
6
|
+
date_added: "2026-09-25"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Dockerfile Generator
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
This skill provides a comprehensive workflow for generating production-ready Dockerfiles with security, optimization, and best practices built-in. Generates multi-stage builds, security-hardened configurations, and optimized layer structures with automatic validation and iterative error fixing.
|
|
14
|
+
|
|
15
|
+
**Key Features:**
|
|
16
|
+
- Multi-stage builds for optimal image size (50-85% reduction)
|
|
17
|
+
- Security hardening (non-root users, minimal base images, no secrets)
|
|
18
|
+
- Layer caching optimization for faster builds
|
|
19
|
+
- Language-specific templates (Node.js, Python, Go, Java)
|
|
20
|
+
- Automatic .dockerignore generation
|
|
21
|
+
- Integration with `dockerfile-validator` for validation
|
|
22
|
+
- Iterative validation and error fixing (minimum 1 iteration if errors found)
|
|
23
|
+
- Local references plus docs lookup fallback chain for framework-specific patterns
|
|
24
|
+
|
|
25
|
+
## When to Use This Skill
|
|
26
|
+
|
|
27
|
+
Invoke this skill when:
|
|
28
|
+
- Creating new Dockerfiles from scratch
|
|
29
|
+
- Containerizing applications (Node.js, Python, Go, Java, or other languages)
|
|
30
|
+
- Implementing multi-stage builds for size optimization
|
|
31
|
+
- Converting existing Dockerfiles to best practices
|
|
32
|
+
- Generating production-ready container configurations
|
|
33
|
+
- Optimizing Docker builds for security and performance
|
|
34
|
+
- The user asks to "create", "generate", "build", or "write" a Dockerfile
|
|
35
|
+
- Implementing containerization for microservices
|
|
36
|
+
- Setting up CI/CD pipeline container builds
|
|
37
|
+
|
|
38
|
+
### Trigger Phrases
|
|
39
|
+
|
|
40
|
+
Use this skill immediately when the request contains phrasing like:
|
|
41
|
+
- "Generate a production Dockerfile for my app"
|
|
42
|
+
- "Create a multi-stage Dockerfile for <language/framework>"
|
|
43
|
+
- "Containerize this service with security best practices"
|
|
44
|
+
- "Optimize this Dockerfile for size and build speed"
|
|
45
|
+
- "Write Dockerfile and .dockerignore for deployment"
|
|
46
|
+
|
|
47
|
+
## Do NOT Use This Skill For
|
|
48
|
+
|
|
49
|
+
- Validating existing Dockerfiles (use `dockerfile-validator` instead)
|
|
50
|
+
- Building or running containers (use docker build/run commands)
|
|
51
|
+
- Debugging running containers (use docker logs, docker exec)
|
|
52
|
+
- Managing Docker images or registries
|
|
53
|
+
|
|
54
|
+
## Deterministic Execution Model
|
|
55
|
+
|
|
56
|
+
Run these stages in order, and do not skip a stage unless the skip reason is reported in the final output.
|
|
57
|
+
|
|
58
|
+
1. Gather requirements (language, runtime version, entrypoint, exposed port, package manager, health endpoint).
|
|
59
|
+
2. Load references (local reference files first; external docs only when local references are insufficient).
|
|
60
|
+
3. Generate Dockerfile and `.dockerignore`.
|
|
61
|
+
4. Validate with `dockerfile-validator` or fallback local tools.
|
|
62
|
+
5. Iterate fixes until stop condition is met.
|
|
63
|
+
6. Publish final artifacts plus validation/audit report.
|
|
64
|
+
|
|
65
|
+
Stop conditions for stage 5:
|
|
66
|
+
- Stop when there are zero validation errors and no unapproved warnings.
|
|
67
|
+
- Stop after 3 iterations maximum, then emit an intentional-deviation report for unresolved findings.
|
|
68
|
+
|
|
69
|
+
## Reference Path Map
|
|
70
|
+
|
|
71
|
+
Consult these files directly by path as needed:
|
|
72
|
+
- `references/security_best_practices.md` for non-root users, secret handling, base image hardening, vulnerability scanning.
|
|
73
|
+
- `references/optimization_patterns.md` for multi-stage strategy, cache optimization, layer reduction, BuildKit cache mounts.
|
|
74
|
+
- `references/language_specific_guides.md` for language/framework runtime and package-manager patterns.
|
|
75
|
+
- `references/multistage_builds.md` for advanced stage-splitting and artifact-copy patterns.
|
|
76
|
+
|
|
77
|
+
## Dockerfile Generation Workflow
|
|
78
|
+
|
|
79
|
+
Follow this workflow when generating Dockerfiles. Adapt based on user needs:
|
|
80
|
+
|
|
81
|
+
### Stage 1: Gather Requirements
|
|
82
|
+
|
|
83
|
+
**Objective:** Understand what needs to be containerized and gather all necessary information.
|
|
84
|
+
|
|
85
|
+
**Information to Collect:**
|
|
86
|
+
|
|
87
|
+
1. **Application Details:**
|
|
88
|
+
- Programming language and version (Node.js 18/20, Python 3.11/3.12, Go 1.21+, Java 17/21, etc.)
|
|
89
|
+
- Application type (web server, API, CLI tool, batch job, etc.)
|
|
90
|
+
- Framework (Express, FastAPI, Spring Boot, etc.)
|
|
91
|
+
- Entry point (main file, command to run)
|
|
92
|
+
|
|
93
|
+
2. **Dependencies:**
|
|
94
|
+
- Package manager (npm/yarn/pnpm, pip/poetry, go mod, maven/gradle)
|
|
95
|
+
- System dependencies (build tools, libraries, etc.)
|
|
96
|
+
- Build-time vs runtime dependencies
|
|
97
|
+
|
|
98
|
+
3. **Application Configuration:**
|
|
99
|
+
- Port(s) to expose
|
|
100
|
+
- Environment variables needed
|
|
101
|
+
- Configuration files
|
|
102
|
+
- Health check endpoint (for web services)
|
|
103
|
+
- Volume mounts (if any)
|
|
104
|
+
|
|
105
|
+
4. **Build Requirements:**
|
|
106
|
+
- Build commands
|
|
107
|
+
- Test commands (optional)
|
|
108
|
+
- Compilation needs (for compiled languages)
|
|
109
|
+
- Static asset generation
|
|
110
|
+
|
|
111
|
+
5. **Production Requirements:**
|
|
112
|
+
- Expected image size constraints
|
|
113
|
+
- Security requirements
|
|
114
|
+
- Scaling needs
|
|
115
|
+
- Resource constraints (CPU, memory)
|
|
116
|
+
|
|
117
|
+
**Use AskUserQuestion if information is missing or unclear.**
|
|
118
|
+
|
|
119
|
+
**Example Questions:**
|
|
120
|
+
```
|
|
121
|
+
- What programming language and version is your application using?
|
|
122
|
+
- What is the main entry point to run your application?
|
|
123
|
+
- Does your application expose any ports? If so, which ones?
|
|
124
|
+
- Do you need any system dependencies beyond the base language runtime?
|
|
125
|
+
- Does your application need a health check endpoint?
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Stage 2: Framework/Library Documentation Lookup (if needed)
|
|
129
|
+
|
|
130
|
+
**Objective:** Research framework-specific containerization patterns and best practices.
|
|
131
|
+
|
|
132
|
+
**When to Perform This Stage:**
|
|
133
|
+
- User mentions a specific framework (Next.js, Django, FastAPI, Spring Boot, etc.)
|
|
134
|
+
- Application has complex build requirements
|
|
135
|
+
- Need guidance on framework-specific optimization
|
|
136
|
+
|
|
137
|
+
**Research Process (strict fallback chain):**
|
|
138
|
+
|
|
139
|
+
1. **Read local references first (required):**
|
|
140
|
+
- `references/security_best_practices.md`
|
|
141
|
+
- `references/optimization_patterns.md`
|
|
142
|
+
- `references/language_specific_guides.md`
|
|
143
|
+
|
|
144
|
+
2. **Use Context7 docs lookup when local references are insufficient (preferred external source):**
|
|
145
|
+
```
|
|
146
|
+
Use mcp__context7__resolve-library-id with the framework name
|
|
147
|
+
Then use mcp__context7__query-docs with query:
|
|
148
|
+
"docker deployment production build"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
3. **Use web search only if Context7 is unavailable or missing needed details:**
|
|
152
|
+
```
|
|
153
|
+
"<framework>" "<version>" dockerfile production deployment best practices
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
4. **If external lookup is unavailable (offline/tooling limits):**
|
|
157
|
+
- Continue with local references and language templates in this file.
|
|
158
|
+
- State assumptions explicitly in the output.
|
|
159
|
+
- Mark the lookup limitation in the final report.
|
|
160
|
+
|
|
161
|
+
5. **Extract only actionable data:**
|
|
162
|
+
- Recommended base image + version policy
|
|
163
|
+
- Build optimization techniques
|
|
164
|
+
- Required runtime environment variables
|
|
165
|
+
- Production vs development differences
|
|
166
|
+
- Security requirements specific to the framework
|
|
167
|
+
|
|
168
|
+
### Stage 3: Generate Dockerfile
|
|
169
|
+
|
|
170
|
+
**Objective:** Create a production-ready, multi-stage Dockerfile following best practices.
|
|
171
|
+
|
|
172
|
+
**Core Principles:**
|
|
173
|
+
|
|
174
|
+
1. **Multi-Stage Builds (REQUIRED for compiled languages, RECOMMENDED for all):**
|
|
175
|
+
- Separate build stage from runtime stage
|
|
176
|
+
- Keep build tools out of final image
|
|
177
|
+
- Copy only necessary artifacts
|
|
178
|
+
- Results in 50-85% smaller images
|
|
179
|
+
|
|
180
|
+
2. **Security Hardening (REQUIRED):**
|
|
181
|
+
- Use specific version tags (NEVER use :latest)
|
|
182
|
+
- Run as non-root user (create dedicated user)
|
|
183
|
+
- Use minimal base images (alpine, distroless)
|
|
184
|
+
- No hardcoded secrets
|
|
185
|
+
- Scan base images for vulnerabilities
|
|
186
|
+
|
|
187
|
+
3. **Layer Optimization (REQUIRED):**
|
|
188
|
+
- Order instructions from least to most frequently changing
|
|
189
|
+
- Copy dependency files before application code
|
|
190
|
+
- Combine related RUN commands with &&
|
|
191
|
+
- Clean up package manager caches in same layer
|
|
192
|
+
- Leverage build cache effectively
|
|
193
|
+
|
|
194
|
+
4. **Production Readiness (REQUIRED):**
|
|
195
|
+
- Add HEALTHCHECK for services
|
|
196
|
+
- Use exec form for ENTRYPOINT/CMD
|
|
197
|
+
- Set WORKDIR to absolute paths
|
|
198
|
+
- Document exposed ports with EXPOSE
|
|
199
|
+
|
|
200
|
+
**Language-Specific Templates:**
|
|
201
|
+
|
|
202
|
+
#### Node.js Multi-Stage Dockerfile
|
|
203
|
+
|
|
204
|
+
> **Build-stage dependency rule:** If the application has a build step (TypeScript,
|
|
205
|
+
> Vite, Webpack, etc.), install **all** dependencies in the builder stage (omit
|
|
206
|
+
> `--only=production`) and prune dev deps after the build. Using
|
|
207
|
+
> `--only=production` before a build step will cause `npm run build` to fail
|
|
208
|
+
> because dev tools are not installed.
|
|
209
|
+
|
|
210
|
+
```dockerfile
|
|
211
|
+
# syntax=docker/dockerfile:1
|
|
212
|
+
|
|
213
|
+
# Build stage — installs all deps so build tools (tsc, vite, etc.) are available,
|
|
214
|
+
# then prunes dev deps so the production stage only ships what is needed at runtime.
|
|
215
|
+
FROM node:20-alpine AS builder
|
|
216
|
+
WORKDIR /app
|
|
217
|
+
|
|
218
|
+
# Copy dependency files for caching
|
|
219
|
+
COPY package*.json ./
|
|
220
|
+
# Install ALL dependencies (including devDependencies required by the build step)
|
|
221
|
+
RUN npm ci && \
|
|
222
|
+
npm cache clean --force
|
|
223
|
+
|
|
224
|
+
# Copy application code
|
|
225
|
+
COPY . .
|
|
226
|
+
|
|
227
|
+
# Build application and prune dev dependencies
|
|
228
|
+
RUN npm run build && \
|
|
229
|
+
npm prune --production
|
|
230
|
+
|
|
231
|
+
# Production stage
|
|
232
|
+
FROM node:20-alpine AS production
|
|
233
|
+
WORKDIR /app
|
|
234
|
+
|
|
235
|
+
# Set production environment
|
|
236
|
+
ENV NODE_ENV=production
|
|
237
|
+
|
|
238
|
+
# Create non-root user
|
|
239
|
+
RUN addgroup -g 1001 -S nodejs && \
|
|
240
|
+
adduser -S nodejs -u 1001
|
|
241
|
+
|
|
242
|
+
# Copy pruned node_modules and built application from builder
|
|
243
|
+
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
|
|
244
|
+
COPY --from=builder --chown=nodejs:nodejs /app .
|
|
245
|
+
|
|
246
|
+
# Switch to non-root user
|
|
247
|
+
USER nodejs
|
|
248
|
+
|
|
249
|
+
# Expose port
|
|
250
|
+
EXPOSE 3000
|
|
251
|
+
|
|
252
|
+
# Health check
|
|
253
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
254
|
+
CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
|
255
|
+
|
|
256
|
+
# Start application
|
|
257
|
+
CMD ["node", "index.js"]
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
> **Simple app (no build step):** If there is no compilation or bundling, install
|
|
261
|
+
> only production deps in the builder stage and copy source from the host context:
|
|
262
|
+
> ```dockerfile
|
|
263
|
+
> RUN npm ci --only=production && npm cache clean --force
|
|
264
|
+
> ...
|
|
265
|
+
> COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
|
|
266
|
+
> COPY --chown=nodejs:nodejs . .
|
|
267
|
+
> ```
|
|
268
|
+
|
|
269
|
+
#### Python Multi-Stage Dockerfile
|
|
270
|
+
|
|
271
|
+
```dockerfile
|
|
272
|
+
# syntax=docker/dockerfile:1
|
|
273
|
+
|
|
274
|
+
# Build stage
|
|
275
|
+
FROM python:3.12-slim AS builder
|
|
276
|
+
WORKDIR /app
|
|
277
|
+
|
|
278
|
+
# Install build dependencies
|
|
279
|
+
# hadolint ignore=DL3008
|
|
280
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
281
|
+
gcc \
|
|
282
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
283
|
+
|
|
284
|
+
# Copy dependency files
|
|
285
|
+
COPY requirements.txt .
|
|
286
|
+
|
|
287
|
+
# Install Python dependencies
|
|
288
|
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
289
|
+
|
|
290
|
+
# Production stage
|
|
291
|
+
FROM python:3.12-slim AS production
|
|
292
|
+
WORKDIR /app
|
|
293
|
+
|
|
294
|
+
# Create non-root user
|
|
295
|
+
RUN useradd -m -u 1001 app
|
|
296
|
+
|
|
297
|
+
# Copy dependencies from builder
|
|
298
|
+
COPY --from=builder /root/.local /home/app/.local
|
|
299
|
+
|
|
300
|
+
# Copy application code
|
|
301
|
+
COPY --chown=app:app . .
|
|
302
|
+
|
|
303
|
+
# Update PATH and set Python production env vars
|
|
304
|
+
# PYTHONUNBUFFERED=1 ensures stdout/stderr are flushed immediately (essential for container logs)
|
|
305
|
+
# PYTHONDONTWRITEBYTECODE=1 prevents writing .pyc files to disk
|
|
306
|
+
ENV PATH=/home/app/.local/bin:$PATH \
|
|
307
|
+
PYTHONUNBUFFERED=1 \
|
|
308
|
+
PYTHONDONTWRITEBYTECODE=1
|
|
309
|
+
|
|
310
|
+
# Switch to non-root user
|
|
311
|
+
USER app
|
|
312
|
+
|
|
313
|
+
# Expose port
|
|
314
|
+
EXPOSE 8000
|
|
315
|
+
|
|
316
|
+
# Health check (adjust endpoint as needed)
|
|
317
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
318
|
+
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()" || exit 1
|
|
319
|
+
|
|
320
|
+
# Start application
|
|
321
|
+
CMD ["python", "app.py"]
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### Go Multi-Stage Dockerfile
|
|
325
|
+
|
|
326
|
+
```dockerfile
|
|
327
|
+
# syntax=docker/dockerfile:1
|
|
328
|
+
|
|
329
|
+
# Build stage
|
|
330
|
+
FROM golang:1.21-alpine AS builder
|
|
331
|
+
WORKDIR /app
|
|
332
|
+
|
|
333
|
+
# Copy go mod files
|
|
334
|
+
COPY go.mod go.sum ./
|
|
335
|
+
RUN go mod download
|
|
336
|
+
|
|
337
|
+
# Copy source code
|
|
338
|
+
COPY . .
|
|
339
|
+
|
|
340
|
+
# Build the application
|
|
341
|
+
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags="-s -w" -o main .
|
|
342
|
+
|
|
343
|
+
# Production stage (using distroless for minimal image)
|
|
344
|
+
# gcr.io/distroless/static-debian12 IS a specific tag; hadolint DL3006 is a
|
|
345
|
+
# false positive for non-Docker-Hub registries.
|
|
346
|
+
# hadolint ignore=DL3006
|
|
347
|
+
FROM gcr.io/distroless/static-debian12 AS production
|
|
348
|
+
WORKDIR /
|
|
349
|
+
|
|
350
|
+
# Copy binary from builder
|
|
351
|
+
COPY --from=builder /app/main /main
|
|
352
|
+
|
|
353
|
+
# Expose port
|
|
354
|
+
EXPOSE 8080
|
|
355
|
+
|
|
356
|
+
# HEALTHCHECK is not supported in distroless images (no shell available)
|
|
357
|
+
|
|
358
|
+
# Switch to non-root user (distroless runs as nonroot by default)
|
|
359
|
+
USER nonroot:nonroot
|
|
360
|
+
|
|
361
|
+
# Start application
|
|
362
|
+
ENTRYPOINT ["/main"]
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
#### Java Multi-Stage Dockerfile
|
|
366
|
+
|
|
367
|
+
```dockerfile
|
|
368
|
+
# syntax=docker/dockerfile:1
|
|
369
|
+
|
|
370
|
+
# Build stage
|
|
371
|
+
FROM eclipse-temurin:21-jdk-jammy AS builder
|
|
372
|
+
WORKDIR /app
|
|
373
|
+
|
|
374
|
+
# Copy Maven wrapper and pom.xml
|
|
375
|
+
COPY mvnw pom.xml ./
|
|
376
|
+
COPY .mvn .mvn
|
|
377
|
+
|
|
378
|
+
# Download dependencies (cached layer)
|
|
379
|
+
RUN ./mvnw dependency:go-offline
|
|
380
|
+
|
|
381
|
+
# Copy source code
|
|
382
|
+
COPY src ./src
|
|
383
|
+
|
|
384
|
+
# Build application
|
|
385
|
+
RUN ./mvnw clean package -DskipTests && \
|
|
386
|
+
mv target/*.jar target/app.jar
|
|
387
|
+
|
|
388
|
+
# Production stage (using JRE instead of JDK)
|
|
389
|
+
FROM eclipse-temurin:21-jre-jammy AS production
|
|
390
|
+
WORKDIR /app
|
|
391
|
+
|
|
392
|
+
# Install healthcheck dependency and create non-root user
|
|
393
|
+
# hadolint ignore=DL3008
|
|
394
|
+
RUN apt-get update && apt-get install -y --no-install-recommends curl && \
|
|
395
|
+
rm -rf /var/lib/apt/lists/* && \
|
|
396
|
+
useradd -m -u 1001 app
|
|
397
|
+
|
|
398
|
+
# Copy JAR from builder
|
|
399
|
+
COPY --from=builder --chown=app:app /app/target/app.jar ./app.jar
|
|
400
|
+
|
|
401
|
+
# Switch to non-root user
|
|
402
|
+
USER app
|
|
403
|
+
|
|
404
|
+
# Expose port
|
|
405
|
+
EXPOSE 8080
|
|
406
|
+
|
|
407
|
+
# Health check
|
|
408
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
|
409
|
+
CMD curl -f http://localhost:8080/actuator/health || exit 1
|
|
410
|
+
|
|
411
|
+
# Start application
|
|
412
|
+
ENTRYPOINT ["java", "-jar", "app.jar"]
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
**Selection Logic:**
|
|
416
|
+
- Node.js: Use for JavaScript/TypeScript applications
|
|
417
|
+
- Python: Use for Python applications (web, API, scripts)
|
|
418
|
+
- Go: Use for Go applications (excellent for minimal images)
|
|
419
|
+
- Java: Use for Spring Boot, Quarkus, or other Java frameworks
|
|
420
|
+
- Generic: Create custom Dockerfile for other languages
|
|
421
|
+
|
|
422
|
+
**Always Include:**
|
|
423
|
+
1. Syntax directive: `# syntax=docker/dockerfile:1`
|
|
424
|
+
2. Multi-stage build (build + production stages)
|
|
425
|
+
3. Non-root user creation and usage
|
|
426
|
+
4. HEALTHCHECK for services (if applicable)
|
|
427
|
+
5. Proper WORKDIR settings
|
|
428
|
+
6. EXPOSE for documented ports
|
|
429
|
+
7. Clean package manager caches
|
|
430
|
+
8. exec form for CMD/ENTRYPOINT
|
|
431
|
+
|
|
432
|
+
### Stage 4: Generate .dockerignore
|
|
433
|
+
|
|
434
|
+
**Objective:** Create comprehensive .dockerignore to reduce build context and prevent secret leaks.
|
|
435
|
+
|
|
436
|
+
**Always create .dockerignore with generated Dockerfile.**
|
|
437
|
+
|
|
438
|
+
**Standard .dockerignore Template:**
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
# Git
|
|
442
|
+
.git
|
|
443
|
+
.gitignore
|
|
444
|
+
.gitattributes
|
|
445
|
+
|
|
446
|
+
# CI/CD
|
|
447
|
+
.github
|
|
448
|
+
.gitlab-ci.yml
|
|
449
|
+
.travis.yml
|
|
450
|
+
.circleci
|
|
451
|
+
|
|
452
|
+
# Documentation
|
|
453
|
+
README.md
|
|
454
|
+
CHANGELOG.md
|
|
455
|
+
CONTRIBUTING.md
|
|
456
|
+
LICENSE
|
|
457
|
+
*.md
|
|
458
|
+
docs/
|
|
459
|
+
|
|
460
|
+
# Docker
|
|
461
|
+
Dockerfile*
|
|
462
|
+
docker-compose*.yml
|
|
463
|
+
.dockerignore
|
|
464
|
+
|
|
465
|
+
# Environment
|
|
466
|
+
.env
|
|
467
|
+
.env.*
|
|
468
|
+
*.local
|
|
469
|
+
|
|
470
|
+
# Logs
|
|
471
|
+
logs/
|
|
472
|
+
*.log
|
|
473
|
+
npm-debug.log*
|
|
474
|
+
yarn-debug.log*
|
|
475
|
+
yarn-error.log*
|
|
476
|
+
|
|
477
|
+
# Dependencies (language-specific - add as needed)
|
|
478
|
+
node_modules/
|
|
479
|
+
__pycache__/
|
|
480
|
+
*.pyc
|
|
481
|
+
*.pyo
|
|
482
|
+
*.pyd
|
|
483
|
+
.Python
|
|
484
|
+
venv/
|
|
485
|
+
.venv/
|
|
486
|
+
target/
|
|
487
|
+
*.class
|
|
488
|
+
|
|
489
|
+
# IDE
|
|
490
|
+
.vscode/
|
|
491
|
+
.idea/
|
|
492
|
+
*.swp
|
|
493
|
+
*.swo
|
|
494
|
+
*~
|
|
495
|
+
.DS_Store
|
|
496
|
+
|
|
497
|
+
# Testing
|
|
498
|
+
coverage/
|
|
499
|
+
.coverage
|
|
500
|
+
*.cover
|
|
501
|
+
.pytest_cache/
|
|
502
|
+
.tox/
|
|
503
|
+
test-results/
|
|
504
|
+
|
|
505
|
+
# Build artifacts
|
|
506
|
+
dist/
|
|
507
|
+
build/
|
|
508
|
+
*.egg-info/
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
**Customize based on language:**
|
|
512
|
+
- Node.js: Add `node_modules/`, `npm-debug.log`, `yarn-error.log`
|
|
513
|
+
- Python: Add `__pycache__/`, `*.pyc`, `.venv/`, `.pytest_cache/`
|
|
514
|
+
- Go: Add `vendor/`, `*.exe`, `*.test`
|
|
515
|
+
- Java: Add `target/`, `*.class`, `*.jar` (except final artifact)
|
|
516
|
+
|
|
517
|
+
### Stage 5: Validate with `dockerfile-validator`
|
|
518
|
+
|
|
519
|
+
**Objective:** Ensure generated Dockerfile follows best practices and has no unresolved critical findings.
|
|
520
|
+
|
|
521
|
+
**REQUIRED: Always run validation after generation.**
|
|
522
|
+
|
|
523
|
+
**Primary path (preferred):**
|
|
524
|
+
1. Invoke `dockerfile-validator`.
|
|
525
|
+
2. Capture findings by severity (`error`, `warning`, `info`).
|
|
526
|
+
3. Prioritize security and reproducibility findings first.
|
|
527
|
+
|
|
528
|
+
**Fallback path (if skill invocation is unavailable):**
|
|
529
|
+
1. Try local validator script directly:
|
|
530
|
+
```bash
|
|
531
|
+
bash ../dockerfile-validator/scripts/dockerfile-validate.sh Dockerfile
|
|
532
|
+
```
|
|
533
|
+
2. If that path is unavailable, run available tools directly:
|
|
534
|
+
```bash
|
|
535
|
+
hadolint Dockerfile
|
|
536
|
+
checkov -f Dockerfile --framework dockerfile
|
|
537
|
+
```
|
|
538
|
+
3. If one or more tools are unavailable, continue generation and report each skipped check in the final report.
|
|
539
|
+
|
|
540
|
+
**Expected validator stages:**
|
|
541
|
+
```
|
|
542
|
+
[1/4] Syntax Validation (hadolint)
|
|
543
|
+
[2/4] Security Scan (Checkov)
|
|
544
|
+
[3/4] Best Practices Validation
|
|
545
|
+
[4/4] Optimization Analysis
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Stage 6: Validate-Iterate Loop (Explicit Requirements)
|
|
549
|
+
|
|
550
|
+
**Objective:** Apply deterministic fix loops with auditable iteration records.
|
|
551
|
+
|
|
552
|
+
**Loop rules (required):**
|
|
553
|
+
1. Run at least one validation pass.
|
|
554
|
+
2. If any `error` exists, apply fixes and re-run validation.
|
|
555
|
+
3. Continue until:
|
|
556
|
+
- no `error` remains, or
|
|
557
|
+
- iteration count reaches 3.
|
|
558
|
+
4. For `warning`, either fix it or mark it as intentional deviation with justification.
|
|
559
|
+
5. Never silently suppress a finding.
|
|
560
|
+
|
|
561
|
+
**Iteration log format (required):**
|
|
562
|
+
|
|
563
|
+
| Iteration | Command/Path Used | Errors | Warnings | Fixes Applied | Result |
|
|
564
|
+
|-----------|-------------------|--------|----------|---------------|--------|
|
|
565
|
+
| 1 | `dockerfile-validator` or fallback command | N | N | short summary | pass/fail |
|
|
566
|
+
| 2 | ... | N | N | short summary | pass/fail |
|
|
567
|
+
| 3 | ... | N | N | short summary | pass/fail |
|
|
568
|
+
|
|
569
|
+
**Common fixes:**
|
|
570
|
+
- Add version tags to base images
|
|
571
|
+
- Add USER directive before CMD/ENTRYPOINT
|
|
572
|
+
- Add HEALTHCHECK for services
|
|
573
|
+
- Combine RUN commands where safe
|
|
574
|
+
- Clean package caches in same layer
|
|
575
|
+
- Replace `ADD` with `COPY` where archive/url behavior is not needed
|
|
576
|
+
|
|
577
|
+
### Stage 7: Final Review and Audit Report
|
|
578
|
+
|
|
579
|
+
**Objective:** Deliver runnable artifacts plus an auditable report.
|
|
580
|
+
|
|
581
|
+
**Deliverables (required):**
|
|
582
|
+
1. Generated files:
|
|
583
|
+
- Dockerfile (validated and optimized)
|
|
584
|
+
- `.dockerignore` (comprehensive)
|
|
585
|
+
2. Validation summary:
|
|
586
|
+
- tool path used (primary vs fallback)
|
|
587
|
+
- findings by severity
|
|
588
|
+
- final status after loop
|
|
589
|
+
3. Iteration log table from Stage 6.
|
|
590
|
+
4. Intentional deviation report (only when applicable).
|
|
591
|
+
5. Usage instructions.
|
|
592
|
+
6. Optimization metrics and next steps.
|
|
593
|
+
|
|
594
|
+
**Intentional deviation report (required when any finding is not fixed):**
|
|
595
|
+
|
|
596
|
+
| ID | Rule/Check | Severity | Decision | Justification | Risk | Mitigation | Expiry/Review Date |
|
|
597
|
+
|----|------------|----------|----------|---------------|------|------------|--------------------|
|
|
598
|
+
| DEV-001 | e.g., DL3059 | warning | accepted | build step readability requirement | minor layer overhead | revisit after refactor | YYYY-MM-DD |
|
|
599
|
+
|
|
600
|
+
**Usage instructions template:**
|
|
601
|
+
```bash
|
|
602
|
+
# Build image
|
|
603
|
+
docker build -t myapp:1.0 .
|
|
604
|
+
|
|
605
|
+
# Run container
|
|
606
|
+
docker run -p 3000:3000 myapp:1.0
|
|
607
|
+
|
|
608
|
+
# Probe health endpoint (if exposed)
|
|
609
|
+
curl http://localhost:3000/health
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
**Optimization metrics (required):**
|
|
613
|
+
```
|
|
614
|
+
## Optimization Metrics
|
|
615
|
+
|
|
616
|
+
| Metric | Estimate |
|
|
617
|
+
|--------|----------|
|
|
618
|
+
| Image Size | ~150MB (vs ~500MB without multi-stage, 70% reduction) |
|
|
619
|
+
| Build Cache | Layer caching enabled for dependencies |
|
|
620
|
+
| Security | Non-root user, minimal base image, no secrets |
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
**Language-specific size estimates:**
|
|
624
|
+
- **Node.js**: ~50-150MB with Alpine (vs ~1GB with full node image)
|
|
625
|
+
- **Python**: ~150-250MB with slim (vs ~900MB with full python image)
|
|
626
|
+
- **Go**: ~5-20MB with distroless/scratch (vs ~800MB with full golang image)
|
|
627
|
+
- **Java**: ~200-350MB with JRE (vs ~500MB+ with JDK)
|
|
628
|
+
|
|
629
|
+
**Next steps (required):**
|
|
630
|
+
```
|
|
631
|
+
## Next Steps
|
|
632
|
+
|
|
633
|
+
- [ ] Test the build locally: `docker build -t myapp:1.0 .`
|
|
634
|
+
- [ ] Run and verify the container works as expected
|
|
635
|
+
- [ ] Update CI/CD pipeline to use the new Dockerfile
|
|
636
|
+
- [ ] Consider BuildKit cache mounts for faster builds (see references/optimization_patterns.md)
|
|
637
|
+
- [ ] Set up automated vulnerability scanning with `docker scout` or `trivy`
|
|
638
|
+
- [ ] Push to registry and deploy
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
## Generation Scripts (Optional Reference)
|
|
642
|
+
|
|
643
|
+
The `scripts/` directory contains standalone bash scripts for manual Dockerfile generation outside of this skill:
|
|
644
|
+
|
|
645
|
+
- `generate_nodejs.sh` - CLI tool for Node.js Dockerfiles
|
|
646
|
+
- `generate_python.sh` - CLI tool for Python Dockerfiles
|
|
647
|
+
- `generate_golang.sh` - CLI tool for Go Dockerfiles
|
|
648
|
+
- `generate_java.sh` - CLI tool for Java Dockerfiles
|
|
649
|
+
- `generate_dockerignore.sh` - CLI tool for .dockerignore generation
|
|
650
|
+
|
|
651
|
+
**Purpose:** These scripts are reference implementations and manual tools for users who want to generate Dockerfiles via command line without using skill invocation. They demonstrate the same best practices embedded in this skill.
|
|
652
|
+
|
|
653
|
+
**When using this skill:** Codex generates Dockerfiles directly using the templates and patterns documented in this SKILL.md, rather than invoking these scripts. The templates in this document are the authoritative source.
|
|
654
|
+
|
|
655
|
+
**Script usage example:**
|
|
656
|
+
```bash
|
|
657
|
+
# Manual Dockerfile generation
|
|
658
|
+
cd devops-skills-plugin/skills/dockerfile-generator/scripts
|
|
659
|
+
./generate_nodejs.sh --version 20 --port 3000 --output Dockerfile
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
**Node/Python entrypoint flags (script mode):**
|
|
663
|
+
|
|
664
|
+
| Flag | Purpose | Notes |
|
|
665
|
+
|------|---------|-------|
|
|
666
|
+
| `--entry` | Legacy shorthand entrypoint | Simple whitespace split only. Quoted values are rejected. |
|
|
667
|
+
| `--entry-cmd` | Preferred command/executable | Use with repeated `--entry-arg` for exact argv control. |
|
|
668
|
+
| `--entry-arg` | Preferred argument value | Repeat for each argument; spaces are preserved per arg. |
|
|
669
|
+
|
|
670
|
+
```bash
|
|
671
|
+
# Recommended for arguments containing spaces
|
|
672
|
+
./generate_nodejs.sh \
|
|
673
|
+
--entry-cmd node \
|
|
674
|
+
--entry-arg server.js \
|
|
675
|
+
--entry-arg --message \
|
|
676
|
+
--entry-arg "hello world"
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
## Best Practices Reference
|
|
680
|
+
|
|
681
|
+
### Security Best Practices
|
|
682
|
+
|
|
683
|
+
1. **Use Specific Tags:**
|
|
684
|
+
```dockerfile
|
|
685
|
+
# Bad
|
|
686
|
+
FROM node:alpine
|
|
687
|
+
|
|
688
|
+
# Good
|
|
689
|
+
FROM node:20-alpine
|
|
690
|
+
|
|
691
|
+
# Better (with digest for reproducibility)
|
|
692
|
+
FROM node:20-alpine@sha256:abc123...
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
2. **Run as Non-Root:**
|
|
696
|
+
```dockerfile
|
|
697
|
+
# Create user
|
|
698
|
+
RUN addgroup -g 1001 -S appgroup && \
|
|
699
|
+
adduser -S app -u 1001 -G appgroup
|
|
700
|
+
|
|
701
|
+
# Switch to user before CMD
|
|
702
|
+
USER app
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
3. **Use Minimal Base Images:**
|
|
706
|
+
- Alpine Linux (small, secure)
|
|
707
|
+
- Distroless (no shell, minimal attack surface)
|
|
708
|
+
- Specific runtime images (node:alpine vs node:latest)
|
|
709
|
+
|
|
710
|
+
4. **Never Hardcode Secrets:**
|
|
711
|
+
```dockerfile
|
|
712
|
+
# Bad
|
|
713
|
+
ENV API_KEY=secret123
|
|
714
|
+
|
|
715
|
+
# Good - use build secrets
|
|
716
|
+
# docker build --secret id=api_key,src=.env
|
|
717
|
+
RUN --mount=type=secret,id=api_key \
|
|
718
|
+
API_KEY=$(cat /run/secrets/api_key) ./configure
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
### Optimization Best Practices
|
|
722
|
+
|
|
723
|
+
1. **Layer Caching:**
|
|
724
|
+
```dockerfile
|
|
725
|
+
# Copy dependency files first
|
|
726
|
+
COPY package.json package-lock.json ./
|
|
727
|
+
RUN npm ci
|
|
728
|
+
|
|
729
|
+
# Copy application code last
|
|
730
|
+
COPY . .
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
2. **Combine RUN Commands:**
|
|
734
|
+
```dockerfile
|
|
735
|
+
# Bad (creates 3 layers)
|
|
736
|
+
RUN apt-get update
|
|
737
|
+
RUN apt-get install -y curl
|
|
738
|
+
RUN rm -rf /var/lib/apt/lists/*
|
|
739
|
+
|
|
740
|
+
# Good (creates 1 layer)
|
|
741
|
+
RUN apt-get update && \
|
|
742
|
+
apt-get install -y --no-install-recommends curl && \
|
|
743
|
+
rm -rf /var/lib/apt/lists/*
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
3. **Multi-Stage Builds:**
|
|
747
|
+
```dockerfile
|
|
748
|
+
# Build stage - can be large
|
|
749
|
+
FROM node:20 AS builder
|
|
750
|
+
WORKDIR /app
|
|
751
|
+
COPY . .
|
|
752
|
+
RUN npm install && npm run build
|
|
753
|
+
|
|
754
|
+
# Production stage - minimal
|
|
755
|
+
FROM node:20-alpine
|
|
756
|
+
COPY --from=builder /app/dist ./dist
|
|
757
|
+
CMD ["node", "dist/index.js"]
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
### Production Readiness
|
|
761
|
+
|
|
762
|
+
1. **Health Checks:**
|
|
763
|
+
```dockerfile
|
|
764
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
765
|
+
CMD curl -f http://localhost:3000/health || exit 1
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
2. **Proper Signals:**
|
|
769
|
+
```dockerfile
|
|
770
|
+
# Use exec form for proper signal handling
|
|
771
|
+
CMD ["node", "server.js"] # Good
|
|
772
|
+
CMD node server.js # Bad (no signal forwarding)
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
3. **Metadata:**
|
|
776
|
+
```dockerfile
|
|
777
|
+
LABEL maintainer="team@example.com" \
|
|
778
|
+
version="1.0.0" \
|
|
779
|
+
description="My application"
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
## Common Patterns
|
|
783
|
+
|
|
784
|
+
### Pattern 1: Node.js with Next.js
|
|
785
|
+
|
|
786
|
+
```dockerfile
|
|
787
|
+
# syntax=docker/dockerfile:1
|
|
788
|
+
FROM node:20-alpine AS deps
|
|
789
|
+
WORKDIR /app
|
|
790
|
+
COPY package*.json ./
|
|
791
|
+
RUN npm ci
|
|
792
|
+
|
|
793
|
+
FROM node:20-alpine AS builder
|
|
794
|
+
WORKDIR /app
|
|
795
|
+
COPY --from=deps /app/node_modules ./node_modules
|
|
796
|
+
COPY . .
|
|
797
|
+
RUN npm run build
|
|
798
|
+
|
|
799
|
+
FROM node:20-alpine AS runner
|
|
800
|
+
WORKDIR /app
|
|
801
|
+
ENV NODE_ENV=production
|
|
802
|
+
RUN addgroup -g 1001 -S nodejs && \
|
|
803
|
+
adduser -S nextjs -u 1001
|
|
804
|
+
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
|
|
805
|
+
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
|
806
|
+
COPY --from=builder /app/node_modules ./node_modules
|
|
807
|
+
COPY --from=builder /app/package.json ./package.json
|
|
808
|
+
USER nextjs
|
|
809
|
+
EXPOSE 3000
|
|
810
|
+
CMD ["npm", "start"]
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
### Pattern 2: Python with FastAPI
|
|
814
|
+
|
|
815
|
+
```dockerfile
|
|
816
|
+
# syntax=docker/dockerfile:1
|
|
817
|
+
FROM python:3.12-slim AS builder
|
|
818
|
+
WORKDIR /app
|
|
819
|
+
# hadolint ignore=DL3008
|
|
820
|
+
RUN apt-get update && apt-get install -y --no-install-recommends gcc && \
|
|
821
|
+
rm -rf /var/lib/apt/lists/*
|
|
822
|
+
COPY requirements.txt .
|
|
823
|
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
824
|
+
|
|
825
|
+
FROM python:3.12-slim
|
|
826
|
+
WORKDIR /app
|
|
827
|
+
RUN useradd -m -u 1001 app
|
|
828
|
+
COPY --from=builder /root/.local /home/app/.local
|
|
829
|
+
COPY --chown=app:app . .
|
|
830
|
+
ENV PATH=/home/app/.local/bin:$PATH \
|
|
831
|
+
PYTHONUNBUFFERED=1 \
|
|
832
|
+
PYTHONDONTWRITEBYTECODE=1
|
|
833
|
+
USER app
|
|
834
|
+
EXPOSE 8000
|
|
835
|
+
HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
|
836
|
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
### Pattern 3: Go CLI Tool
|
|
840
|
+
|
|
841
|
+
```dockerfile
|
|
842
|
+
# syntax=docker/dockerfile:1
|
|
843
|
+
FROM golang:1.21-alpine AS builder
|
|
844
|
+
WORKDIR /app
|
|
845
|
+
COPY go.* ./
|
|
846
|
+
RUN go mod download
|
|
847
|
+
COPY . .
|
|
848
|
+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /bin/app
|
|
849
|
+
|
|
850
|
+
FROM scratch
|
|
851
|
+
COPY --from=builder /bin/app /app
|
|
852
|
+
ENTRYPOINT ["/app"]
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
## Modern Docker Features (2025)
|
|
856
|
+
|
|
857
|
+
### Multi-Platform Builds with BuildX
|
|
858
|
+
|
|
859
|
+
**Use Case:** Build images that work on both AMD64 and ARM64 architectures (e.g., x86 servers and Apple Silicon Macs).
|
|
860
|
+
|
|
861
|
+
**Enable BuildX:**
|
|
862
|
+
```bash
|
|
863
|
+
# BuildX is included in Docker Desktop by default
|
|
864
|
+
# For Linux, ensure BuildX is installed
|
|
865
|
+
docker buildx version
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
**Create Multi-Platform Images:**
|
|
869
|
+
```bash
|
|
870
|
+
# Build for multiple platforms
|
|
871
|
+
docker buildx build \
|
|
872
|
+
--platform linux/amd64,linux/arm64 \
|
|
873
|
+
-t myapp:latest \
|
|
874
|
+
--push \
|
|
875
|
+
.
|
|
876
|
+
|
|
877
|
+
# Build and load for current platform (testing)
|
|
878
|
+
docker buildx build \
|
|
879
|
+
--platform linux/amd64 \
|
|
880
|
+
-t myapp:latest \
|
|
881
|
+
--load \
|
|
882
|
+
.
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
**Dockerfile Considerations:**
|
|
886
|
+
```dockerfile
|
|
887
|
+
# Most Dockerfiles work across platforms automatically
|
|
888
|
+
# Use platform-specific base images when needed
|
|
889
|
+
FROM --platform=$BUILDPLATFORM node:20-alpine AS builder
|
|
890
|
+
|
|
891
|
+
# Access build arguments for platform info
|
|
892
|
+
ARG TARGETPLATFORM
|
|
893
|
+
ARG BUILDPLATFORM
|
|
894
|
+
RUN echo "Building on $BUILDPLATFORM for $TARGETPLATFORM"
|
|
895
|
+
```
|
|
896
|
+
|
|
897
|
+
**When to Use:**
|
|
898
|
+
- Deploying to mixed infrastructure (x86 + ARM)
|
|
899
|
+
- Supporting Apple Silicon Macs in development
|
|
900
|
+
- Optimizing for AWS Graviton (ARM-based) instances
|
|
901
|
+
- Building cross-platform CLI tools
|
|
902
|
+
|
|
903
|
+
### Software Bill of Materials (SBOM)
|
|
904
|
+
|
|
905
|
+
**Use Case:** Generate SBOM for supply chain security and compliance (increasingly required in 2025).
|
|
906
|
+
|
|
907
|
+
**Generate SBOM During Build:**
|
|
908
|
+
```bash
|
|
909
|
+
# Generate SBOM with BuildKit (Docker 24.0+)
|
|
910
|
+
docker buildx build \
|
|
911
|
+
--sbom=true \
|
|
912
|
+
-t myapp:latest \
|
|
913
|
+
.
|
|
914
|
+
|
|
915
|
+
# SBOM is attached as attestation to the image
|
|
916
|
+
# View SBOM
|
|
917
|
+
docker buildx imagetools inspect myapp:latest --format "{{ json .SBOM }}"
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
**Generate SBOM from Existing Image:**
|
|
921
|
+
```bash
|
|
922
|
+
# Using Syft
|
|
923
|
+
syft myapp:latest -o json > sbom.json
|
|
924
|
+
|
|
925
|
+
# Using Docker Scout
|
|
926
|
+
docker scout sbom myapp:latest
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
**SBOM Benefits:**
|
|
930
|
+
- Vulnerability tracking across supply chain
|
|
931
|
+
- License compliance verification
|
|
932
|
+
- Dependency transparency
|
|
933
|
+
- Audit trail for security reviews
|
|
934
|
+
- Required for government/enterprise contracts
|
|
935
|
+
|
|
936
|
+
**Integration with CI/CD:**
|
|
937
|
+
```yaml
|
|
938
|
+
# GitHub Actions example
|
|
939
|
+
- name: Build with SBOM
|
|
940
|
+
run: |
|
|
941
|
+
docker buildx build \
|
|
942
|
+
--sbom=true \
|
|
943
|
+
--provenance=true \
|
|
944
|
+
-t myapp:latest \
|
|
945
|
+
--push \
|
|
946
|
+
.
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
### BuildKit Cache Mounts (Advanced)
|
|
950
|
+
|
|
951
|
+
**Use Case:** Dramatically faster builds by persisting package manager caches across builds.
|
|
952
|
+
|
|
953
|
+
**Already covered in detail in `references/optimization_patterns.md`.**
|
|
954
|
+
|
|
955
|
+
**Quick reference:**
|
|
956
|
+
```dockerfile
|
|
957
|
+
# syntax=docker/dockerfile:1
|
|
958
|
+
|
|
959
|
+
# NPM cache mount (30-50% faster builds)
|
|
960
|
+
RUN --mount=type=cache,target=/root/.npm \
|
|
961
|
+
npm ci
|
|
962
|
+
|
|
963
|
+
# Go module cache
|
|
964
|
+
RUN --mount=type=cache,target=/go/pkg/mod \
|
|
965
|
+
go mod download
|
|
966
|
+
|
|
967
|
+
# Pip cache
|
|
968
|
+
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
969
|
+
pip install -r requirements.txt
|
|
970
|
+
```
|
|
971
|
+
|
|
972
|
+
## Error Handling
|
|
973
|
+
|
|
974
|
+
### Common Generation Issues
|
|
975
|
+
|
|
976
|
+
1. **Missing dependency files:**
|
|
977
|
+
- Ensure package.json, requirements.txt, go.mod, pom.xml exist
|
|
978
|
+
- Ask user to provide or generate template
|
|
979
|
+
|
|
980
|
+
2. **Unknown framework:**
|
|
981
|
+
- Use local references first, then Context7, then web search
|
|
982
|
+
- Fall back to generic template
|
|
983
|
+
- Ask user for specific runtime/build requirements
|
|
984
|
+
|
|
985
|
+
3. **Validation failures:**
|
|
986
|
+
- Apply fixes automatically
|
|
987
|
+
- Iterate until clean
|
|
988
|
+
- Document any suppressions
|
|
989
|
+
|
|
990
|
+
## Integration with Other Skills
|
|
991
|
+
|
|
992
|
+
This skill works well in combination with:
|
|
993
|
+
- **dockerfile-validator** - Validates generated Dockerfiles (REQUIRED)
|
|
994
|
+
- **k8s-yaml-generator** - Generate Kubernetes deployments for the container
|
|
995
|
+
- **helm-generator** - Create Helm charts with the container image
|
|
996
|
+
|
|
997
|
+
## Notes
|
|
998
|
+
|
|
999
|
+
- **Always use multi-stage builds** for compiled languages
|
|
1000
|
+
- **Always create non-root user** for security
|
|
1001
|
+
- **Always generate .dockerignore** to prevent secret leaks
|
|
1002
|
+
- **Always validate** with `dockerfile-validator` (or explicit fallback checks)
|
|
1003
|
+
- **Iterate at least once** if validation finds errors
|
|
1004
|
+
- Use alpine or distroless base images when possible
|
|
1005
|
+
- Pin all version tags (never use :latest)
|
|
1006
|
+
- Clean up package manager caches in same layer
|
|
1007
|
+
- Order Dockerfile instructions from least to most frequently changing
|
|
1008
|
+
- Use BuildKit features for advanced optimization
|
|
1009
|
+
- Test builds locally before committing
|
|
1010
|
+
- Keep Dockerfiles simple and maintainable
|
|
1011
|
+
- Document any non-obvious patterns with comments
|
|
1012
|
+
|
|
1013
|
+
## Done Criteria
|
|
1014
|
+
|
|
1015
|
+
Mark the task done only when all items below are true:
|
|
1016
|
+
- Dockerfile and `.dockerignore` are generated.
|
|
1017
|
+
- Validation has been executed via `dockerfile-validator` or documented fallback commands.
|
|
1018
|
+
- Validate-iterate loop evidence is present (iteration log with command path, counts, and fixes).
|
|
1019
|
+
- No remaining validation `error` findings.
|
|
1020
|
+
- Every remaining `warning` has either a fix or an intentional-deviation report row.
|
|
1021
|
+
- Output includes optimization metrics and actionable next steps.
|
|
1022
|
+
|
|
1023
|
+
## Sources
|
|
1024
|
+
|
|
1025
|
+
This skill is based on comprehensive research from authoritative sources:
|
|
1026
|
+
|
|
1027
|
+
**Official Docker Documentation:**
|
|
1028
|
+
- [Docker Best Practices](https://docs.docker.com/build/building/best-practices/)
|
|
1029
|
+
- [Multi-stage Builds](https://docs.docker.com/get-started/docker-concepts/building-images/multi-stage-builds/)
|
|
1030
|
+
- [Dockerfile Reference](https://docs.docker.com/reference/dockerfile/)
|
|
1031
|
+
|
|
1032
|
+
**Security Guidelines:**
|
|
1033
|
+
- [Dockerfile Best Practices 2025](https://blog.bytescrum.com/dockerfile-best-practices-2025-secure-fast-and-modern)
|
|
1034
|
+
- [Docker Security Best Practices](https://betterstack.com/community/guides/scaling-docker/docker-build-best-practices/)
|
|
1035
|
+
|
|
1036
|
+
**Optimization Resources:**
|
|
1037
|
+
- [Docker Multistage Builds Guide](https://spacelift.io/blog/docker-multistage-builds)
|
|
1038
|
+
- [Building Optimized Docker Images](https://developers-heaven.net/blog/building-optimized-docker-images-dockerfile-best-practices-multi-stage-builds/)
|