2014-02-25 20:17:48 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-11-03 14:11:29 +03:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"sort"
|
2014-02-25 20:17:48 +04:00
|
|
|
"strings"
|
2014-06-23 22:19:52 +04:00
|
|
|
"time"
|
2015-03-18 17:11:01 +03:00
|
|
|
|
2015-10-16 17:09:32 +03:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-03-24 14:25:26 +03:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2015-04-18 19:46:47 +03:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 20:17:48 +04:00
|
|
|
)
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-10-26 21:47:21 +03:00
|
|
|
imagesOut, _ := dockerCmd(c, "images")
|
|
|
|
c.Assert(imagesOut, checker.Contains, "busybox")
|
2014-02-25 20:17:48 +04:00
|
|
|
}
|
2014-04-04 04:57:41 +04:00
|
|
|
|
2015-08-08 16:58:48 +03:00
|
|
|
func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-08-08 16:58:48 +03:00
|
|
|
|
2015-11-25 05:43:14 +03:00
|
|
|
name := "imagewithtag"
|
|
|
|
dockerCmd(c, "tag", "busybox", name+":v1")
|
|
|
|
dockerCmd(c, "tag", "busybox", name+":v1v1")
|
|
|
|
dockerCmd(c, "tag", "busybox", name+":v2")
|
2015-08-08 16:58:48 +03:00
|
|
|
|
2015-11-25 05:43:14 +03:00
|
|
|
imagesOut, _ := dockerCmd(c, "images", name+":v1")
|
|
|
|
c.Assert(imagesOut, checker.Contains, name)
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(imagesOut, checker.Contains, "v1")
|
|
|
|
c.Assert(imagesOut, checker.Not(checker.Contains), "v2")
|
2015-11-25 05:43:14 +03:00
|
|
|
c.Assert(imagesOut, checker.Not(checker.Contains), "v1v1")
|
2015-08-08 16:58:48 +03:00
|
|
|
|
2015-11-25 05:43:14 +03:00
|
|
|
imagesOut, _ = dockerCmd(c, "images", name)
|
|
|
|
c.Assert(imagesOut, checker.Contains, name)
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(imagesOut, checker.Contains, "v1")
|
2015-11-25 05:43:14 +03:00
|
|
|
c.Assert(imagesOut, checker.Contains, "v1v1")
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(imagesOut, checker.Contains, "v2")
|
2015-08-08 16:58:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) {
|
2015-10-26 21:47:21 +03:00
|
|
|
imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent")
|
|
|
|
c.Assert(imagesOut, checker.Not(checker.Contains), "busybox")
|
2015-08-08 16:58:48 +03:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-06-23 22:19:52 +04:00
|
|
|
id1, err := buildImage("order:test_a",
|
|
|
|
`FROM scratch
|
|
|
|
MAINTAINER dockerio1`, true)
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-11 10:41:11 +03:00
|
|
|
time.Sleep(1 * time.Second)
|
2014-06-23 22:19:52 +04:00
|
|
|
id2, err := buildImage("order:test_c",
|
|
|
|
`FROM scratch
|
|
|
|
MAINTAINER dockerio2`, true)
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-11 10:41:11 +03:00
|
|
|
time.Sleep(1 * time.Second)
|
2014-06-23 22:19:52 +04:00
|
|
|
id3, err := buildImage("order:test_b",
|
|
|
|
`FROM scratch
|
|
|
|
MAINTAINER dockerio3`, true)
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2014-06-23 22:19:52 +04:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
|
2014-06-23 22:19:52 +04:00
|
|
|
imgs := strings.Split(out, "\n")
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(imgs[0], checker.Equals, id3, check.Commentf("First image must be %s, got %s", id3, imgs[0]))
|
|
|
|
c.Assert(imgs[1], checker.Equals, id2, check.Commentf("First image must be %s, got %s", id2, imgs[1]))
|
|
|
|
c.Assert(imgs[2], checker.Equals, id1, check.Commentf("First image must be %s, got %s", id1, imgs[2]))
|
2014-06-23 22:19:52 +04:00
|
|
|
}
|
2014-11-03 14:11:29 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *check.C) {
|
2015-07-27 21:13:25 +03:00
|
|
|
out, _, err := dockerCmdWithError("images", "-f", "FOO=123")
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, "Invalid filter")
|
2014-11-03 14:11:29 +03:00
|
|
|
}
|
|
|
|
|
2015-11-26 04:27:11 +03:00
|
|
|
func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-01-07 03:04:10 +03:00
|
|
|
imageName1 := "images_filter_test1"
|
|
|
|
imageName2 := "images_filter_test2"
|
|
|
|
imageName3 := "images_filter_test3"
|
|
|
|
image1ID, err := buildImage(imageName1,
|
|
|
|
`FROM scratch
|
|
|
|
LABEL match me`, true)
|
2015-08-22 15:06:48 +03:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-01-07 03:04:10 +03:00
|
|
|
|
|
|
|
image2ID, err := buildImage(imageName2,
|
|
|
|
`FROM scratch
|
|
|
|
LABEL match="me too"`, true)
|
2015-08-22 15:06:48 +03:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-01-07 03:04:10 +03:00
|
|
|
|
|
|
|
image3ID, err := buildImage(imageName3,
|
|
|
|
`FROM scratch
|
|
|
|
LABEL nomatch me`, true)
|
2015-08-22 15:06:48 +03:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-01-07 03:04:10 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
|
2015-01-07 03:04:10 +03:00
|
|
|
out = strings.TrimSpace(out)
|
2015-11-19 01:20:54 +03:00
|
|
|
c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image1ID))
|
|
|
|
c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image2ID))
|
|
|
|
c.Assert(out, check.Not(check.Matches), fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image3ID))
|
2015-01-07 03:04:10 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too")
|
2015-01-07 03:04:10 +03:00
|
|
|
out = strings.TrimSpace(out)
|
2015-08-22 15:06:48 +03:00
|
|
|
c.Assert(out, check.Equals, image2ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regression : #15659
|
|
|
|
func (s *DockerSuite) TestImagesFilterLabelWithCommit(c *check.C) {
|
|
|
|
// Create a container
|
|
|
|
dockerCmd(c, "run", "--name", "bar", "busybox", "/bin/sh")
|
|
|
|
// Commit with labels "using changes"
|
|
|
|
out, _ := dockerCmd(c, "commit", "-c", "LABEL foo.version=1.0.0-1", "-c", "LABEL foo.name=bar", "-c", "LABEL foo.author=starlord", "bar", "bar:1.0.0-1")
|
|
|
|
imageID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=foo.version=1.0.0-1")
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
c.Assert(out, check.Equals, imageID)
|
2015-01-07 03:04:10 +03:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-11-03 14:11:29 +03:00
|
|
|
imageName := "images_filter_test"
|
|
|
|
buildImage(imageName,
|
|
|
|
`FROM scratch
|
|
|
|
RUN touch /test/foo
|
|
|
|
RUN touch /test/bar
|
|
|
|
RUN touch /test/baz`, true)
|
|
|
|
|
|
|
|
filters := []string{
|
|
|
|
"dangling=true",
|
|
|
|
"Dangling=true",
|
|
|
|
" dangling=true",
|
|
|
|
"dangling=true ",
|
|
|
|
"dangling = true",
|
|
|
|
}
|
|
|
|
|
|
|
|
imageListings := make([][]string, 5, 5)
|
|
|
|
for idx, filter := range filters {
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "images", "-q", "-f", filter)
|
2014-11-03 14:11:29 +03:00
|
|
|
listing := strings.Split(out, "\n")
|
|
|
|
sort.Strings(listing)
|
|
|
|
imageListings[idx] = listing
|
|
|
|
}
|
|
|
|
|
|
|
|
for idx, listing := range imageListings {
|
|
|
|
if idx < 4 && !reflect.DeepEqual(listing, imageListings[idx+1]) {
|
|
|
|
for idx, errListing := range imageListings {
|
|
|
|
fmt.Printf("out %d", idx)
|
|
|
|
for _, image := range errListing {
|
|
|
|
fmt.Print(image)
|
|
|
|
}
|
|
|
|
fmt.Print("")
|
|
|
|
}
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("All output must be the same")
|
2014-11-03 14:11:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 17:11:01 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-03-18 17:11:01 +03:00
|
|
|
// create container 1
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
2015-07-22 15:59:24 +03:00
|
|
|
containerID1 := strings.TrimSpace(out)
|
2015-03-18 17:11:01 +03:00
|
|
|
|
|
|
|
// tag as foobox
|
2015-07-22 15:59:24 +03:00
|
|
|
out, _ = dockerCmd(c, "commit", containerID1, "foobox")
|
|
|
|
imageID := stringid.TruncateID(strings.TrimSpace(out))
|
2015-03-18 17:11:01 +03:00
|
|
|
|
|
|
|
// overwrite the tag, making the previous image dangling
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "tag", "-f", "busybox", "foobox")
|
2015-03-18 17:11:01 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
|
2015-12-13 19:00:39 +03:00
|
|
|
// Expect one dangling image
|
2015-10-26 21:47:21 +03:00
|
|
|
c.Assert(strings.Count(out, imageID), checker.Equals, 1)
|
2015-03-18 17:11:01 +03:00
|
|
|
}
|
2015-10-16 17:09:32 +03:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) {
|
|
|
|
out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, "Invalid filter")
|
|
|
|
}
|
2015-10-09 20:13:45 +03:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
dockerfile := `
|
|
|
|
FROM scratch
|
|
|
|
MAINTAINER docker
|
|
|
|
ENV foo bar`
|
|
|
|
|
|
|
|
head, out, err := buildImageWithOut("scratch-image", dockerfile, false)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2015-10-11 10:32:52 +03:00
|
|
|
// this is just the output of docker build
|
|
|
|
// we're interested in getting the image id of the MAINTAINER instruction
|
|
|
|
// and that's located at output, line 5, from 7 to end
|
2015-10-09 20:13:45 +03:00
|
|
|
split := strings.Split(out, "\n")
|
|
|
|
intermediate := strings.TrimSpace(split[5][7:])
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "images")
|
2015-10-26 21:47:21 +03:00
|
|
|
// images shouldn't show non-heads images
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), intermediate)
|
|
|
|
// images should contain final built images
|
2015-11-19 01:20:54 +03:00
|
|
|
c.Assert(out, checker.Contains, stringid.TruncateID(head))
|
2015-10-09 20:13:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
dockerfile := `
|
|
|
|
FROM scratch
|
|
|
|
MAINTAINER docker`
|
|
|
|
|
|
|
|
id, _, err := buildImageWithOut("scratch-image", dockerfile, false)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "images")
|
2015-10-26 21:47:21 +03:00
|
|
|
// images should contain images built from scratch
|
2015-11-19 01:20:54 +03:00
|
|
|
c.Assert(out, checker.Contains, stringid.TruncateID(id))
|
2015-10-09 20:13:45 +03:00
|
|
|
}
|
2015-11-25 05:43:14 +03:00
|
|
|
|
|
|
|
// #18181
|
|
|
|
func (s *DockerSuite) TestImagesFilterNameWithPort(c *check.C) {
|
|
|
|
tag := "a.b.c.d:5000/hello"
|
|
|
|
dockerCmd(c, "tag", "busybox", tag)
|
|
|
|
out, _ := dockerCmd(c, "images", tag)
|
|
|
|
c.Assert(out, checker.Contains, tag)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "images", tag+":latest")
|
|
|
|
c.Assert(out, checker.Contains, tag)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "images", tag+":no-such-tag")
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), tag)
|
|
|
|
}
|