cli icon indicating copy to clipboard operation
cli copied to clipboard

feat: optimize Dockerfile to reduce image size and build time

Open Saru2003 opened this issue 5 months ago • 6 comments

Description

This PR optimizes the Docker build process for the AsyncAPI CLI. The current Docker image is large and takes a long time to build. These changes address both of those concerns:

Changes Made:

  • Rewrote the Dockerfile using a multi-stage build to separate dependencies and runtime.
  • Switched to ghcr.io/puppeteer/puppeteer:20.8.0 as the base image - it includes Chromium out of the box, which is required by some templates.
  • Added a .dockerignore file to exclude unnecessary files like node_modules, .git, test, etc., reducing build context.
  • Removed unused dev tools and temporary folders post-build to slim down the image.
  • Used npm prune --omit=dev to eliminate devDependencies from the final image.
  • Switched to a non-root user (myuser) for safer container execution.
  • Created a symlink /usr/local/bin/asyncapi so the CLI can be invoked directly.

Performance Comparison

Image Tag Size (GB) Build Time (s) Size Reduction Build Time Improvement
asyncapi-cli-unoptimized 5.53 GB 530 s
asyncapi-cli-revised 4.32 GB 245 s ↓ 1.21 GB (↓21.88%) ↓ 285 s (↓53.77%)

Build and runtime tested locally using a fork of the repository.


How to Build & Run

docker build -t asyncapi-cli.

docker run -it --entrypoint sh asyncapi-cli

asyncapi --version

Related issue(s) Resolves #1798

Saru2003 avatar Jul 10 '25 12:07 Saru2003

🦋 Changeset detected

Latest commit: 2e155c89068cc9b58d705eba942c985511f3d0e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Minor

Not sure what this means? Click here to learn what changesets are.

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

changeset-bot[bot] avatar Jul 10 '25 12:07 changeset-bot[bot]

Changeset has been generated for this PR as part of auto-changeset workflow.

Please review the changeset before merging the PR.
---
'@asyncapi/cli': minor
---

feat: optimize Dockerfile to reduce image size and build time

- 4b0017d: build: optimize Dockerfile and add .dockerignore to reduce image size

If you are a maintainer or the author of the PR, you can change the changeset by clicking here

[!TIP] If you don't want auto-changeset to run on this PR, you can add the label skip-changeset to the PR or remove the changeset and change PR title to something other than fix: or feat:.

github-actions[bot] avatar Jul 10 '25 12:07 github-actions[bot]

The GitHub issue https://github.com/asyncapi/cli/issues/1798 participates in the strictly serial AsyncAPI Bounty Program and is the responsibility of the assigned user.

You are welcome to choose another GitHub issue for contribution.

aeworxet avatar Jul 30 '25 10:07 aeworxet

This pull request has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation.

There can be many reasons why some specific pull request has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this pull request forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Dec 13 '25 00:12 github-actions[bot]

@Saru2003 as the issue has now been removed from bounty program could you please continue your work on this?

Shurtu-gal avatar Dec 17 '25 13:12 Shurtu-gal