feat: proxy download image
This commit is contained in:
61
x/t2/main.go
Normal file
61
x/t2/main.go
Normal file
@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/google/go-containerregistry/pkg/name"
|
||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||
"io"
|
||||
"log"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||
defer cancel()
|
||||
|
||||
puller, err := remote.NewPuller()
|
||||
if err != nil {
|
||||
log.Panic(1, err)
|
||||
}
|
||||
|
||||
//imageName := "loveuer/hello:v2.0.1"
|
||||
imageName := "alpine:latest"
|
||||
tn, err := name.NewTag(imageName)
|
||||
if err != nil {
|
||||
log.Panic(2, err)
|
||||
}
|
||||
|
||||
des, err := puller.Get(ctx, tn)
|
||||
if err != nil {
|
||||
log.Panic(3, err)
|
||||
}
|
||||
|
||||
img, err := des.Image()
|
||||
if err != nil {
|
||||
log.Panic(4, err)
|
||||
}
|
||||
|
||||
lys, err := img.Layers()
|
||||
if err != nil {
|
||||
log.Panic(5, err)
|
||||
}
|
||||
|
||||
rs := make([]io.Reader, 0)
|
||||
for _, item := range lys {
|
||||
r, err := item.Uncompressed()
|
||||
if err != nil {
|
||||
log.Panic(6, err)
|
||||
}
|
||||
|
||||
rs = append(rs, r)
|
||||
}
|
||||
|
||||
allr := io.MultiReader(rs...)
|
||||
bs, err := io.ReadAll(allr)
|
||||
if err != nil {
|
||||
log.Panic(7, err)
|
||||
}
|
||||
|
||||
log.Printf("size: %.2f MB", float64(len(bs))/1024/1024)
|
||||
}
|
Reference in New Issue
Block a user