mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
the "reference" filter was introduced in [moby@820b809] (docker 1.13.0-rc1) to replace the "filter" query argument. That commit initially included a version-gate anticipating the API version to be used for v17.12, but as this was yet unknown, the version-gate was removed in [moby@0f9d22c]. A later PR re-introduced a version-gate in [moby@4a19009], reflecting the API version in which the deprecation was (finally) completed. For the client, [moby@c6e3145] added a fallback was added for older daemons (docker 1.12.0 and older, using API < v1.25) that did not support the new filter. Looking at the above, any version of docker 1.13.0 or above handles the "reference" filter, but (depending on the docker version) may also handle the old filter on API < 1.28 or API < 1.41. Removing this option will only impact daemon versions older than 1.13.0, which are long obsolete. Given that current clients forcibly remove the "reference" filter and replace it with the old "filter" when using API v1.24, we keep support on the daemon side, but update the version to v1.24, and only if no reference filter is set. [moby@820b809]:820b809e70[moby@c6e3145]:c6e31454ba[moby@0f9d22c]:0f9d22cd66[moby@4a19009]:4a1900915aSigned-off-by: Sebastiaan van Stijn <github@gone.nl>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/url"
|
|
|
|
"github.com/moby/moby/api/types/filters"
|
|
"github.com/moby/moby/api/types/image"
|
|
"github.com/moby/moby/api/types/versions"
|
|
)
|
|
|
|
// ImageList returns a list of images in the docker host.
|
|
//
|
|
// Experimental: Set the [image.ListOptions.Manifest] option
|
|
// to include [image.Summary.Manifests] with information about image manifests.
|
|
// This is experimental and might change in the future without any backward
|
|
// compatibility.
|
|
func (cli *Client) ImageList(ctx context.Context, options ImageListOptions) ([]image.Summary, error) {
|
|
var images []image.Summary
|
|
|
|
// Make sure we negotiated (if the client is configured to do so),
|
|
// as code below contains API-version specific handling of options.
|
|
//
|
|
// Normally, version-negotiation (if enabled) would not happen until
|
|
// the API request is made.
|
|
if err := cli.checkVersion(ctx); err != nil {
|
|
return images, err
|
|
}
|
|
|
|
query := url.Values{}
|
|
|
|
if options.Filters.Len() > 0 {
|
|
filterJSON, err := filters.ToJSON(options.Filters)
|
|
if err != nil {
|
|
return images, err
|
|
}
|
|
query.Set("filters", filterJSON)
|
|
}
|
|
if options.All {
|
|
query.Set("all", "1")
|
|
}
|
|
if options.SharedSize && versions.GreaterThanOrEqualTo(cli.version, "1.42") {
|
|
query.Set("shared-size", "1")
|
|
}
|
|
if options.Manifests && versions.GreaterThanOrEqualTo(cli.version, "1.47") {
|
|
query.Set("manifests", "1")
|
|
}
|
|
|
|
resp, err := cli.get(ctx, "/images/json", query, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return images, err
|
|
}
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&images)
|
|
return images, err
|
|
}
|