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

Dockerfile: reduce karmada website container image size by 28% #771

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mohamedawnallah
Copy link

@mohamedawnallah mohamedawnallah commented Dec 23, 2024

Description

This commit optimizes the Karmada website's Docker container, reducing the image size from ~796MB to ~570MB, achieving a significant ~28% reduction.

The size reduction was achieved by:

  • Using a multi-stage build approach: One stage for building the Node modules and another for running the server runtime.
  • Consolidating RUN commands: Combining multiple RUN operations to reduce intermediate tarball files generated during those operations.

What type of PR is this?

/kind cleanup

Which issue(s) this PR fixes:
N/A

Special Notes for Reviewers:

  • Verification:
    This optimization can be verified by comparing Docker image builds before and after the changes:
    Docker Optimization Before and After

  • Further Debugging:
    For deeper insights, the optimization can be analyzed using dive, a tool for exploring each layer in a Docker image.

@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Dec 23, 2024
@karmada-bot
Copy link
Collaborator

Welcome @mohamedawnallah! It looks like this is your first PR to karmada-io/website 🎉

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 23, 2024
@mohamedawnallah
Copy link
Author

Hi @XiShanYongYe-Chang, @zhzhuang-zju,

I’ve submitted that PR and would appreciate any feedback you may have. Looking forward to your thoughts! 🙏

@zhzhuang-zju
Copy link
Contributor

@mohamedawnallah Good job~ I'm not very good at this, but from your validation, it does look like a great optimization. With this optimization, is it possible to optimize the Karmada components images?

@mohamedawnallah
Copy link
Author

is it possible to optimize the Karmada components images?

Yes, I would love to optimize the Karmada components images if I see any opportunities for optimization. I'm just wondering where the Dockerfiles are located?

@zhzhuang-zju
Copy link
Contributor

I'm just wondering where the Dockerfiles are located?

you can find them in https://github.com/karmada-io/karmada/tree/master/cluster/images

@mohamedawnallah
Copy link
Author

you can find them in https://github.com/karmada-io/karmada/tree/master/cluster/images

Thanks for sharing this! 🙏 I’ll take a look at them by the end of the day and submit a PR if I spot any opportunities for optimization. At first glance, I see that we could group the RUN commands together, and I’ll check for any other potential improvements.

Copy link
Member

@samzong samzong left a comment

Choose a reason for hiding this comment

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

great!

@mohamedawnallah
Copy link
Author

from your validation, it does look like a great optimization. With this optimization, is it possible to optimize the Karmada components images?

@zhzhuang-zju I reviewed the Dockerfile specifications for all Karmada component images on Docker Hub (those prefixed with karmada/), and they are already optimized as of the time of writing this comment. While a few KBs could be saved by combining RUN commands, I think it's unnecessary and could reduce the readability of the Dockerfile.

@mohamedawnallah
Copy link
Author

Regards that PR, How am I supposed to move it forward?

cc: @XiShanYongYe-Chang, @zhzhuang-zju

Copy link
Contributor

@zhzhuang-zju zhzhuang-zju left a comment

Choose a reason for hiding this comment

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

Regards that PR, How am I supposed to move it forward?

If all the CI checks pass and there is no impact on the deployment of the website, then it's ok with me.

@XiShanYongYe-Chang
Copy link
Member

Thanks @mohamedawnallah
/assign @samzong

@mohamedawnallah mohamedawnallah force-pushed the optimizeKarmadaWebsiteDockerImage branch from 745082d to a6c8e2c Compare February 25, 2025 10:21
@samzong
Copy link
Member

samzong commented Feb 25, 2025

/approve
/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 25, 2025
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: samzong
Once this PR has been reviewed and has the lgtm label, please assign rainbowmango for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@XiShanYongYe-Chang
Copy link
Member

Hi @mohamedawnallah, the CI is failed.

@zhzhuang-zju
Copy link
Contributor

Hi @mohamedawnallah, the CI is failed.

#764 has encountered the same error. I suspect that it is caused by fluctuations in the CI operating environment.

/retest

@mohamedawnallah
Copy link
Author

mohamedawnallah commented Feb 26, 2025

It seems the CI hasn't been re-triggered after /retest and also after closing and reopening the PR?

@zhzhuang-zju
Copy link
Contributor

/retest

@zhzhuang-zju
Copy link
Contributor

It seems the CI hasn't been re-triggered after /retest and also after closing and reopening the PR?

Yeah, for some reason, /retest doesn't work. You can try to update your commit to trigger ci.

@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 26, 2025
@mohamedawnallah mohamedawnallah force-pushed the optimizeKarmadaWebsiteDockerImage branch from 32ddd3d to 99bdedb Compare February 26, 2025 01:49
@mohamedawnallah
Copy link
Author

mohamedawnallah commented Feb 26, 2025

I've seen this issue in the netlify deployment error:

12:42:35 PM: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

I've updated netlify.toml to increase the memory allocation for NodeJS up to 4GB. May be this solve the issue entirely.

[build]
command = "NODE_OPTIONS=\"--max_old_space_size=4096\" yarn run build"

Not sure if netlify CI should be triggered automatically here

EDIT:
Yes I found them running here let's see:
https://app.netlify.com/sites/karmada/deploys/67be733528974f00082a028d

@XiShanYongYe-Chang
Copy link
Member

The CI is passed, thanks~
/lgtm
/cc @RainbowMango

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 26, 2025
@karmada-bot
Copy link
Collaborator

New changes are detected. LGTM label has been removed.

@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 27, 2025
@RainbowMango
Copy link
Member

Could you please squash the commits? And I think we are ready to go after that.

mohamedawnallah and others added 2 commits February 27, 2025 14:40
Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
Co-authored-by: zhzhuang-zju <m17799853869@163.com>
Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
Co-authored-by: Hongcai Ren <renhongcai@huawei.com>
@mohamedawnallah mohamedawnallah force-pushed the optimizeKarmadaWebsiteDockerImage branch from 207b160 to 655bb60 Compare February 27, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants