Skip to content

Conversation

Saru2003
Copy link

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

Copy link

changeset-bot bot commented Jul 10, 2025

🦋 Changeset detected

Latest commit: 2e155c8

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

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Copy link
Contributor

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:.

Copy link

@aeworxet
Copy link
Contributor

The GitHub issue #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.

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To Triage
Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Docker images are take too long to build and are quite large.
2 participants