diff --git a/internal/registry/registry.go b/internal/registry/registry.go index 10852669..b49e2cf5 100644 --- a/internal/registry/registry.go +++ b/internal/registry/registry.go @@ -13,6 +13,7 @@ import ( "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/remote/transport" + "github.com/google/go-containerregistry/pkg/v1/types" ) var Endpoint = "" @@ -105,7 +106,7 @@ func CacheImage(imageName string, keychain authn.Keychain) error { } auth := remote.WithAuthFromKeychain(keychain) - image, err := remote.Image(sourceRef, auth) + desc, err := remote.Get(sourceRef, auth) if err != nil { if errIsImageNotFound(err) { @@ -114,8 +115,23 @@ func CacheImage(imageName string, keychain authn.Keychain) error { return err } - if err := remote.Write(destRef, image); err != nil { - return err + switch desc.MediaType { + case types.OCIImageIndex, types.DockerManifestList: + index, err := desc.ImageIndex() + if err != nil { + return err + } + if err := remote.WriteIndex(destRef, index); err != nil { + return err + } + default: + image, err := desc.Image() + if err != nil { + return err + } + if err := remote.Write(destRef, image); err != nil { + return err + } } return nil }