Skip to content

Commit

Permalink
use docker command line to check if image exists, since it is much fa…
Browse files Browse the repository at this point in the history
…ster than go-containerregistry
  • Loading branch information
Priya Wadhwa committed Mar 3, 2020
1 parent 3d291fd commit 5d16281
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/minikube/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -86,14 +87,18 @@ func WriteImageToDaemon(img string) error {
return errors.Wrap(err, "point host docker-daemon")
}
// Check if image exists locally
cmd := exec.Command("docker", "images", "--format", "{{.Repository}}:{{.Tag}}@{{.Digest}}")
if output, err := cmd.Output(); err == nil {
if strings.Contains(string(output), img) {
glog.Infof("Found %s in local docker daemon, skipping pull", img)
return nil
}
}
// Else, pull it
ref, err := name.ParseReference(img)
if err != nil {
return errors.Wrap(err, "parsing reference")
}
if _, err := daemon.Image(ref); err == nil {
glog.Infof("Found %s in local docker daemon, skipping pull", img)
return nil
}
i, err := remote.Image(ref)
if err != nil {
return errors.Wrap(err, "getting remote image")
Expand Down

0 comments on commit 5d16281

Please sign in to comment.