feat: optimize Dockerfile to reduce image size and build time
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.0as the base image - it includes Chromium out of the box, which is required by some templates. - Added a
.dockerignorefile to exclude unnecessary files likenode_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=devto eliminate devDependencies from the final image. - Switched to a non-root user (
myuser) for safer container execution. - Created a symlink
/usr/local/bin/asyncapiso 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
🦋 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 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-changesetto the PR or remove the changeset and change PR title to something other thanfix:orfeat:.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
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.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
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:
@Saru2003 as the issue has now been removed from bounty program could you please continue your work on this?