From 4496612c709ae71cf72b8e9c804eac79112f8e19 Mon Sep 17 00:00:00 2001 From: Christoph Ostarek Date: Fri, 15 Mar 2024 18:33:50 +0100 Subject: [PATCH] util: allow pulling from local registry before a command like linuxkit cache pull 127.0.0.1:5000/pkgalpine would result in trying to pull the following image: docker.io/127.0.0.1:5000/pkgalpine and this is wrong Signed-off-by: Christoph Ostarek --- src/cmd/linuxkit/util/reference.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cmd/linuxkit/util/reference.go b/src/cmd/linuxkit/util/reference.go index b5aaedc315..862ce16636 100644 --- a/src/cmd/linuxkit/util/reference.go +++ b/src/cmd/linuxkit/util/reference.go @@ -1,6 +1,8 @@ package util -import "strings" +import ( + "strings" +) type refOpts struct { withTag bool @@ -21,16 +23,13 @@ func ReferenceExpand(ref string, options ...ReferenceOption) string { for _, opt := range options { opt(&opts) } - var ret string + ret := ref + parts := strings.Split(ref, "/") - switch len(parts) { - case 1: + if len(parts) == 1 { ret = "docker.io/library/" + ref - case 2: - ret = "docker.io/" + ref - default: - ret = ref } + if opts.withTag && !strings.Contains(ret, ":") { ret += ":latest" }