chore(images): filter images by name with wildcard pattern using Docker filter

This commit is contained in:
Pasha Sviderski
2025-10-08 12:33:13 +10:00
parent 1f9c2c873d
commit a2c6cbe633
3 changed files with 17 additions and 37 deletions
+3
View File
@@ -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.
+7
View File
@@ -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)