name: dockerfile-designer description: Activates when asked to create a Dockerfile or when working on a new project in the monorepo. Designs Dockerfiles that follow the monorepo's CI/CD conventions with proper test and final stages.
Dockerfile Designer
Overview
Designs Dockerfiles that comply with the monorepo's CI/CD pipeline requirements. Ensures proper multi-stage builds with test and final stages for seamless integration with GitHub Actions.
When to Use This Skill
- When told "create a Dockerfile" or "design a Dockerfile"
- When creating a new project in
projects/ - When migrating an existing project to use the monorepo CI/CD
- When reviewing a Dockerfile for CI/CD compliance
What the Agent Does
- Check if the project is CI-only (test only) or full CI/CD (test + final)
- Read the project structure and entry point
- Design a multi-stage Dockerfile with appropriate stages
- Include COMMIT_HASH build argument support
- Add pre-docker-build.sh hook if needed
- Validate the Dockerfile against CI/CD requirements
Input and Output
Input:
- Project path (e.g.,
projects/my-app/) - Project type (application, library, tool)
- Whether the project needs deployment (CI/CD) or just testing (CI-only)
Output:
Dockerfile- Multi-stage build configurationpre-docker-build.sh(optional) - Pre-build hook script
Step Details
Step 1: Determine Project Type
Ask or determine:
- Does this project need to be deployed (requires final stage)?
- Is this a library/test tool that only needs validation (CI-only)?
- What is the runtime (Node.js, Python, Go, etc.)?
Project types:
| Type | CI Stage | CD Stage | Use Case |
|---|---|---|---|
| CI-only | test | (none) | Libraries, test tools, validators |
| Full CI/CD | test | final | Applications, services, deployable tools |
Important: CD workflow uses required-stage: final filter. Projects without final stage are skipped during CD and no image is built or pushed.
Step 2: Design the Dockerfile Structure
Create a Dockerfile with these required stages:
# ---- base stage ----
FROM {base-image} AS base
WORKDIR /app
COPY package*.json ./ # or requirements.txt, go.mod, etc.
RUN install-dependencies
# ---- test stage (REQUIRED for CI) ----
FROM base AS test
COPY . .
RUN ./run-tests.sh
# ---- final stage (REQUIRED for CD) ----
FROM base AS final
COPY . .
CMD ["./start.sh"]
Required elements:
AS teststage - CI builds with--target=testAS finalstage - CD builds with--target=final(skip for CI-only)COMMIT_HASHbuild argument - passed by the CI/CD pipeline
Step 3: Include COMMIT_HASH Build Argument
Add this to both test and final stages:
ARG COMMIT_HASH
ENV COMMIT_HASH=${COMMIT_HASH}
This enables version tracking in built images.
Step 4: Add pre-docker-build.sh (Optional)
If the project needs build-time preparation:
- Create
pre-docker-build.shin the project root - Make it executable:
chmod +x pre-docker-build.sh - The CI/CD pipeline runs this before docker build automatically
Example use cases:
- Generate code from templates
- Build frontend assets
- Download external resources
Step 5: Validate Against CI/CD Requirements
Checklist:
- Dockerfile exists in project root
-
teststage exists (FROM ... AS test) -
finalstage exists (for deployable projects) - COMMIT_HASH is accepted as build argument
- File follows best practices (minimal layers, .dockerignore)
Examples
Example 1: CI-Only Project (Library/Test Tool)
Reference: projects/_samples/cicd-ci-sample/Dockerfile
# CI専用 - testステージのみ
FROM alpine:3.21 AS base
ARG COMMIT_HASH=""
WORKDIR /app
FROM base AS test
COPY scripts/ scripts/
COPY tests/ tests/
RUN chmod +x scripts/test.sh && \
./scripts/test.sh
# finalステージはない - CI専用
Example 2: Full CI/CD Project (Application)
Reference: projects/_samples/cicd-cd-sample/Dockerfile
# CD用 - マルチステージビルド
FROM alpine:3.21 AS base
ARG COMMIT_HASH=""
WORKDIR /app
FROM base AS builder
COPY src/ src/
RUN mkdir -p dist && \
cp src/* dist/
FROM base AS final
ARG COMMIT_HASH
ENV APP_VERSION="${COMMIT_HASH}"
COPY --from=builder /app/dist/ dist/
CMD ["cat", "dist/build-info.txt"]
Note: For full CI/CD projects that need PR validation, add a test stage:
FROM base AS test
COPY . .
RUN ./run-tests.sh
Quality Check
- Dockerfile has
teststage defined withAS test - For CI/CD projects:
finalstage exists withAS final - For full CI/CD: both
testandfinalstages exist - COMMIT_HASH build argument is handled
- Base stage is used to share layers between test and final
- Only necessary files are copied (use .dockerignore)
- Commands are ordered by change frequency (dependencies first)
References
docs/about-cicd.md- CI/CD documentationprojects/_samples/cicd-ci-sample/- CI-only sample projectprojects/_samples/cicd-cd-sample/- CD sample project