summaryrefslogtreecommitdiff
path: root/libpod/image/parts.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/image/parts.go')
-rw-r--r--libpod/image/parts.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/libpod/image/parts.go b/libpod/image/parts.go
index 127f723a8..1509005e5 100644
--- a/libpod/image/parts.go
+++ b/libpod/image/parts.go
@@ -2,6 +2,7 @@ package image
import (
"fmt"
+ "strings"
"github.com/containers/image/docker/reference"
)
@@ -16,6 +17,11 @@ type imageParts struct {
hasRegistry bool
}
+// Registries must contain a ":" or a "." or be localhost
+func isRegistry(name string) bool {
+ return strings.ContainsAny(name, ".:") || name == "localhost"
+}
+
// decompose breaks an input name into an imageParts description
func decompose(input string) (imageParts, error) {
var (
@@ -37,10 +43,16 @@ func decompose(input string) (imageParts, error) {
tag = ntag.Tag()
}
registry := reference.Domain(imgRef.(reference.Named))
- if registry != "" {
+ imageName := reference.Path(imgRef.(reference.Named))
+ // Is this a registry or a repo?
+ if isRegistry(registry) {
hasRegistry = true
+ } else {
+ if registry != "" {
+ imageName = registry + "/" + imageName
+ registry = ""
+ }
}
- imageName := reference.Path(imgRef.(reference.Named))
return imageParts{
registry: registry,
hasRegistry: hasRegistry,
@@ -53,10 +65,15 @@ func decompose(input string) (imageParts, error) {
// 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)
+ spec := fmt.Sprintf("%s:%s", ip.name, ip.tag)
+
+ if ip.registry != "" {
+ spec = fmt.Sprintf("%s/%s", ip.registry, spec)
+ }
+ return spec
}
// assemble concatenates an image's parts with transport into a string
func (ip *imageParts) assembleWithTransport() string {
- return fmt.Sprintf("%s%s/%s:%s", ip.transport, ip.registry, ip.name, ip.tag)
+ return fmt.Sprintf("%s%s", ip.transport, ip.assemble())
}