fix(create-voltagent-app): render the Dockerfile for the selected package manager

WX
3d ago
+126-15

Description

The generated Dockerfile copied yarn.lock* and pnpm-lock.yaml* unconditionally in both stages and picked the install command at run time with an if [ -f … ] block. Docker requires every COPY source to match a file in the build context, so:

  • an npm project (package-lock.json, no other lockfiles) failed its first docker build at COPY yarn.lock* ./ — the npm fallback in the RUN block was never reached
  • a bun project failed the same way, and its RUN block would have fallen through to npm ci, which cannot work without package-lock.json

The template now carries {{dockerBaseImage}} / {{dockerCopyFiles}} / {{dockerInstall}} / {{dockerInstallProd}} placeholders and a transform renders them from the packageManager the user picked in the wizard (same pattern as the .env.template transform):

  • npm: COPY package*.json + npm ci / npm ci --omit=dev
  • yarn: yarn.lock + corepack enable && yarn install --frozen-lockfile
  • pnpm: pnpm-lock.yaml + corepack enable && pnpm install --frozen-lockfile
  • bun: bun.lock* on the official oven/bun:1-alpine image + bun install --frozen-lockfile

Every stage copies only the lockfile that exists for the project; the .env copy, non-root user, dumb-init and dist handoff are unchanged.

Fixes #1427

Summary by CodeRabbit

  • Bug Fixes
    • Generated Dockerfiles now use the package manager selected during setup, including its appropriate base image and install command.
    • Docker builds now copy the project’s existing lockfile instead of assuming Yarn or pnpm lockfiles are present, improving compatibility with npm and Bun projects.

Summary by cubic

Fixes the generated Dockerfile so the first docker build succeeds for npm and bun projects, which previously failed because the template unconditionally copied yarn.lock* and pnpm-lock.yaml*, and Docker requires every COPY source to exist in the build context.

The template now uses {{dockerBaseImage}}, {{dockerCopyFiles}}, {{dockerInstall}}, and {{dockerInstallProd}} placeholders, rendered from the package manager picked in the wizard:

  • npm: npm ci / npm ci --omit=dev
  • yarn: corepack enable && yarn install --frozen-lockfile
  • pnpm: corepack enable && pnpm install --frozen-lockfile
  • bun: bun install --frozen-lockfile on the oven/bun:1-alpine image

Adds spec coverage for all four package managers. Fixes #1427.