Last active
August 14, 2020 09:35
-
-
Save mkmik/ad47a519fe2b3dd1103755984efe2d59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in $(crane ls bitnami/node | grep -E '^[0-9]+'); do crane manifest bitnami/node:$i; done >/tmp/layers.jsonish |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"errors" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
) | |
type image struct { | |
Layers []layer `json:"layers"` | |
} | |
type layer struct { | |
Size int `json:"size"` | |
Digest string `json:"digest"` | |
} | |
func mainE() error { | |
dec := json.NewDecoder(os.Stdin) | |
blobs := map[string]int{} | |
imagesTotal := 0 | |
ociImagesTotal := 0 | |
stupidTotal := 0 | |
for { | |
var img image | |
err := dec.Decode(&img) | |
if errors.Is(err, io.EOF) { | |
break | |
} | |
if err != nil { | |
return err | |
} | |
imagesTotal++ | |
if img.Layers != nil { | |
ociImagesTotal++ | |
} | |
for _, l := range img.Layers { | |
stupidTotal += l.Size | |
blobs[l.Digest] = l.Size | |
} | |
} | |
total := 0 | |
for _, s := range blobs { | |
total += s | |
} | |
fmt.Printf("Total images: %d\n", imagesTotal) | |
fmt.Printf("Total OCI images: %d\n", ociImagesTotal) | |
fmt.Printf("Undeduplicated total: %d GB\n", stupidTotal/1024/1024/1024) | |
fmt.Printf("Total: %d GB\n", total/1024/1024/1024) | |
fmt.Printf("Saving %.2f%%\n", (1-float64(total)/float64(stupidTotal))*100) | |
return nil | |
} | |
func main() { | |
if err := mainE(); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment