From 47d2590a657e762498cbbcab76a4ea2eb9801f16 Mon Sep 17 00:00:00 2001 From: Hennadii Mykhailiuta Date: Fri, 23 Jun 2023 22:47:59 +0200 Subject: [PATCH] feat(controller): multi-platform images support --- internal/registry/registry.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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 }