Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): reduce the docker image size #1301

Merged
merged 1 commit into from
May 19, 2023
Merged

chore(cli): reduce the docker image size #1301

merged 1 commit into from
May 19, 2023

Conversation

ysfscream
Copy link
Member

@ysfscream ysfscream commented May 18, 2023

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:

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

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

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

  4. Use of --frozen-lockfile flag: The yarn --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.

image

Please describe the new behavior or provide screenshots.

Does this PR introduce a breaking change?

  • Yes
  • No

Specific Instructions

Are there any specific instructions or things that should be known prior to review?

Other information

@ysfscream ysfscream requested review from wivwiv and Red-Asuka May 18, 2023 11:46
@ysfscream ysfscream self-assigned this May 18, 2023
@ysfscream ysfscream added chore Changes in build tools or dependent packages CLI MQTTX CLI labels May 18, 2023

CMD /bin/bash
CMD /bin/ash

Choose a reason for hiding this comment

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

with the code review.

The patch adds two new build stages, which is a good idea for separating the build processes from running the application. The first stage copies the package.json and yarn.lock files and runs the yarn command to install the dependencies. The second stage copies the built application from the first stage and links the dependencies with yarn link. Finally, the CMD command in the second stage is changed from /bin/bash to /bin/ash.

Overall, the patch looks good. However, it is important to test the application after the changes are applied to make sure everything works as expected. Good luck!

@Red-Asuka Red-Asuka merged commit 4f045ff into main May 19, 2023
@Red-Asuka Red-Asuka deleted the ysf/dev branch May 19, 2023 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes in build tools or dependent packages CLI MQTTX CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants