summaryrefslogtreecommitdiff
path: root/libpod/image/utils.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-02-27 12:25:25 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2018-03-08 19:31:31 +0000
commitbb6f0f8e266a77852c2690d1ee956ecbf23d28ff (patch)
treefbb6a14c5c22766b3912f5dd1272700fbc4cef71 /libpod/image/utils.go
parent54f32f2cc024090c3f284f7b0b6832f2b19a6660 (diff)
downloadpodman-bb6f0f8e266a77852c2690d1ee956ecbf23d28ff.tar.gz
podman-bb6f0f8e266a77852c2690d1ee956ecbf23d28ff.tar.bz2
podman-bb6f0f8e266a77852c2690d1ee956ecbf23d28ff.zip
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
Diffstat (limited to 'libpod/image/utils.go')
-rw-r--r--libpod/image/utils.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/libpod/image/utils.go b/libpod/image/utils.go
new file mode 100644
index 000000000..f312c8e4d
--- /dev/null
+++ b/libpod/image/utils.go
@@ -0,0 +1,42 @@
+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
+}