c8d/delete: Support deleting specific platforms

This change adds the ability to delete a specific platform from a
multi-platform image.

Previously, image deletion was an all-or-nothing operation - when
deleting a multi-platform image, all platforms would be removed
together. This change allows users to selectively remove individual
platforms from a multi-architecture image while keeping other platforms
intact.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-05-13 18:46:18 +02:00
parent acf6b6542e
commit 30da69d694
11 changed files with 270 additions and 19 deletions

View File

@@ -12,6 +12,7 @@ import (
cerrdefs "github.com/containerd/errdefs"
"github.com/docker/docker/api/types/image"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@@ -40,6 +41,7 @@ func TestImageRemove(t *testing.T) {
removeCases := []struct {
force bool
pruneChildren bool
platform *ocispec.Platform
expectedQueryParams map[string]string
}{
{
@@ -49,7 +51,8 @@ func TestImageRemove(t *testing.T) {
"force": "",
"noprune": "1",
},
}, {
},
{
force: true,
pruneChildren: true,
expectedQueryParams: map[string]string{
@@ -57,6 +60,15 @@ func TestImageRemove(t *testing.T) {
"noprune": "",
},
},
{
platform: &ocispec.Platform{
Architecture: "amd64",
OS: "linux",
},
expectedQueryParams: map[string]string{
"platforms": `{"architecture":"amd64","os":"linux"}`,
},
},
}
for _, removeCase := range removeCases {
client := &Client{
@@ -92,10 +104,16 @@ func TestImageRemove(t *testing.T) {
}, nil
}),
}
imageDeletes, err := client.ImageRemove(context.Background(), "image_id", image.RemoveOptions{
opts := image.RemoveOptions{
Force: removeCase.force,
PruneChildren: removeCase.pruneChildren,
})
}
if removeCase.platform != nil {
opts.Platforms = []ocispec.Platform{*removeCase.platform}
}
imageDeletes, err := client.ImageRemove(context.Background(), "image_id", opts)
assert.NilError(t, err)
assert.Check(t, is.Len(imageDeletes, 2))
}