29 lines
649 B
Go
29 lines
649 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/containers/image/docker"
|
|
"github.com/containers/image/types"
|
|
"github.com/docker/distribution/reference"
|
|
)
|
|
|
|
// 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))
|
|
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)
|
|
if err != nil {
|
|
return tags, err
|
|
}
|
|
|
|
return tags, nil
|
|
}
|