mirror of
https://github.com/docker/cli.git
synced 2026-09-24 07:25:07 -05:00
Merge pull request #15693 from vdemeester/15659-image-label-filter
Fix #15659 : filter by label for docker images commited Upstream-commit: 41c99cc62161376981d1c24f30c0e340124778e8 Component: engine
This commit is contained in:
@@ -108,17 +108,19 @@ func (s *TagStore) Images(filterArgs, filter string, all bool) ([]*types.Image,
|
||||
} else {
|
||||
// get the boolean list for if only the untagged images are requested
|
||||
delete(allImages, id)
|
||||
if !imageFilters.MatchKVList("label", image.ContainerConfig.Labels) {
|
||||
continue
|
||||
|
||||
if len(imageFilters["label"]) > 0 {
|
||||
if image.Config == nil {
|
||||
// Very old image that do not have image.Config (or even labels)
|
||||
continue
|
||||
}
|
||||
// We are now sure image.Config is not nil
|
||||
if !imageFilters.MatchKVList("label", image.Config.Labels) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if filtTagged {
|
||||
newImage := new(types.Image)
|
||||
newImage.ParentID = image.Parent
|
||||
newImage.ID = image.ID
|
||||
newImage.Created = image.Created.Unix()
|
||||
newImage.Size = image.Size
|
||||
newImage.VirtualSize = s.graph.GetParentsSize(image) + image.Size
|
||||
newImage.Labels = image.ContainerConfig.Labels
|
||||
newImage := newImage(image, s.graph.GetParentsSize(image))
|
||||
|
||||
if utils.DigestReference(ref) {
|
||||
newImage.RepoTags = []string{}
|
||||
@@ -144,18 +146,19 @@ func (s *TagStore) Images(filterArgs, filter string, all bool) ([]*types.Image,
|
||||
// Display images which aren't part of a repository/tag
|
||||
if filter == "" || filtLabel {
|
||||
for _, image := range allImages {
|
||||
if !imageFilters.MatchKVList("label", image.ContainerConfig.Labels) {
|
||||
continue
|
||||
if len(imageFilters["label"]) > 0 {
|
||||
if image.Config == nil {
|
||||
// Very old image that do not have image.Config (or even labels)
|
||||
continue
|
||||
}
|
||||
// We are now sure image.Config is not nil
|
||||
if !imageFilters.MatchKVList("label", image.Config.Labels) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
newImage := new(types.Image)
|
||||
newImage.ParentID = image.Parent
|
||||
newImage := newImage(image, s.graph.GetParentsSize(image))
|
||||
newImage.RepoTags = []string{"<none>:<none>"}
|
||||
newImage.RepoDigests = []string{"<none>@<none>"}
|
||||
newImage.ID = image.ID
|
||||
newImage.Created = image.Created.Unix()
|
||||
newImage.Size = image.Size
|
||||
newImage.VirtualSize = s.graph.GetParentsSize(image) + image.Size
|
||||
newImage.Labels = image.ContainerConfig.Labels
|
||||
|
||||
images = append(images, newImage)
|
||||
}
|
||||
@@ -165,3 +168,16 @@ func (s *TagStore) Images(filterArgs, filter string, all bool) ([]*types.Image,
|
||||
|
||||
return images, nil
|
||||
}
|
||||
|
||||
func newImage(image *image.Image, parentSize int64) *types.Image {
|
||||
newImage := new(types.Image)
|
||||
newImage.ParentID = image.Parent
|
||||
newImage.ID = image.ID
|
||||
newImage.Created = image.Created.Unix()
|
||||
newImage.Size = image.Size
|
||||
newImage.VirtualSize = parentSize + image.Size
|
||||
if image.Config != nil {
|
||||
newImage.Labels = image.Config.Labels
|
||||
}
|
||||
return newImage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user