spikes/containerregistry/main.go
package main
import (
"fmt"
"os"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
)
func main() {
for _, ref := range []string{"hello-world", "postgres:14"} {
parsed, err := name.ParseReference(ref)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
img, err := remote.Image(parsed, remote.WithAuthFromKeychain(authn.DefaultKeychain))
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
digest, err := img.Digest()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(parsed, digest)
}
}