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

new command: crane size #1916

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

new command: crane size #1916

wants to merge 1 commit into from

Conversation

imjasonh
Copy link
Collaborator

@imjasonh imjasonh commented Apr 9, 2024

This adds crane size which returns the total compressed size of blobs referenced by a manifest. This can be useful to roughly determine the relative size of two images in a registry, and over the wire.

This won't tell you how many uncompressed bytes the image might take up if you pull it locally.

go run ./cmd/crane size ubuntu                               
146051085

go run ./cmd/crane size ubuntu --human                       
139 MiB

go run ./cmd/crane size ubuntu --platform=linux/arm64
27361037

go run ./cmd/crane size ubuntu --platform=linux/ppc64le
34496056

go run ./cmd/crane size ubuntu --platform=linux/s390x --human
27 MiB

It forks some code from https://github.com/dustin/go-humanize/blob/master/bytes.go which hasn't been changed in 7 years, so it's expected to be pretty stable. This avoids taking a full dependency on the package, which overall does get occasional updates.

Open to ideas about other things we may want to support with this. This is a Go port of this one-liner that I use pretty often:

function imgsize() {
  crane manifest $1 --platform ${2:-linux/amd64} | jq '.config.size + ([.layers[].size] | add)' | numfmt --to=iec
}

Signed-off-by: Jason Hall <jason@chainguard.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant