summaryrefslogtreecommitdiff
path: root/libpod/image/utils.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-02-19 10:08:43 -0600
committerbaude <bbaude@redhat.com>2019-02-20 12:58:05 -0600
commit711ac9305185e645f2970d09ff76c2761132202a (patch)
treee8c7c83be19cc075446b20ea49a88c529dda69f1 /libpod/image/utils.go
parent4de0bf9c74624de8a2cab1e5cbebc0beaa67339a (diff)
downloadpodman-711ac9305185e645f2970d09ff76c2761132202a.tar.gz
podman-711ac9305185e645f2970d09ff76c2761132202a.tar.bz2
podman-711ac9305185e645f2970d09ff76c2761132202a.zip
podman-remote save [image]
Add the ability to save an image from the remote-host to the remote-client. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/image/utils.go')
-rw-r--r--libpod/image/utils.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/libpod/image/utils.go b/libpod/image/utils.go
index 3585428ad..544796a4b 100644
--- a/libpod/image/utils.go
+++ b/libpod/image/utils.go
@@ -1,6 +1,7 @@
package image
import (
+ "fmt"
"io"
"net/url"
"regexp"
@@ -148,3 +149,28 @@ func IsValidImageURI(imguri string) (bool, error) {
}
return true, nil
}
+
+// imageNameForSaveDestination returns a Docker-like reference appropriate for saving img,
+// which the user referred to as imgUserInput; or an empty string, if there is no appropriate
+// reference.
+func imageNameForSaveDestination(img *Image, imgUserInput string) string {
+ if strings.Contains(img.ID(), imgUserInput) {
+ return ""
+ }
+
+ prepend := ""
+ localRegistryPrefix := fmt.Sprintf("%s/", DefaultLocalRegistry)
+ if !strings.HasPrefix(imgUserInput, localRegistryPrefix) {
+ // we need to check if localhost was added to the image name in NewFromLocal
+ for _, name := range img.Names() {
+ // If the user is saving an image in the localhost registry, getLocalImage need
+ // a name that matches the format localhost/<tag1>:<tag2> or localhost/<tag>:latest to correctly
+ // set up the manifest and save.
+ if strings.HasPrefix(name, localRegistryPrefix) && (strings.HasSuffix(name, imgUserInput) || strings.HasSuffix(name, fmt.Sprintf("%s:latest", imgUserInput))) {
+ prepend = localRegistryPrefix
+ break
+ }
+ }
+ }
+ return fmt.Sprintf("%s%s", prepend, imgUserInput)
+}