mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #35790 from thaJeztah/image-shortid
Remove support for referencing images by 'repository:shortid'
This commit is contained in:
commit
6796e740fd
3 changed files with 4 additions and 47 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// errImageDoesNotExist is error returned when no image can be found for a reference.
|
// errImageDoesNotExist is error returned when no image can be found for a reference.
|
||||||
|
@ -59,21 +58,6 @@ func (daemon *Daemon) GetImageIDAndOS(refOrID string) (image.ID, string, error)
|
||||||
return id, imageOS, nil
|
return id, imageOS, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// deprecated: repo:shortid https://github.com/docker/docker/pull/799
|
|
||||||
if tagged, ok := namedRef.(reference.Tagged); ok {
|
|
||||||
if tag := tagged.Tag(); stringid.IsShortID(stringid.TruncateID(tag)) {
|
|
||||||
for platform := range daemon.stores {
|
|
||||||
if id, err := daemon.stores[platform].imageStore.Search(tag); err == nil {
|
|
||||||
for _, storeRef := range daemon.referenceStore.References(id.Digest()) {
|
|
||||||
if storeRef.Name() == namedRef.Name() {
|
|
||||||
return id, platform, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search based on ID
|
// Search based on ID
|
||||||
for os := range daemon.stores {
|
for os := range daemon.stores {
|
||||||
if id, err := daemon.stores[os].imageStore.Search(refOrID); err == nil {
|
if id, err := daemon.stores[os].imageStore.Search(refOrID); err == nil {
|
||||||
|
|
|
@ -268,7 +268,6 @@ func (s *DockerSuite) TestCreateByImageID(c *check.C) {
|
||||||
|
|
||||||
dockerCmd(c, "create", imageID)
|
dockerCmd(c, "create", imageID)
|
||||||
dockerCmd(c, "create", truncatedImageID)
|
dockerCmd(c, "create", truncatedImageID)
|
||||||
dockerCmd(c, "create", fmt.Sprintf("%s:%s", imageName, truncatedImageID))
|
|
||||||
|
|
||||||
// Ensure this fails
|
// Ensure this fails
|
||||||
out, exit, _ := dockerCmdWithError("create", fmt.Sprintf("%s:%s", imageName, imageID))
|
out, exit, _ := dockerCmdWithError("create", fmt.Sprintf("%s:%s", imageName, imageID))
|
||||||
|
@ -280,7 +279,10 @@ func (s *DockerSuite) TestCreateByImageID(c *check.C) {
|
||||||
c.Fatalf(`Expected %q in output; got: %s`, expected, out)
|
c.Fatalf(`Expected %q in output; got: %s`, expected, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
out, exit, _ = dockerCmdWithError("create", fmt.Sprintf("%s:%s", "wrongimage", truncatedImageID))
|
if i := strings.IndexRune(imageID, ':'); i >= 0 {
|
||||||
|
imageID = imageID[i+1:]
|
||||||
|
}
|
||||||
|
out, exit, _ = dockerCmdWithError("create", fmt.Sprintf("%s:%s", "wrongimage", imageID))
|
||||||
if exit == 0 {
|
if exit == 0 {
|
||||||
c.Fatalf("expected non-zero exit code; received %d", exit)
|
c.Fatalf("expected non-zero exit code; received %d", exit)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/integration-cli/checker"
|
"github.com/docker/docker/integration-cli/checker"
|
||||||
"github.com/docker/docker/integration-cli/cli/build"
|
|
||||||
"github.com/docker/docker/internal/testutil"
|
"github.com/docker/docker/internal/testutil"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -140,29 +137,3 @@ func (s *DockerSuite) TestTagInvalidRepoName(c *check.C) {
|
||||||
c.Fatal("tagging with image named \"sha256\" should have failed")
|
c.Fatal("tagging with image named \"sha256\" should have failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure tags cannot create ambiguity with image ids
|
|
||||||
func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) {
|
|
||||||
buildImageSuccessfully(c, "notbusybox:latest", build.WithDockerfile(`FROM busybox
|
|
||||||
MAINTAINER dockerio`))
|
|
||||||
imageID := getIDByName(c, "notbusybox:latest")
|
|
||||||
truncatedImageID := stringid.TruncateID(imageID)
|
|
||||||
truncatedTag := fmt.Sprintf("notbusybox:%s", truncatedImageID)
|
|
||||||
|
|
||||||
id := inspectField(c, truncatedTag, "Id")
|
|
||||||
|
|
||||||
// Ensure inspect by image id returns image for image id
|
|
||||||
c.Assert(id, checker.Equals, imageID)
|
|
||||||
c.Logf("Built image: %s", imageID)
|
|
||||||
|
|
||||||
// test setting tag fails
|
|
||||||
_, _, err := dockerCmdWithError("tag", "busybox:latest", truncatedTag)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatalf("Error tagging with an image id: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
id = inspectField(c, truncatedTag, "Id")
|
|
||||||
|
|
||||||
// Ensure id is imageID and not busybox:latest
|
|
||||||
c.Assert(id, checker.Not(checker.Equals), imageID)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue