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

Build squash image for size reduction. #52

Closed
ZCube opened this issue Jan 2, 2023 · 4 comments
Closed

Build squash image for size reduction. #52

ZCube opened this issue Jan 2, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@ZCube
Copy link
Owner

ZCube commented Jan 2, 2023

Build squash image for size reduction.

@ZCube ZCube added the enhancement New feature or request label Jan 2, 2023
@ddelange
Copy link
Collaborator

With --squash, the overall size on the registry would increase, because overlapping layers can't be shared across images / image versions anymore.

I'm not sure what the default compression level is, but compression method and compression level can be tweaked: https://github.com/moby/buildkit#imageregistry

You can additionally achieve lazy-pulling capabilities if you set estargz+oci-mediatypes like:

--output type=...,compression=estargz,compression-level=9,oci-mediatypes=true

although I'm not sure if that feature is completely stable.

Regarding sharing layers across builds: to optimize the sharing/re-using there is cache-to: type=inline combined with cache-from type=registry,ref=... combined with --pull in case of upstream security patches. see e.g. actions-runner-controller/releases#3

@ZCube
Copy link
Owner Author

ZCube commented Jan 19, 2023

Bitnami is already using squashed images.

docker inspect bitnami/redis:6.2.10 | jq '.[0].RootFS'
{
  "Type": "layers",
  "Layers": [
    "sha256:bb0dc2a9e4b156523b294481b686606a2a9c048f8c844023e812a7bd7987e90d",
    "sha256:0469306aa3b1df0122ca17a0b982e3d2ac8397486b00b68331bfd6beaf8a7b18"
  ]
}

So Bitnami's Dockerfile operates as a single layer, which eliminates duplication of binary capacity due to factors such as permission changes included in the Dockerfile.
The largest case of this is the Discourse image, which has a difference of about 3590.51MB and 2541.46 MB before and after squash.
I don't care about the cache as squash can be applied after the build.

@ddelange
Copy link
Collaborator

ok awesome and good to know :) thanks!

@ZCube
Copy link
Owner Author

ZCube commented Jan 19, 2023

List of attempts

  1. Using docker-squash : https://github.com/ZCube/bitnami-compat/blob/main/scripts/squash.sh
  • There is a disadvantage that the base image layer is also merged and becomes one layer.
  1. Create Dockerfile.Squash for multistage build :
    func GenerateSquashDockerfile(path string, newPath string, imageTag string) error {
  • The reason is unknown, but the owner information is lost during the copy process.
  • Researching methods using cache mount and rsync...

@ZCube ZCube closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants