Use go-containerregistry library instead of docker CLI

pull/8417/head
Priya Wadhwa 2020-06-08 14:01:06 -07:00
parent 0033381049
commit 173666d203
2 changed files with 15 additions and 7 deletions

View File

@ -34,6 +34,7 @@ import (
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/localpath"
@ -100,11 +101,18 @@ func LoadFromTarball(img string) error {
p := filepath.Join(constants.ImageCacheDir, img)
p = localpath.SanitizeCacheDir(p)
cmd := exec.Command("docker", "load", "-i", p)
if output, err := cmd.CombinedOutput(); err != nil {
return errors.Wrapf(err, "%s", string(output))
tag, err := name.NewTag(Tag(img))
if err != nil {
return errors.Wrap(err, "new tag")
}
return nil
i, err := tarball.ImageFromPath(p, &tag)
if err != nil {
return errors.Wrap(err, "tarball")
}
_, err = daemon.Write(tag, i)
return err
}
// Tag returns just the image with the tag

View File

@ -128,10 +128,10 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
for _, img := range append([]string{cc.KicBaseImage}, kic.FallbackImages...) {
if err := image.LoadFromTarball(img); err == nil {
glog.Infof("successfully loaded %s from cached tarball", img)
finalImg = img
// strip the digest from the img before saving it in the config
// because loading an image from tarball to daemon doesn't load the digest
finalImg = image.Tag(img)
return nil
} else {
fmt.Println("Failed to load tarball:", err)
}
glog.Infof("Downloading %s to local daemon", img)
err := image.WriteImageToDaemon(img)