Files
podman/libpod/image/utils.go
baude bb6f0f8e26 Image Resolution Stage 1
This is the stage 1 effort for an image library that can be eventually used by buildah and
podman alike.  In eventuality, the main goal of the library (package) is to:

* provide a consistent approach to resolving image names in various forms (from users).
* based on the result of the above, provide image methods that in a singular spot but separate from the runtime.
* reduce the cruft and bloat in the current podman runtime.

The goal of stage 1 is to demonstrate fast, accurate image resolution for both local and remote images resulting in
an image object as part of the return.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #463
Approved by: baude
2018-03-08 19:31:31 +00:00

43 lines
1.2 KiB
Go

package image
import (
"github.com/containers/image/docker/reference"
"github.com/containers/storage"
"github.com/pkg/errors"
)
func getTags(nameInput string) (reference.NamedTagged, bool, error) {
inputRef, err := reference.Parse(nameInput)
if err != nil {
return nil, false, errors.Wrapf(err, "unable to obtain tag from input name")
}
tagged, isTagged := inputRef.(reference.NamedTagged)
return tagged, isTagged, nil
}
// findImageInRepotags takes an imageParts struct and searches images' repotags for
// a match on name:tag
func findImageInRepotags(search imageParts, images []*storage.Image) (*storage.Image, error) {
var results []*storage.Image
for _, image := range images {
for _, name := range image.Names {
d, err := decompose(name)
// if we get an error, ignore and keep going
if err != nil {
continue
}
if d.name == search.name && d.tag == search.tag {
results = append(results, image)
break
}
}
}
if len(results) == 0 {
return &storage.Image{}, errors.Errorf("unable to find a name and tag match for %s in repotags", search)
} else if len(results) > 1 {
return &storage.Image{}, errors.Errorf("found multiple name and tag matches for %s in repotags", search)
}
return results[0], nil
}