feat(http): optional query parameter to update only containers of a specified image (#1289)

* feat(http): optional query parameter to update only containers of a specified image

* fix style issues

* comma separated image parameter

* Support comma-separated query parameter as well as specifying it multiple times

Co-authored-by: nils måsén <nils@piksel.se>

* fixed compile error

* fixed FilterByImageTag

Not sure what changed in my testing setup, but Docker reports image names including the tag name now.

* consistent use of image/tag (use image)

* fixed multiple image queries

* assuming I'm right here, only block on lock when any images are specified.

* add unit tests for image filter. didn't add tests for update api because they didn't already exist

* whoops.

* use ImageName instead, add unit test for empty ImageName filter.

Co-authored-by: nils måsén <nils@piksel.se>
This commit is contained in:
Dirk Kok 2022-06-14 09:13:14 +02:00 committed by GitHub
parent 33b8a9822c
commit 739f328ee5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 96 additions and 8 deletions

View file

@ -70,6 +70,24 @@ func FilterByScope(scope string, baseFilter t.Filter) t.Filter {
}
}
// FilterByImage returns all containers that have a specific image
func FilterByImage(images []string, baseFilter t.Filter) t.Filter {
if images == nil {
return baseFilter
}
return func(c t.FilterableContainer) bool {
image := strings.Split(c.ImageName(), ":")[0]
for _, targetImage := range images {
if image == targetImage {
return baseFilter(c)
}
}
return false
}
}
// BuildFilter creates the needed filter of containers
func BuildFilter(names []string, enableLabel bool, scope string) (t.Filter, string) {
sb := strings.Builder{}