Skip to content

Commit c902e1a

Browse files
committed
c8d/inspect: Fix duplicate RepoDigests
Multiple images with the same repository name but different tag caused the `RepoDigests` to contain duplicated entries for each of the image. Deduplicate the slice before setting the `RepoDigests` field. Signed-off-by: Paweł Gronowski <[email protected]> (cherry picked from commit ba454f5) Signed-off-by: Paweł Gronowski <[email protected]>
1 parent bad984f commit c902e1a

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

daemon/containerd/image.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/docker/docker/daemon/images"
2020
"github.com/docker/docker/errdefs"
2121
"github.com/docker/docker/image"
22+
"github.com/docker/docker/internal/sliceutil"
2223
imagespec "github.com/moby/docker-image-spec/specs-go/v1"
2324
"github.com/opencontainers/go-digest"
2425
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -109,7 +110,7 @@ func (i *ImageService) GetImage(ctx context.Context, refOrID string, options bac
109110
}
110111

111112
img.Details = &image.Details{
112-
References: refs,
113+
References: sliceutil.Dedup(refs),
113114
Size: size,
114115
Metadata: nil,
115116
Driver: i.snapshotter,

daemon/containerd/image_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
imagetypes "github.com/docker/docker/api/types/image"
2323
timetypes "github.com/docker/docker/api/types/time"
2424
"github.com/docker/docker/errdefs"
25+
"github.com/docker/docker/internal/sliceutil"
2526
"github.com/moby/buildkit/util/attestation"
2627
dockerspec "github.com/moby/docker-image-spec/specs-go/v1"
2728
"github.com/opencontainers/go-digest"
@@ -501,7 +502,7 @@ func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore con
501502
summary := &imagetypes.Summary{
502503
ParentID: rawImg.Labels[imageLabelClassicBuilderParent],
503504
ID: target.String(),
504-
RepoDigests: repoDigests,
505+
RepoDigests: sliceutil.Dedup(repoDigests),
505506
RepoTags: repoTags,
506507
Size: totalSize,
507508
Labels: cfg.Config.Labels,

integration/image/inspect_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"testing"
66

7+
"github.com/docker/docker/api/types/image"
78
"github.com/docker/docker/internal/testutils/specialimage"
89
"gotest.tools/v3/assert"
910
is "gotest.tools/v3/assert/cmp"
@@ -34,3 +35,27 @@ func TestImageInspectEmptyTagsAndDigests(t *testing.T) {
3435
assert.Check(t, is.Len(rawJson["RepoTags"], 0))
3536
assert.Check(t, is.Len(rawJson["RepoDigests"], 0))
3637
}
38+
39+
// Regression test for: https://github.com/moby/moby/issues/48747
40+
func TestImageInspectUniqueRepoDigests(t *testing.T) {
41+
ctx := setupTest(t)
42+
43+
client := testEnv.APIClient()
44+
45+
before, _, err := client.ImageInspectWithRaw(ctx, "busybox")
46+
assert.NilError(t, err)
47+
48+
for _, tag := range []string{"master", "newest"} {
49+
imgName := "busybox:" + tag
50+
err := client.ImageTag(ctx, "busybox", imgName)
51+
assert.NilError(t, err)
52+
defer func() {
53+
_, _ = client.ImageRemove(ctx, imgName, image.RemoveOptions{Force: true})
54+
}()
55+
}
56+
57+
after, _, err := client.ImageInspectWithRaw(ctx, "busybox")
58+
assert.NilError(t, err)
59+
60+
assert.Check(t, is.Len(after.RepoDigests, len(before.RepoDigests)))
61+
}

0 commit comments

Comments
 (0)