AgentSkillsCN

dockerfile-gen

通过检测堆栈(Next.js 或 Hono)为每个项目生成一个 Dockerfile。输出结果可以是带有 Next.js 独立构建的 Node.js 镜像(环境变量 → ARGs,pnpm),也可以是带有 Hono/rolldown Vite 构建的 Node.js 镜像(pnpm)。当用户请求生成 Dockerfile 或对 Next.js 或 Hono 应用进行容器化时使用此工具。

SKILL.md
--- frontmatter
name: dockerfile-gen
description: Generates a single Dockerfile per project by detecting stack (Next.js or Hono). Output is either a Node.js image with Next.js standalone build (env→ARGs, pnpm) or a Node.js image with Hono/rolldown vite build (pnpm). Use when the user asks for a Dockerfile or containerizing a Next.js or Hono app.

Dockerfile Generation (Next.js or Hono)

Generate one Dockerfile per project. Detect the stack (Next.js or Hono) and output the matching variant:

StackOutput imageReference
Next.jsNode.js image with Next.js buildnextjs.md
HonoNode.js image with rolldown/vite buildhono.md

Do not combine both stacks in one Dockerfile. If the app is Next.js, follow nextjs.md only; if Hono, follow hono.md only.


Package manager

Use pnpm when possible, not npm. Prefer pnpm unless the project has no pnpm-lock.yaml (or equivalent) and explicitly uses npm.

  • In the Dockerfile base image, enable pnpm via Corepack: RUN corepack enable pnpm (Node 16.9+).
  • Install deps: pnpm install --frozen-lockfile (or pnpm ci where available).
  • Run scripts: pnpm run build, pnpm run start, etc.

Workflow checklist

When generating a Dockerfile:

  1. Detect stack: Is the app Next.js (e.g. next in deps, next.config.*) or Hono (e.g. hono in deps, Vite config)? Choose one variant.
  2. Next.js → Read nextjs.md and apply its rules (grep .env → ARGs, standalone output, pnpm).
  3. Hono → Read hono.md and apply its rules (rolldown/vite build, pnpm).
  4. Package manager: Use pnpm when possible; fall back to npm only if no pnpm lockfile.
  5. Use multi-stage builds: build stage for deps + build, final stage minimal (Node.js + app only).
  6. Do not bake secrets into the image; document passing them at runtime.