summaryrefslogtreecommitdiff
path: root/libpod/image/parts.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/parts.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/parts.go')
-rw-r--r--libpod/image/parts.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/libpod/image/parts.go b/libpod/image/parts.go
new file mode 100644
index 000000000..e4ae489f9
--- /dev/null
+++ b/libpod/image/parts.go
@@ -0,0 +1,56 @@
+package image
+
+import (
+ "fmt"
+
+ "github.com/containers/image/docker/reference"
+)
+
+// imageParts describes the parts of an image's name
+type imageParts struct {
+ transport string
+ registry string
+ name string
+ tag string
+ isTagged bool
+ hasRegistry bool
+}
+
+// decompose breaks an input name into an imageParts description
+func decompose(input string) (imageParts, error) {
+ var (
+ parts imageParts
+ hasRegistry bool
+ tag string
+ )
+ imgRef, err := reference.Parse(input)
+ if err != nil {
+ return parts, err
+ }
+ ntag, isTagged, err := getTags(input)
+ if err != nil {
+ return parts, err
+ }
+ if !isTagged {
+ tag = "latest"
+ } else {
+ tag = ntag.Tag()
+ }
+ registry := reference.Domain(imgRef.(reference.Named))
+ if registry != "" {
+ hasRegistry = true
+ }
+ imageName := reference.Path(imgRef.(reference.Named))
+ return imageParts{
+ registry: registry,
+ hasRegistry: hasRegistry,
+ name: imageName,
+ tag: tag,
+ isTagged: isTagged,
+ }, nil
+}
+
+// assemble concatenates an image's parts into a string
+func (ip *imageParts) assemble() string {
+ return fmt.Sprintf("%s/%s:%s", ip.registry, ip.name, ip.tag)
+}