mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-27 11:33:33 +00:00
chore(images): filter images by name with wildcard pattern using Docker filter
This commit is contained in:
@@ -28,6 +28,9 @@ type ImageFilter struct {
|
||||
// Machines filters images to those present on the specified machines (names or IDs).
|
||||
// If empty, it matches images on all machines.
|
||||
Machines []string
|
||||
// Name filters images by name (with or without tag). Accepts a wildcard pattern.
|
||||
// If empty, it matches all image names.
|
||||
Name string
|
||||
}
|
||||
|
||||
// MachineRemoteImage represents an image in a remote registry fetched by a particular machine.
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/docker/compose/v2/pkg/progress"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/image"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
@@ -52,6 +53,12 @@ func (cli *Client) ListImages(ctx context.Context, filter api.ImageFilter) ([]ap
|
||||
}
|
||||
|
||||
opts := image.ListOptions{Manifests: true}
|
||||
if filter.Name != "" {
|
||||
opts.Filters = filters.NewArgs(
|
||||
filters.Arg("reference", filter.Name),
|
||||
)
|
||||
}
|
||||
|
||||
optsBytes, err := json.Marshal(opts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal options: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user