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

Image size include duplicate layers in the total size #38

Open
drudnev opened this issue Feb 20, 2019 · 0 comments
Open

Image size include duplicate layers in the total size #38

drudnev opened this issue Feb 20, 2019 · 0 comments

Comments

@drudnev
Copy link

drudnev commented Feb 20, 2019

When running image size -n {image} you get total size of all layer in all tags . This counts each of the layers toward total size. Most images include base layers in each of the images thus do not need to be counted for each tag.

tag v1.0
layer: xyz
layer: abc

tag v1.1
layer: xyz
layer : cdf

Sum should be xyz + abc + cdf ( not xyz + abc + xyz + cdf )

I propose to pull out the sizeInfo to the outside loop and only count distinct layer to toward total image size.

		sizeInfo := make(map[string]int64)

		for _, tag := range tags {
			manifest, err := r.ImageManifest(imgName, tag)
			if err != nil {
				return cli.NewExitError(err.Error(), 1)
			}


			for _, layer := range manifest.Layers {
				sizeInfo[layer.Digest] = layer.Size
			}


		}

		for _, size := range sizeInfo {
			totalSize += size
		}
		fmt.Printf("%d %s\n", totalSize, imgName)
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

No branches or pull requests

1 participant