go-containerregistry icon indicating copy to clipboard operation
go-containerregistry copied to clipboard

Ability to get root index or manifest of an image from v1/layout

Open deitch opened this issue 5 years ago • 9 comments

When I want to get the root ImageIndex or Image from a remote registry, I can call remote.Get. At that point, with an Image or ImageIndex, I can do whatever I need.

If the image already is downloaded to a path using v1/layout, I have to do some processing to get the same root, based on the index.json.

I would like an ability to get the root by a matcher, so I can do Path.Get(someArg) and get back either an Image or an ImageIndex, and then follow the rest of the Path flow just like with remote.

However, unlike remote.Get(), the possible inputs are more than just a tag->hash. It could be anything in a descriptor, since the entry in index.json is a list of manifests, each of which is a full Descriptor.

The simplest I could come up with was:

type Matcher func(desc Descriptor) bool
func (p Path) FindIndex(m Matcher) (ImageIndex, error) { }
func (p Path) FindImage(m Matcher) (Image, error) { }

The caller provides a function that either matches or does not match the descriptor, and returns a bool. The FindIndex/FindImage then can find the right blob, process it, and return the ImageIndex/Image/.

A slightly simpler interface - one that more closely hews to remote.Get() and may allow code reuse, would be:

type Matcher func(desc Descriptor) bool
func (p Path) Find(m Matcher) (*v1.Descriptor, error) { }

Happy to submit a PR once design is agreed.

As discussed offline with @jonjohnsonjr

deitch avatar Nov 05 '20 19:11 deitch