Skip to content

Commit

Permalink
Merge pull request moby#48785 from vvoland/48777-27.x
Browse files Browse the repository at this point in the history
[27.x] c8d/inspect: Fix duplicate RepoDigests
  • Loading branch information
thaJeztah authored Oct 30, 2024
2 parents bad984f + c902e1a commit 15ad1e4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion daemon/containerd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/docker/docker/daemon/images"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/image"
"github.com/docker/docker/internal/sliceutil"
imagespec "github.com/moby/docker-image-spec/specs-go/v1"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -109,7 +110,7 @@ func (i *ImageService) GetImage(ctx context.Context, refOrID string, options bac
}

img.Details = &image.Details{
References: refs,
References: sliceutil.Dedup(refs),
Size: size,
Metadata: nil,
Driver: i.snapshotter,
Expand Down
3 changes: 2 additions & 1 deletion daemon/containerd/image_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
imagetypes "github.com/docker/docker/api/types/image"
timetypes "github.com/docker/docker/api/types/time"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/internal/sliceutil"
"github.com/moby/buildkit/util/attestation"
dockerspec "github.com/moby/docker-image-spec/specs-go/v1"
"github.com/opencontainers/go-digest"
Expand Down Expand Up @@ -501,7 +502,7 @@ func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore con
summary := &imagetypes.Summary{
ParentID: rawImg.Labels[imageLabelClassicBuilderParent],
ID: target.String(),
RepoDigests: repoDigests,
RepoDigests: sliceutil.Dedup(repoDigests),
RepoTags: repoTags,
Size: totalSize,
Labels: cfg.Config.Labels,
Expand Down
25 changes: 25 additions & 0 deletions integration/image/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/docker/docker/api/types/image"
"github.com/docker/docker/internal/testutils/specialimage"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
Expand Down Expand Up @@ -34,3 +35,27 @@ func TestImageInspectEmptyTagsAndDigests(t *testing.T) {
assert.Check(t, is.Len(rawJson["RepoTags"], 0))
assert.Check(t, is.Len(rawJson["RepoDigests"], 0))
}

// Regression test for: https://github.com/moby/moby/issues/48747
func TestImageInspectUniqueRepoDigests(t *testing.T) {
ctx := setupTest(t)

client := testEnv.APIClient()

before, _, err := client.ImageInspectWithRaw(ctx, "busybox")
assert.NilError(t, err)

for _, tag := range []string{"master", "newest"} {
imgName := "busybox:" + tag
err := client.ImageTag(ctx, "busybox", imgName)
assert.NilError(t, err)
defer func() {
_, _ = client.ImageRemove(ctx, imgName, image.RemoveOptions{Force: true})
}()
}

after, _, err := client.ImageInspectWithRaw(ctx, "busybox")
assert.NilError(t, err)

assert.Check(t, is.Len(after.RepoDigests, len(before.RepoDigests)))
}

0 comments on commit 15ad1e4

Please sign in to comment.