abra/pkg/client/registry.go

29 lines
649 B
Go
Raw Normal View History

2021-08-06 13:40:23 +00:00
package client
import (
"context"
"fmt"
"github.com/containers/image/docker"
"github.com/containers/image/types"
2021-08-10 10:21:42 +00:00
"github.com/docker/distribution/reference"
2021-08-06 13:40:23 +00:00
)
// GetRegistryTags retrieves all tags of an image from a container registry.
func GetRegistryTags(img reference.Named) ([]string, error) {
var tags []string
ref, err := docker.ParseReference(fmt.Sprintf("//%s", img))
2021-08-10 10:21:42 +00:00
if err != nil {
return tags, fmt.Errorf("failed to parse image %s, saw: %s", img, err.Error())
}
ctx := context.Background()
tags, err = docker.GetRepositoryTags(ctx, &types.SystemContext{}, ref)
2021-08-10 10:21:42 +00:00
if err != nil {
return tags, err
2021-08-10 10:21:42 +00:00
}
return tags, nil
2021-08-10 10:21:42 +00:00
}