2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-11-18 22:20:54 +00:00
|
|
|
"fmt"
|
2014-10-20 03:10:31 +00:00
|
|
|
"strings"
|
2015-03-24 11:25:26 +00:00
|
|
|
|
2015-10-08 19:42:41 +00:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-11-18 22:20:54 +00:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2015-03-24 11:25:26 +00:00
|
|
|
"github.com/docker/docker/pkg/stringutils"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// tagging a named image in a new unprefixed repo should work
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagUnprefixedRepoByName(c *check.C) {
|
2016-01-26 18:41:31 +00:00
|
|
|
// Don't attempt to pull on Windows as not in hub. It's installed
|
|
|
|
// as an image through .ensure-frozen-images-windows
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 06:44:22 +00:00
|
|
|
dockerCmd(c, "tag", "busybox:latest", "testfoobarbaz")
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// tagging an image by ID in a new unprefixed repo should work
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagUnprefixedRepoByID(c *check.C) {
|
2016-01-28 14:19:25 +00:00
|
|
|
imageID := inspectField(c, "busybox", "Id")
|
2015-07-20 06:44:22 +00:00
|
|
|
dockerCmd(c, "tag", imageID, "testfoobarbaz")
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 14:32:44 +00:00
|
|
|
// ensure we don't allow the use of invalid repository names; these tag operations should fail
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagInvalidUnprefixedRepo(c *check.C) {
|
2016-02-08 19:07:57 +00:00
|
|
|
invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd", "FOO/bar"}
|
2014-02-25 16:17:48 +00:00
|
|
|
|
|
|
|
for _, repo := range invalidRepos {
|
2015-10-08 19:42:41 +00:00
|
|
|
out, _, err := dockerCmdWithError("tag", "busybox", repo)
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repo, out))
|
2014-09-11 14:32:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we don't allow the use of invalid tags; these tag operations should fail
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) {
|
2015-03-26 01:40:23 +00:00
|
|
|
longTag := stringutils.GenerateRandomAlphaOnlyString(121)
|
2014-09-11 14:32:44 +00:00
|
|
|
|
2015-03-26 01:40:23 +00:00
|
|
|
invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}
|
2014-09-11 14:32:44 +00:00
|
|
|
|
|
|
|
for _, repotag := range invalidTags {
|
2015-10-08 19:42:41 +00:00
|
|
|
out, _, err := dockerCmdWithError("tag", "busybox", repotag)
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repotag, out))
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we allow the use of valid tags
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagValidPrefixedRepo(c *check.C) {
|
2016-01-26 18:41:31 +00:00
|
|
|
// Don't attempt to pull on Windows as not in hub. It's installed
|
|
|
|
// as an image through .ensure-frozen-images-windows
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 19:07:57 +00:00
|
|
|
validRepos := []string{"fooo/bar", "fooaa/test", "foooo:t", "HOSTNAME.DOMAIN.COM:443/foo/bar"}
|
2014-02-25 16:17:48 +00:00
|
|
|
|
|
|
|
for _, repo := range validRepos {
|
2015-07-27 18:13:25 +00:00
|
|
|
_, _, err := dockerCmdWithError("tag", "busybox:latest", repo)
|
2014-02-25 16:17:48 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("tag busybox %v should have worked: %s", repo, err)
|
2014-02-25 16:17:48 +00:00
|
|
|
continue
|
|
|
|
}
|
2014-04-04 00:22:32 +00:00
|
|
|
deleteImages(repo)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-20 03:10:31 +00:00
|
|
|
|
2015-12-01 22:02:02 +00:00
|
|
|
// tag an image with an existed tag name without -f option should work
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagExistedNameWithoutForce(c *check.C) {
|
2016-01-26 18:41:31 +00:00
|
|
|
// Don't attempt to pull on Windows as not in hub. It's installed
|
|
|
|
// as an image through .ensure-frozen-images-windows
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
|
|
}
|
2014-10-20 03:10:31 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 06:44:22 +00:00
|
|
|
dockerCmd(c, "tag", "busybox:latest", "busybox:test")
|
2014-10-20 03:10:31 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 14:22:33 +00:00
|
|
|
func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) {
|
2016-01-26 18:41:31 +00:00
|
|
|
// Don't attempt to pull on Windows as not in hub. It's installed
|
|
|
|
// as an image through .ensure-frozen-images-windows
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
|
|
}
|
2015-05-13 06:23:13 +00:00
|
|
|
}
|
|
|
|
// test repository name begin with '-'
|
2015-07-27 18:13:25 +00:00
|
|
|
out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test")
|
2015-10-08 19:42:41 +00:00
|
|
|
c.Assert(err, checker.NotNil, check.Commentf(out))
|
2015-12-10 07:31:38 +00:00
|
|
|
c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed"))
|
2015-10-08 19:42:41 +00:00
|
|
|
|
2015-05-13 06:23:13 +00:00
|
|
|
// test namespace name begin with '-'
|
2015-07-27 18:13:25 +00:00
|
|
|
out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test")
|
2015-10-08 19:42:41 +00:00
|
|
|
c.Assert(err, checker.NotNil, check.Commentf(out))
|
2015-12-10 07:31:38 +00:00
|
|
|
c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed"))
|
2015-10-08 19:42:41 +00:00
|
|
|
|
2015-08-07 22:24:18 +00:00
|
|
|
// test index name begin with '-'
|
2015-07-27 18:13:25 +00:00
|
|
|
out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test")
|
2015-10-08 19:42:41 +00:00
|
|
|
c.Assert(err, checker.NotNil, check.Commentf(out))
|
2015-12-10 07:31:38 +00:00
|
|
|
c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed"))
|
2015-05-13 06:23:13 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 01:54:52 +00:00
|
|
|
// ensure tagging using official names works
|
|
|
|
// ensure all tags result in the same name
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagOfficialNames(c *check.C) {
|
2014-10-07 01:54:52 +00:00
|
|
|
names := []string{
|
|
|
|
"docker.io/busybox",
|
|
|
|
"index.docker.io/busybox",
|
|
|
|
"library/busybox",
|
|
|
|
"docker.io/library/busybox",
|
|
|
|
"index.docker.io/library/busybox",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
2015-12-01 22:02:02 +00:00
|
|
|
out, exitCode, err := dockerCmdWithError("tag", "busybox:latest", name+":latest")
|
2014-10-07 01:54:52 +00:00
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("tag busybox %v should have worked: %s, %s", name, err, out)
|
2014-10-07 01:54:52 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we don't have multiple tag names.
|
2015-07-27 18:13:25 +00:00
|
|
|
out, _, err = dockerCmdWithError("images")
|
2014-10-07 01:54:52 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("listing images failed with errors: %v, %s", err, out)
|
2014-10-07 01:54:52 +00:00
|
|
|
} else if strings.Contains(out, name) {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("images should not have listed '%s'", name)
|
2014-10-07 01:54:52 +00:00
|
|
|
deleteImages(name + ":latest")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
2015-12-01 22:02:02 +00:00
|
|
|
_, exitCode, err := dockerCmdWithError("tag", name+":latest", "fooo/bar:latest")
|
2014-10-07 01:54:52 +00:00
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("tag %v fooo/bar should have worked: %s", name, err)
|
2014-10-07 01:54:52 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
deleteImages("fooo/bar:latest")
|
|
|
|
}
|
|
|
|
}
|
2015-09-14 17:20:11 +00:00
|
|
|
|
|
|
|
// ensure tags can not match digests
|
|
|
|
func (s *DockerSuite) TestTagMatchesDigest(c *check.C) {
|
2016-01-26 18:41:31 +00:00
|
|
|
// Don't attempt to pull on Windows as not in hub. It's installed
|
|
|
|
// as an image through .ensure-frozen-images-windows
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
|
|
}
|
2015-09-14 17:20:11 +00:00
|
|
|
}
|
|
|
|
digest := "busybox@sha256:abcdef76720241213f5303bda7704ec4c2ef75613173910a56fb1b6e20251507"
|
|
|
|
// test setting tag fails
|
2015-12-01 22:02:02 +00:00
|
|
|
_, _, err := dockerCmdWithError("tag", "busybox:latest", digest)
|
2015-09-14 17:20:11 +00:00
|
|
|
if err == nil {
|
|
|
|
c.Fatal("digest tag a name should have failed")
|
|
|
|
}
|
|
|
|
// check that no new image matches the digest
|
|
|
|
_, _, err = dockerCmdWithError("inspect", digest)
|
|
|
|
if err == nil {
|
|
|
|
c.Fatal("inspecting by digest should have failed")
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 22:20:54 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestTagInvalidRepoName(c *check.C) {
|
2016-01-26 18:41:31 +00:00
|
|
|
// Don't attempt to pull on Windows as not in hub. It's installed
|
|
|
|
// as an image through .ensure-frozen-images-windows
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
|
|
}
|
2015-11-18 22:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test setting tag fails
|
2015-12-01 22:02:02 +00:00
|
|
|
_, _, err := dockerCmdWithError("tag", "busybox:latest", "sha256:sometag")
|
2015-11-18 22:20:54 +00:00
|
|
|
if err == nil {
|
|
|
|
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) {
|
2016-01-26 18:41:31 +00:00
|
|
|
//testRequires(c, DaemonIsLinux)
|
|
|
|
// Don't attempt to pull on Windows as not in hub. It's installed
|
|
|
|
// as an image through .ensure-frozen-images-windows
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
|
|
}
|
2015-11-18 22:20:54 +00:00
|
|
|
}
|
|
|
|
imageID, err := buildImage("notbusybox:latest",
|
|
|
|
`FROM busybox
|
|
|
|
MAINTAINER dockerio`,
|
|
|
|
true)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
truncatedImageID := stringid.TruncateID(imageID)
|
|
|
|
truncatedTag := fmt.Sprintf("notbusybox:%s", truncatedImageID)
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
id := inspectField(c, truncatedTag, "Id")
|
2015-11-18 22:20:54 +00:00
|
|
|
|
|
|
|
// 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
|
2015-12-01 22:02:02 +00:00
|
|
|
_, _, err = dockerCmdWithError("tag", "busybox:latest", truncatedTag)
|
2015-11-18 22:20:54 +00:00
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Error tagging with an image id: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
id = inspectField(c, truncatedTag, "Id")
|
2015-11-18 22:20:54 +00:00
|
|
|
|
|
|
|
// Ensure id is imageID and not busybox:latest
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), imageID)
|
|
|
|
}
|