mirror of
https://github.com/containers/podman.git
synced 2025-06-27 21:50:18 +08:00
run complex image names with short names
In cases where the image name is more complex like: quay/baude/alpine_nginx:latest and is not from the docker registry, we need to be able to run the image by its shortname such as baude/alpine_nginx. The same goes when the image is not from a registry but instead has the localhost repository. This resolves buildah issue #1034 Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -239,6 +239,7 @@ func (i *Image) getLocalImage() (*storage.Image, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// the inputname isn't tagged, so we assume latest and try again
|
// the inputname isn't tagged, so we assume latest and try again
|
||||||
if !decomposedImage.isTagged {
|
if !decomposedImage.isTagged {
|
||||||
taggedName = fmt.Sprintf("%s:latest", i.InputName)
|
taggedName = fmt.Sprintf("%s:latest", i.InputName)
|
||||||
@ -247,15 +248,14 @@ func (i *Image) getLocalImage() (*storage.Image, error) {
|
|||||||
return img.image, nil
|
return img.image, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasReg, err := i.hasRegistry()
|
|
||||||
if err != nil {
|
// The image has a registry name in it and we made sure we looked for it locally
|
||||||
return nil, errors.Wrapf(err, imageError)
|
// with a tag. It cannot be local.
|
||||||
|
if decomposedImage.hasRegistry {
|
||||||
|
return nil, errors.Errorf("%s", imageError)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the input name has a registry in it, the image isnt here
|
|
||||||
if hasReg {
|
|
||||||
return nil, errors.Errorf("%s", imageError)
|
|
||||||
}
|
|
||||||
// if the image is saved with the repository localhost, searching with localhost prepended is necessary
|
// if the image is saved with the repository localhost, searching with localhost prepended is necessary
|
||||||
// We don't need to strip the sha because we have already determined it is not an ID
|
// We don't need to strip the sha because we have already determined it is not an ID
|
||||||
img, err = i.imageruntime.getImage(fmt.Sprintf("%s/%s", DefaultLocalRegistry, i.InputName))
|
img, err = i.imageruntime.getImage(fmt.Sprintf("%s/%s", DefaultLocalRegistry, i.InputName))
|
||||||
@ -274,21 +274,8 @@ func (i *Image) getLocalImage() (*storage.Image, error) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return repoImage, nil
|
return repoImage, nil
|
||||||
}
|
}
|
||||||
return nil, errors.Wrapf(err, imageError)
|
|
||||||
}
|
|
||||||
|
|
||||||
// hasRegistry returns a bool/err response if the image has a registry in its
|
return nil, errors.Wrapf(err, imageError)
|
||||||
// name
|
|
||||||
func (i *Image) hasRegistry() (bool, error) {
|
|
||||||
imgRef, err := reference.Parse(i.InputName)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
registry := reference.Domain(imgRef.(reference.Named))
|
|
||||||
if registry != "" {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID returns the image ID as a string
|
// ID returns the image ID as a string
|
||||||
|
@ -42,6 +42,28 @@ var _ = Describe("Podman run", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman run a container based on a complex local image name", func() {
|
||||||
|
podmanTest.RestoreArtifact(nginx)
|
||||||
|
session := podmanTest.Podman([]string{"run", "baude/alpine_nginx:latest", "ls"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ErrorToString()).ToNot(ContainSubstring("Trying to pull"))
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("podman run a container based on on a short name with localhost", func() {
|
||||||
|
podmanTest.RestoreArtifact(nginx)
|
||||||
|
tag := podmanTest.Podman([]string{"tag", nginx, "localhost/baude/alpine_nginx:latest"})
|
||||||
|
tag.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
|
rmi := podmanTest.Podman([]string{"rmi", nginx})
|
||||||
|
rmi.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
|
session := podmanTest.Podman([]string{"run", "baude/alpine_nginx:latest", "ls"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ErrorToString()).ToNot(ContainSubstring("Trying to pull"))
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman run a container based on local image with short options", func() {
|
It("podman run a container based on local image with short options", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "-dt", ALPINE, "ls"})
|
session := podmanTest.Podman([]string{"run", "-dt", ALPINE, "ls"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user