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

Reduce image size #20640

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

Conversation

kariya-mitsuru
Copy link

@kariya-mitsuru kariya-mitsuru commented Jun 20, 2024

Comprehensive Summary of your change

Do following actions to reduce the size of the generated images.

  • Change COPY command + chown/chmod command to COPY command + --chown/--chmod option. To prevent both files before/after chown/chmod commands from being recorded on different layers.
  • Put all tdnf commands in a single RUN command and move tdnf clean all command to the end. To prevent the tdnf cache from being recorded on a layer, and the tdnf database from being recorded on multiple layers.
  • Add --link option to COPY command. This does not contribute to image size reduction, but makes image building more efficient.
  • Move chown /etc/pki/tls/certs to the Dockerfile.base. This does not contribute to image size reduction, but is used in conjunction with COPY --link to make image building more efficient.

The target images and their sizes are as follows. (The sizes are the value when built locally)

  • harbor-core : 185MB -> 118MB
  • harbor-db : 285MB -> 263MB
  • harbor-exporter : 108MB -> 79.1MB
  • harbor-jobservice : 159MB -> 105MB
  • harbor-registryctl : 160MB -> 104MB
  • redis-photon : 179MB -> 170 MB
  • standalone-db-migrator : 328MB -> 284MB

Note that harbor-log, harbor-portal, and nginx-photon have almost no effect, and prepare is not directly executed by the user, so they are not included.

Also, registry-photon and trivy-adapter-photon are not included, since PR #20622 and PR #20623 include equivalent action for these two, respectively.

Issue being fixed

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed in website repository.
Do following actions to reduce the size of the generated images.

- Change `COPY` command + `chown`/`chmod` command to `COPY` command +
  `--chown`/`--chmod` option.
  To prevent both files before/after `chown`/`chmod` commands from being
  recorded on different layers.
- Put all `tdnf` commands in a single `RUN` command and move `tdnf clean all`
  command to the end.
  To prevent the `tdnf` cache from being recorded on a layer, and the `tdnf`
  database from being recorded on multiple layers.
- Add `--link` option to `COPY` command.
  This does not contribute to image size reduction, but makes image building
  more efficient.
- Move `chown /etc/pki/tls/certs` to the `Dockerfile.base`.
  This does not contribute to image size reduction, but is used in
  conjunction with `COPY --link` to make image building more efficient.

The target images and their sizes are as follows. (The sizes are the value
when built locally)

- harbor-core : 185MB -> 118MB
- harbor-db : 285MB -> 263MB
- harbor-exporter : 108MB -> 79.1MB
- harbor-jobservice : 159MB -> 105MB
- harbor-registryctl : 160MB -> 104MB
- redis-photon : 179MB -> 170 MB
- standalone-db-migrator : 328MB -> 284MB

Note that harbor-log, harbor-portal, and nginx-photon have almost no effect,
and prepare is not directly executed by the user, so they are not included.

Also, registry-photon and trivy-adapter-photon are not included, since
PR#20622 and PR#20623 include equivalent action for these two, respectively.

Signed-off-by: Mitsuru Kariya <mitsuru.kariya@nttdata.com>
@kariya-mitsuru kariya-mitsuru requested a review from a team as a code owner June 20, 2024 17:11
@MinerYang MinerYang assigned wy65701436 and unassigned Vad1mo, stonezdj and zyyw Jun 24, 2024
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.23%. Comparing base (c8c11b4) to head (b99feb0).
Report is 239 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #20640       +/-   ##
===========================================
+ Coverage   45.36%   66.23%   +20.86%     
===========================================
  Files         244     1045      +801     
  Lines       13333   113501   +100168     
  Branches     2719     2845      +126     
===========================================
+ Hits         6049    75179    +69130     
- Misses       6983    34211    +27228     
- Partials      301     4111     +3810     
Flag Coverage Δ
unittests 66.23% <ø> (+20.86%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1287 files with indirect coverage changes

@Vad1mo Vad1mo added the release-note/infra Infra related changes e.g. release, test, ship etc... label Jun 28, 2024
Copy link
Member

@Vad1mo Vad1mo left a comment

Choose a reason for hiding this comment

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

nice discovery, thank your for your improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/infra Infra related changes e.g. release, test, ship etc...
5 participants