Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cache image for Windows #2000

Merged
merged 2 commits into from
Oct 3, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions pkg/minikube/machine/cache_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package machine
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -122,6 +123,32 @@ func hasWindowsDriveLetter(s string) bool {
return false
}

func getWindowsVolumeName(d string) (string, error) {
cmd := exec.Command("wmic", "volume", "where", "DriveLetter = '"+d+":'", "get", "DeviceID")

stdout, err := cmd.Output()
if err != nil {
return "", err
}

outs := strings.Split(strings.Replace(string(stdout), "\r", "", -1), "\n")

var vname string
for _, l := range outs {
s := strings.TrimSpace(l)
if strings.HasPrefix(s, `\\?\Volume{`) && strings.HasSuffix(s, `}\`) {
vname = s
break
}
}

if vname == "" {
return "", errors.New("failed to get a volume GUID")
}

return vname, nil
}

func LoadFromCacheBlocking(cmd bootstrapper.CommandRunner, src string) error {
glog.Infoln("Loading image from cache at ", src)
filename := filepath.Base(src)
Expand Down Expand Up @@ -162,6 +189,18 @@ func getSrcRef(image string) (types.ImageReference, error) {
}

func getDstRef(image, dst string) (types.ImageReference, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe add a few unit tests here for the new behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I will add the unit tests from now.

if hasWindowsDriveLetter(dst) {
// ParseReference does not support a Windows drive letter.
// Therefore, will change the drive letter to a volume name.
vname, err := getWindowsVolumeName(dst[:1])
if err != nil {
return nil, errors.Wrap(err, "parsing docker archive dst ref: get Windows volume name")
}
dst = vname + dst[3:]
if _, err := os.Stat(filepath.Dir(dst)); err != nil {
return nil, errors.Wrap(err, "parsing docker archive dst ref: get Windows volume name")
}
}
dstRef, err := archive.ParseReference(dst + ":" + image)
if err != nil {
return nil, errors.Wrap(err, "parsing docker archive dst ref")
Expand All @@ -179,13 +218,6 @@ func CacheImage(image, dst string) error {
return errors.Wrapf(err, "making cache image directory: %s", dst)
}

// TODO: support Windows drive letter.
// L:164 ParseReference does not support Windows drive letter.
// If contains Windows drive letter, it disable cache image for now.
if hasWindowsDriveLetter(dst) {
return nil
}

srcRef, err := getSrcRef(image)
if err != nil {
return errors.Wrap(err, "creating docker image src ref")
Expand Down