Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@PeterDaveHello
Copy link
Contributor

Context

Optimize the CLI Docker images by reducing build context size, trimming Debian
install recommendations, and failing early when VERSION is missing.

Implementation

  • Add .dockerignore to keep build context minimal while retaining dist/.
  • Use --no-install-recommends for Debian dependencies.
  • Clean npm cache after global install to reduce image size.
  • Validate VERSION build arg in both final stages to provide a clear error.

How to Test

  • From repo root:
pnpm install
pnpm cli:bundle
(cd cli/dist && npm pack)

cd cli
VERSION=$(node -p "require('./package.json').version")
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
VCS_REF=$(git rev-parse HEAD)

docker build --target alpine \
  --build-arg VERSION=$VERSION \
  --build-arg BUILD_DATE=$BUILD_DATE \
  --build-arg VCS_REF=$VCS_REF \
  -t kilocode-cli:alpine .

docker build --target debian \
  --build-arg VERSION=$VERSION \
  --build-arg BUILD_DATE=$BUILD_DATE \
  --build-arg VCS_REF=$VCS_REF \
  -t kilocode-cli:debian .

GitHub Copilot summary

This pull request improves the Docker build for the CLI by cleaning up the build context, enforcing best practices, and optimizing image size. The most important changes include adding a .dockerignore file to exclude unnecessary files, validating required build arguments, and cleaning up the npm cache after installation.

Docker build context and image optimization:

  • Added a new .dockerignore file to exclude dependencies, build cache, local data, source files, documentation, config files, git files, logs, and all markdown files except README.md, reducing build context size and improving build performance.
  • Updated cli/Dockerfile to use --no-install-recommends when installing system dependencies, minimizing unnecessary packages and reducing image size.

Build reliability and correctness:

  • Added a check in cli/Dockerfile to ensure the VERSION build argument is provided, failing the build with a clear error message if missing. [1] [2]

Post-installation cleanup:

  • Modified the npm installation step in cli/Dockerfile to clean the npm cache after installing the CLI package, further reducing image size. [1] [2]

Get in Touch

@PeterDaveHello

Reduce build context size while keeping the dist archive available for install.
Use `apt-get install` with `--no-install-recommends`, and clear npm
cache to reduce image size.
Fail early when VERSION is missing to avoid unclear COPY errors during
image builds.
@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2026

⚠️ No Changeset found

Latest commit: a68d311

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant