fix local image removal when compose down is ran with --project-name (#10558)

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De loof 2023-05-11 18:41:14 +02:00 committed by GitHub
parent 0e375a8c61
commit 0363d9260a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 9 deletions

View File

@ -223,6 +223,7 @@ func TestDownRemoveImages(t *testing.T) {
localImagesToBeRemoved := []string{
"testproject-local-anonymous:latest",
"local-named-image:latest",
}
for _, img := range localImagesToBeRemoved {
// test calls down --rmi=local then down --rmi=all, so local images
@ -238,7 +239,6 @@ func TestDownRemoveImages(t *testing.T) {
assert.NilError(t, err)
otherImagesToBeRemoved := []string{
"local-named-image:latest",
"remote-image:latest",
"registry.example.com/remote-image-tagged:v1.0",
}

View File

@ -107,14 +107,8 @@ func (p *ImagePruner) ImagesToPrune(ctx context.Context, opts ImagePruneOptions)
// removed from YAML)
shouldPrune = true
} else {
// only prune the image if it belongs to a known service for the
// project AND is either an implicitly-named, locally-built image
// or `--rmi=all` has been specified.
// TODO(milas): now that Compose labels the images it builds, this
// makes less sense; arguably, locally-built but explicitly-named
// images should be removed with `--rmi=local` as well.
service, err := p.project.GetService(img.Labels[api.ServiceLabel])
if err == nil && (opts.Mode == ImagePruneAll || service.Image == "") {
// only prune the image if it belongs to a known service for the project.
if _, err := p.project.GetService(img.Labels[api.ServiceLabel]); err == nil {
shouldPrune = true
}
}