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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
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

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

# Set environment variable
ENV NODE_ENV=development
# Stage 2: Development Stage.
FROM alpine:latest
Copy link
Member

Choose a reason for hiding this comment

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

I understand that the final image is based on alpine:latest, and node:18-alpine was used before. Does it matter?

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.

4 participants