diff --git a/go.mod b/go.mod index e6d30a12be26..2dd5140c3552 100644 --- a/go.mod +++ b/go.mod @@ -71,3 +71,5 @@ require ( k8s.io/api v0.22.2 k8s.io/apimachinery v0.22.2 ) + +replace github.com/containers/common => github.com/vrothberg/common v0.0.3-0.20211018125314-1039100afe76 diff --git a/go.sum b/go.sum index 5a66611623d4..2c60b363f158 100644 --- a/go.sum +++ b/go.sum @@ -250,9 +250,6 @@ github.com/containernetworking/plugins v1.0.1 h1:wwCfYbTCj5FC0EJgyzyjTXmqysOiJE9 github.com/containernetworking/plugins v1.0.1/go.mod h1:QHCfGpaTwYTbbH+nZXKVTxNBDZcxSOplJT5ico8/FLE= github.com/containers/buildah v1.23.1 h1:Tpc9DsRuU+0Oofewpxb6OJVNQjCu7yloN/obUqzfDTY= github.com/containers/buildah v1.23.1/go.mod h1:4WnrN0yrA7ab0ppgunixu2WM1rlD2rG8QLJAKbEkZlQ= -github.com/containers/common v0.44.2/go.mod h1:7sdP4vmI5Bm6FPFxb3lvAh1Iktb6tiO1MzjUzhxdoGo= -github.com/containers/common v0.46.1-0.20211008123044-d846f5aaec0e h1:lYazDued7KBcMq5IJzRIbX47SSLRg/yYxvM/P9LaVhE= -github.com/containers/common v0.46.1-0.20211008123044-d846f5aaec0e/go.mod h1:ggZks97KCmjBcHvNTCyLc17SqdjSYoeexW7rnRt9H9Y= github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg= github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I= github.com/containers/image/v5 v5.16.0/go.mod h1:XgTpfAPLRGOd1XYyCU5cISFr777bLmOerCSpt/v7+Q4= @@ -934,6 +931,8 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17 github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= +github.com/vrothberg/common v0.0.3-0.20211018125314-1039100afe76 h1:VrvL2rOhSVEKrYiqiK70hctsW52u4Bmqe0VelCmeMrg= +github.com/vrothberg/common v0.0.3-0.20211018125314-1039100afe76/go.mod h1:Wr/HeT/HRMT82u9IwMurz32UPFRwguWgwvJYKJuHlN8= github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at index d3fde9f9d08a..abe3f0861667 100644 --- a/test/apiv2/10-images.at +++ b/test/apiv2/10-images.at @@ -11,7 +11,7 @@ t GET libpod/images/json 200 \ iid=$(jq -r '.[0].Id' <<<"$output") t GET libpod/images/$iid/exists 204 -t GET libpod/images/$PODMAN_TEST_IMAGE_NAME/exists 204 +t GET libpod/images/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME/exists 204 t GET libpod/images/${iid}abcdef/exists 404 \ .cause="failed to find image ${iid}abcdef" @@ -62,7 +62,7 @@ t POST "images/create?fromImage=quay.io/libpod/alpine&tag=sha256:fa93b01658e3a5a # Display the image history t GET libpod/images/nonesuch/history 404 -for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do +for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME; do t GET libpod/images/$i/history 200 \ .[0].Id=$iid \ .[0].Created~[0-9]\\{10\\} \ @@ -74,9 +74,9 @@ done # Export an image on the local t GET libpod/images/nonesuch/get 404 t GET libpod/images/$iid/get?format=foo 500 -t GET libpod/images/$PODMAN_TEST_IMAGE_NAME/get?compress=bar 400 +t GET libpod/images/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME/get?compress=bar 400 -for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do +for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME; do t GET "libpod/images/$i/get" 200 '[POSIX tar archive]' t GET "libpod/images/$i/get?compress=true" 200 '[POSIX tar archive]' t GET "libpod/images/$i/get?compress=false" 200 '[POSIX tar archive]' diff --git a/test/e2e/pull_test.go b/test/e2e/pull_test.go index c377f158d17c..16f6e9a27def 100644 --- a/test/e2e/pull_test.go +++ b/test/e2e/pull_test.go @@ -48,7 +48,7 @@ var _ = Describe("Podman pull", func() { found, _ := session.ErrorGrepString(expectedError) Expect(found).To(Equal(true)) - session = podmanTest.Podman([]string{"rmi", "busybox", "alpine", "testdigest_v2s2", "quay.io/libpod/cirros"}) + session = podmanTest.Podman([]string{"rmi", "busybox:musl", "alpine", "alpine:latest", "libpod/cirros", "quay.io/libpod/testdigest_v2s2@sha256:755f4d90b3716e2bf57060d249e2cd61c9ac089b1233465c5c2cb2d7ee550fdb"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) }) @@ -64,7 +64,7 @@ var _ = Describe("Podman pull", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "testdigest_v2s2:20200210"}) + session = podmanTest.Podman([]string{"rmi", "libpod/testdigest_v2s2:20200210"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) }) @@ -74,7 +74,7 @@ var _ = Describe("Podman pull", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "testdigest_v2s2"}) + session = podmanTest.Podman([]string{"rmi", "libpod/testdigest_v2s2"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) }) @@ -104,7 +104,13 @@ var _ = Describe("Podman pull", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "testdigest_v2s2"}) + // Pulling by digest yields a tag. Hence, the short name + // won't resolve. + session = podmanTest.Podman([]string{"rmi", "libpod/testdigest_v2s2"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(1)) + + session = podmanTest.Podman([]string{"rmi", "quay.io/libpod/testdigest_v2s2@sha256:755f4d90b3716e2bf57060d249e2cd61c9ac089b1233465c5c2cb2d7ee550fdb"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) }) @@ -257,17 +263,17 @@ var _ = Describe("Podman pull", func() { podmanTest.AddImageToRWStore(cirros) tarfn := filepath.Join(podmanTest.TempDir, "cirros.tar") - session := podmanTest.Podman([]string{"save", "-o", tarfn, "cirros"}) + session := podmanTest.Podman([]string{"save", "-o", tarfn, "libpod/cirros"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "cirros"}) + + session = podmanTest.Podman([]string{"rmi", "libpod/cirros"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:%s", tarfn)}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "cirros"}) + session = podmanTest.Podman([]string{"rmi", "libpod/cirros"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) @@ -320,17 +326,17 @@ var _ = Describe("Podman pull", func() { podmanTest.AddImageToRWStore(cirros) tarfn := filepath.Join(podmanTest.TempDir, "oci-cirrus.tar") - session := podmanTest.Podman([]string{"save", "--format", "oci-archive", "-o", tarfn, "cirros"}) + session := podmanTest.Podman([]string{"save", "--format", "oci-archive", "-o", tarfn, "libpod/cirros"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "cirros"}) + + session = podmanTest.Podman([]string{"rmi", "libpod/cirros"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) session = podmanTest.Podman([]string{"pull", fmt.Sprintf("oci-archive:%s", tarfn)}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "cirros"}) + session = podmanTest.Podman([]string{"rmi", "libpod/cirros"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) }) @@ -343,10 +349,10 @@ var _ = Describe("Podman pull", func() { os.MkdirAll(dirpath, os.ModePerm) imgPath := fmt.Sprintf("dir:%s", dirpath) - session := podmanTest.Podman([]string{"push", "cirros", imgPath}) + session := podmanTest.Podman([]string{"push", "libpod/cirros", imgPath}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "cirros"}) + session = podmanTest.Podman([]string{"rmi", "libpod/cirros"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) session = podmanTest.Podman([]string{"pull", imgPath}) @@ -366,10 +372,10 @@ var _ = Describe("Podman pull", func() { os.MkdirAll(dirpath, os.ModePerm) imgPath := fmt.Sprintf("oci:%s", dirpath) - session := podmanTest.Podman([]string{"push", "cirros", imgPath}) + session := podmanTest.Podman([]string{"push", "libpod/cirros", imgPath}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"rmi", "cirros"}) + session = podmanTest.Podman([]string{"rmi", "libpod/cirros"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) session = podmanTest.Podman([]string{"pull", imgPath}) diff --git a/test/e2e/rmi_test.go b/test/e2e/rmi_test.go index 03a347a6f9b9..730844dc2feb 100644 --- a/test/e2e/rmi_test.go +++ b/test/e2e/rmi_test.go @@ -53,8 +53,12 @@ var _ = Describe("Podman rmi", func() { podmanTest.AddImageToRWStore(cirros) session := podmanTest.Podman([]string{"rmi", "cirros"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(0)) + Expect(session).Should(Exit(1)) + Expect(session.ErrorToString()).To(Equal("Error: cirros: image not known")) + session = podmanTest.Podman([]string{"rmi", "libpod/cirros"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) }) It("podman rmi all images", func() { @@ -99,7 +103,7 @@ var _ = Describe("Podman rmi", func() { Expect(setup).Should(Exit(0)) cirrosId := setup.OutputToString() - session := podmanTest.Podman([]string{"tag", "cirros", "foo:bar", "foo"}) + session := podmanTest.Podman([]string{"tag", "libpod/cirros", "foo:bar", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) diff --git a/test/python/docker/compat/constant.py b/test/python/docker/compat/constant.py index 892293c97ff6..608026e13099 100644 --- a/test/python/docker/compat/constant.py +++ b/test/python/docker/compat/constant.py @@ -1,5 +1,5 @@ ALPINE = "quay.io/libpod/alpine:latest" -ALPINE_SHORTNAME = "alpine" +ALPINE_SHORTNAME = "libpod/alpine" ALPINE_TARBALL = "alpine.tar" BB = "quay.io/libpod/busybox:latest" NGINX = "quay.io/libpod/alpine_nginx:latest" diff --git a/test/python/docker/compat/test_containers.py b/test/python/docker/compat/test_containers.py index 1ad1e7f153cd..d8d23d7a0827 100644 --- a/test/python/docker/compat/test_containers.py +++ b/test/python/docker/compat/test_containers.py @@ -61,12 +61,12 @@ def tearDownClass(cls): def test_create_container(self): # Run a container with detach mode - self.client.containers.create(image="alpine", detach=True) + self.client.containers.create(image=constant.ALPINE_SHORTNAME, detach=True) self.assertEqual(len(self.client.containers.list(all=True)), 2) def test_create_network(self): net = self.client.networks.create("testNetwork", driver="bridge") - ctnr = self.client.containers.create(image="alpine", detach=True) + ctnr = self.client.containers.create(image=constant.ALPINE_SHORTNAME, detach=True) # TODO fix when ready # This test will not work until all connect|disconnect @@ -188,7 +188,7 @@ def test_unpause_container(self): def test_list_container(self): # Add container and validate the count - self.client.containers.create(image="alpine", detach=True) + self.client.containers.create(image=constant.ALPINE_SHORTNAME, detach=True) containers = self.client.containers.list(all=True) self.assertEqual(len(containers), 2) @@ -209,7 +209,7 @@ def test_copy_to_container(self): ctr: Optional[Container] = None try: test_file_content = b"Hello World!" - ctr = self.client.containers.create(image="alpine", detach=True, command="top") + ctr = self.client.containers.create(image=constant.ALPINE_SHORTNAME, detach=True, command="top") ctr.start() buff: IO[bytes] = io.BytesIO() diff --git a/vendor/github.com/containers/common/libimage/runtime.go b/vendor/github.com/containers/common/libimage/runtime.go index 7f25df20053e..a06790e335bf 100644 --- a/vendor/github.com/containers/common/libimage/runtime.go +++ b/vendor/github.com/containers/common/libimage/runtime.go @@ -282,7 +282,7 @@ func (r *Runtime) LookupImage(name string, options *LookupImageOptions) (*Image, } } - return r.lookupImageInDigestsAndRepoTags(originalName, options) + return r.lookupImageInDigests(originalName, options) } // lookupImageInLocalStorage looks up the specified candidate for name in the @@ -365,67 +365,31 @@ func (r *Runtime) lookupImageInLocalStorage(name, candidate string, options *Loo return image, nil } -// lookupImageInDigestsAndRepoTags attempts to match name against any image in -// the local containers storage. If name is digested, it will be compared -// against image digests. Otherwise, it will be looked up in the repo tags. -func (r *Runtime) lookupImageInDigestsAndRepoTags(name string, options *LookupImageOptions) (*Image, string, error) { - // Until now, we've tried very hard to find an image but now it is time - // for limbo. If the image includes a digest that we couldn't detect - // verbatim in the storage, we must have a look at all digests of all - // images. Those may change over time (e.g., via manifest lists). - // Both Podman and Buildah want us to do that dance. - allImages, err := r.ListImages(context.Background(), nil, nil) +// If name is a digested image, look at all images in the local storage and +// check whether a digest matches. +func (r *Runtime) lookupImageInDigests(name string, options *LookupImageOptions) (*Image, string, error) { + named, err := reference.ParseNormalizedNamed(name) if err != nil { return nil, "", err } - - if !shortnames.IsShortName(name) { - named, err := reference.ParseNormalizedNamed(name) - if err != nil { - return nil, "", err - } - digested, hasDigest := named.(reference.Digested) - if !hasDigest { - return nil, "", errors.Wrap(storage.ErrImageUnknown, name) - } - - logrus.Debug("Looking for image with matching recorded digests") - digest := digested.Digest() - for _, image := range allImages { - for _, d := range image.Digests() { - if d == digest { - return image, name, nil - } - } - } - + digested, hasDigest := named.(reference.Digested) + if !hasDigest { return nil, "", errors.Wrap(storage.ErrImageUnknown, name) } - // Podman compat: if we're looking for a short name but couldn't - // resolve it via the registries.conf dance, we need to look at *all* - // images and check if the name we're looking for matches a repo tag. - // Split the name into a repo/tag pair - split := strings.SplitN(name, ":", 2) - repo := split[0] - tag := "" - if len(split) == 2 { - tag = split[1] + logrus.Debug("Looking for image with matching recorded digests") + + allImages, err := r.ListImages(context.Background(), nil, nil) + if err != nil { + return nil, "", err } + + digest := digested.Digest() for _, image := range allImages { - named, err := image.inRepoTags(repo, tag) - if err != nil { - return nil, "", err - } - if named == nil { - continue - } - img, err := r.lookupImageInLocalStorage(name, named.String(), options) - if err != nil { - return nil, "", err - } - if img != nil { - return img, named.String(), err + for _, d := range image.Digests() { + if d == digest { + return image, name, nil + } } } diff --git a/vendor/github.com/containers/common/libimage/search.go b/vendor/github.com/containers/common/libimage/search.go index 7e20e4331075..ece81531a4f8 100644 --- a/vendor/github.com/containers/common/libimage/search.go +++ b/vendor/github.com/containers/common/libimage/search.go @@ -244,7 +244,7 @@ func (r *Runtime) searchImageInRegistry(ctx context.Context, term, registry stri name = index + "/library/" + results[i].Name } params := SearchResult{ - Index: index, + Index: registry, Name: name, Description: description, Official: official, diff --git a/vendor/github.com/containers/common/pkg/config/config.go b/vendor/github.com/containers/common/pkg/config/config.go index d5be77edd332..45230703d8dc 100644 --- a/vendor/github.com/containers/common/pkg/config/config.go +++ b/vendor/github.com/containers/common/pkg/config/config.go @@ -574,7 +574,7 @@ func readConfigFromFile(path string, config *Config) error { } keys := meta.Undecoded() if len(keys) > 0 { - logrus.Warningf("Failed to decode the keys %q from %q.", keys, path) + logrus.Debugf("Failed to decode the keys %q from %q.", keys, path) } return nil diff --git a/vendor/modules.txt b/vendor/modules.txt index 830de276b4f9..d952868fb170 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -95,7 +95,7 @@ github.com/containers/buildah/pkg/rusage github.com/containers/buildah/pkg/sshagent github.com/containers/buildah/pkg/util github.com/containers/buildah/util -# github.com/containers/common v0.46.1-0.20211008123044-d846f5aaec0e +# github.com/containers/common v0.46.1-0.20211008123044-d846f5aaec0e => github.com/vrothberg/common v0.0.3-0.20211018125314-1039100afe76 github.com/containers/common/libimage github.com/containers/common/libimage/manifests github.com/containers/common/pkg/apparmor