mirror of
https://github.com/psviderski/uncloud.git
synced 2026-11-10 12:44:16 +00:00
feat(images): include all tags and digest references when listing images
This commit is contained in:
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"slices"
|
||||
|
||||
"github.com/distribution/reference"
|
||||
"github.com/docker/docker/api/types/image"
|
||||
@@ -42,6 +43,28 @@ type ImageFilter struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// ImageReferences returns the image tag and named digest references, sorted and without duplicates.
|
||||
// References use familiar names such as "alpine:latest" and "alpine@sha256:...".
|
||||
// Bare digests and invalid references are excluded. It returns nil if there are no named references.
|
||||
func ImageReferences(img image.Summary) []string {
|
||||
var refs []string
|
||||
for _, names := range [][]string{img.RepoTags, img.RepoDigests} {
|
||||
for _, name := range names {
|
||||
ref, err := reference.ParseAnyReference(name)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// RepoDigests can contain bare digests. Keep only references with a repository name.
|
||||
if named, ok := ref.(reference.Named); ok {
|
||||
refs = append(refs, reference.FamiliarString(named))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slices.Sort(refs)
|
||||
return slices.Compact(refs)
|
||||
}
|
||||
|
||||
// MachineRemoteImage represents an image in a remote registry fetched by a particular machine.
|
||||
type MachineRemoteImage struct {
|
||||
Metadata *pb.Metadata
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ func (cli *Client) ListImages(ctx context.Context, filter api.ImageFilter) ([]ap
|
||||
// Broadcast the image list request to the specified machines or all machines if none specified.
|
||||
listCtx := ProxyMachinesContext(ctx, filter.Machines)
|
||||
|
||||
opts := image.ListOptions{Manifests: true}
|
||||
opts := image.ListOptions{All: true, Manifests: true}
|
||||
if filter.Name != "" {
|
||||
opts.Filters = filters.NewArgs(
|
||||
filters.Arg("reference", filter.Name),
|
||||
|
||||
Reference in New Issue
Block a user