chore(cli): reduce the docker image size #1301
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
If you have any questions, you can refer to the Contributing Guide
What is the current behavior?
Please describe the current behavior and link to a relevant issue.
Issue Number
Example: #123
What is the new behavior?
This Dockerfile incorporates several common practices to optimize the image size and reduce the final image's overall size:
Multi-stage builds: It uses multiple build stages (build and runtime) to separate the build process from the final runtime image. The build stage is responsible for compiling and building the application, while only necessary files are copied from it to the runtime stage. This helps to avoid including build tools and dependencies in the final image, resulting in a smaller image size.
Lightweight base image: The Dockerfile selects
node:16-alpine
as the base image. The Alpine version of the Node.js image is relatively smaller. Alpine Linux is a lightweight Linux distribution that provides the required functionality while keeping the image size minimal.Avoid unnecessary file copying: Only the necessary files are copied from the build stage to the final runtime stage. By copying only the required files, redundant content is minimized, reducing the overall size of the image.
Use of
--frozen-lockfile
flag: Theyarn --frozen-lockfile
command is used in the build stage to install dependencies. This flag ensures that the versions specified in the lockfile (yarn.lock
) remain frozen, providing better reproducibility of the build.By implementing these optimization techniques, the Dockerfile effectively reduces the image size, resulting in more efficient image building and deployment processes.
Please describe the new behavior or provide screenshots.
Does this PR introduce a breaking change?
Specific Instructions
Are there any specific instructions or things that should be known prior to review?
Other information