Browse code

Remove support for referencing images by 'repository:shortid'

The `repository:shortid` syntax for referencing images is very little used,
collides with with tag references can be confused with digest references.

The `repository:shortid` notation was deprecated in Docker 1.13 through
5fc71599a0b77189f0fedf629ed43c7f7067956c, and scheduled for removal
in Docker 17.12.

This patch removes the support for this notation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2017/12/14 07:00:01
Showing 3 changed files
... ...
@@ -6,7 +6,6 @@ import (
6 6
 
7 7
 	"github.com/docker/distribution/reference"
8 8
 	"github.com/docker/docker/image"
9
-	"github.com/docker/docker/pkg/stringid"
10 9
 )
11 10
 
12 11
 // 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)
59 59
 		return id, imageOS, nil
60 60
 	}
61 61
 
62
-	// deprecated: repo:shortid https://github.com/docker/docker/pull/799
63
-	if tagged, ok := namedRef.(reference.Tagged); ok {
64
-		if tag := tagged.Tag(); stringid.IsShortID(stringid.TruncateID(tag)) {
65
-			for platform := range daemon.stores {
66
-				if id, err := daemon.stores[platform].imageStore.Search(tag); err == nil {
67
-					for _, storeRef := range daemon.referenceStore.References(id.Digest()) {
68
-						if storeRef.Name() == namedRef.Name() {
69
-							return id, platform, nil
70
-						}
71
-					}
72
-				}
73
-			}
74
-		}
75
-	}
76
-
77 62
 	// Search based on ID
78 63
 	for os := range daemon.stores {
79 64
 		if id, err := daemon.stores[os].imageStore.Search(refOrID); err == nil {
... ...
@@ -268,7 +268,6 @@ func (s *DockerSuite) TestCreateByImageID(c *check.C) {
268 268
 
269 269
 	dockerCmd(c, "create", imageID)
270 270
 	dockerCmd(c, "create", truncatedImageID)
271
-	dockerCmd(c, "create", fmt.Sprintf("%s:%s", imageName, truncatedImageID))
272 271
 
273 272
 	// Ensure this fails
274 273
 	out, exit, _ := dockerCmdWithError("create", fmt.Sprintf("%s:%s", imageName, imageID))
... ...
@@ -280,7 +279,10 @@ func (s *DockerSuite) TestCreateByImageID(c *check.C) {
280 280
 		c.Fatalf(`Expected %q in output; got: %s`, expected, out)
281 281
 	}
282 282
 
283
-	out, exit, _ = dockerCmdWithError("create", fmt.Sprintf("%s:%s", "wrongimage", truncatedImageID))
283
+	if i := strings.IndexRune(imageID, ':'); i >= 0 {
284
+		imageID = imageID[i+1:]
285
+	}
286
+	out, exit, _ = dockerCmdWithError("create", fmt.Sprintf("%s:%s", "wrongimage", imageID))
284 287
 	if exit == 0 {
285 288
 		c.Fatalf("expected non-zero exit code; received %d", exit)
286 289
 	}
... ...
@@ -1,13 +1,10 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"strings"
6 5
 
7 6
 	"github.com/docker/docker/integration-cli/checker"
8
-	"github.com/docker/docker/integration-cli/cli/build"
9 7
 	"github.com/docker/docker/internal/testutil"
10
-	"github.com/docker/docker/pkg/stringid"
11 8
 	"github.com/go-check/check"
12 9
 )
13 10
 
... ...
@@ -140,29 +137,3 @@ func (s *DockerSuite) TestTagInvalidRepoName(c *check.C) {
140 140
 		c.Fatal("tagging with image named \"sha256\" should have failed")
141 141
 	}
142 142
 }
143
-
144
-// ensure tags cannot create ambiguity with image ids
145
-func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) {
146
-	buildImageSuccessfully(c, "notbusybox:latest", build.WithDockerfile(`FROM busybox
147
-		MAINTAINER dockerio`))
148
-	imageID := getIDByName(c, "notbusybox:latest")
149
-	truncatedImageID := stringid.TruncateID(imageID)
150
-	truncatedTag := fmt.Sprintf("notbusybox:%s", truncatedImageID)
151
-
152
-	id := inspectField(c, truncatedTag, "Id")
153
-
154
-	// Ensure inspect by image id returns image for image id
155
-	c.Assert(id, checker.Equals, imageID)
156
-	c.Logf("Built image: %s", imageID)
157
-
158
-	// test setting tag fails
159
-	_, _, err := dockerCmdWithError("tag", "busybox:latest", truncatedTag)
160
-	if err != nil {
161
-		c.Fatalf("Error tagging with an image id: %s", err)
162
-	}
163
-
164
-	id = inspectField(c, truncatedTag, "Id")
165
-
166
-	// Ensure id is imageID and not busybox:latest
167
-	c.Assert(id, checker.Not(checker.Equals), imageID)
168
-}