mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
Merge pull request #4030 from deitch/canonicalize-pull
use canonical ref when looking in cache
This commit is contained in:
commit
e6b0ae05eb
7
src/cmd/linuxkit/cache/write.go
vendored
7
src/cmd/linuxkit/cache/write.go
vendored
@ -20,6 +20,7 @@ import (
|
||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||
"github.com/google/go-containerregistry/pkg/v1/types"
|
||||
lktspec "github.com/linuxkit/linuxkit/src/cmd/linuxkit/spec"
|
||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/util"
|
||||
lktutil "github.com/linuxkit/linuxkit/src/cmd/linuxkit/util"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -41,6 +42,12 @@ const (
|
||||
// Note that ImagePull does try ValidateImage first, so if the image is already in the cache, it will not
|
||||
// do any network activity at all.
|
||||
func (p *Provider) ImagePull(ref *reference.Spec, trustedRef, architecture string, alwaysPull bool) (lktspec.ImageSource, error) {
|
||||
imageName := util.ReferenceExpand(ref.String())
|
||||
canonicalRef, err := reference.Parse(imageName)
|
||||
if err != nil {
|
||||
return ImageSource{}, fmt.Errorf("invalid image name %s: %v", imageName, err)
|
||||
}
|
||||
ref = &canonicalRef
|
||||
image := ref.String()
|
||||
pullImageName := image
|
||||
remoteOptions := []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)}
|
||||
|
@ -17,7 +17,9 @@ func ReferenceWithTag() ReferenceOption {
|
||||
}
|
||||
}
|
||||
|
||||
// ReferenceExpand expands "redis" to "docker.io/library/redis" so all images have a full domain
|
||||
// ReferenceExpand expands "redis" to "docker.io/library/redis" so all images have a full domain,
|
||||
// and similarly foo/bar to docker.io/foo/bar.
|
||||
// If the image does not have a tag, ":latest" is added.
|
||||
func ReferenceExpand(ref string, options ...ReferenceOption) string {
|
||||
var opts refOpts
|
||||
for _, opt := range options {
|
||||
@ -26,8 +28,11 @@ func ReferenceExpand(ref string, options ...ReferenceOption) string {
|
||||
ret := ref
|
||||
|
||||
parts := strings.Split(ref, "/")
|
||||
if len(parts) == 1 {
|
||||
switch len(parts) {
|
||||
case 1:
|
||||
ret = "docker.io/library/" + ref
|
||||
case 2:
|
||||
ret = "docker.io/" + ref
|
||||
}
|
||||
|
||||
if opts.withTag && !strings.Contains(ret, ":") {
|
||||
|
Loading…
Reference in New Issue
Block a user