From fb0407ecdcb7911ff5582f1870659db288290680 Mon Sep 17 00:00:00 2001 From: Nathan LeClaire Date: Mon, 15 Dec 2014 12:57:02 -0800 Subject: [PATCH 1/2] Only download boot2docker.iso one time Signed-off-by: Nathan LeClaire --- drivers/virtualbox/virtualbox.go | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/virtualbox/virtualbox.go b/drivers/virtualbox/virtualbox.go index e4ab774d0f..84a2da48c5 100644 --- a/drivers/virtualbox/virtualbox.go +++ b/drivers/virtualbox/virtualbox.go @@ -97,6 +97,17 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { return nil } +func cpIso(src, dest string) error { + buf, err := ioutil.ReadFile(src) + if err != nil { + return err + } + if err := ioutil.WriteFile(dest, buf, 0600); err != nil { + return err + } + return nil +} + func (d *Driver) Create() error { var ( err error @@ -124,8 +135,26 @@ func (d *Driver) Create() error { // return err // } } - log.Infof("Downloading boot2docker...") - if err := downloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil { + + // todo: check latest release URL, download if it's new + // until then always use "latest" + + // todo: use real constant for .docker + rootPath := filepath.Join(drivers.GetHomeDir(), ".docker") + imgPath := filepath.Join(rootPath, "images") + commonIsoPath := filepath.Join(imgPath, "boot2docker.iso") + if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) { + log.Infof("Downloading boot2docker.iso to %s...", commonIsoPath) + if err := os.Mkdir(imgPath, 0700); err != nil { + return err + } + if err := downloadISO(imgPath, "boot2docker.iso", isoURL); err != nil { + return err + } + } + + isoDest := filepath.Join(d.storePath, "boot2docker.iso") + if err := cpIso(commonIsoPath, isoDest); err != nil { return err } From 154d71ee9cc53548db72d44c81291af4a80cef7d Mon Sep 17 00:00:00 2001 From: Nathan LeClaire Date: Tue, 16 Dec 2014 16:24:48 -0800 Subject: [PATCH 2/2] Make more robust based on feedback from @ehazlett Signed-off-by: Nathan LeClaire --- drivers/virtualbox/virtualbox.go | 44 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/drivers/virtualbox/virtualbox.go b/drivers/virtualbox/virtualbox.go index 84a2da48c5..80daf12a20 100644 --- a/drivers/virtualbox/virtualbox.go +++ b/drivers/virtualbox/virtualbox.go @@ -127,37 +127,47 @@ func (d *Driver) Create() error { if d.Boot2DockerURL != "" { isoURL = d.Boot2DockerURL + log.Infof("Downloading boot2docker.iso from %s...", isoURL) + if err := downloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil { + return err + } } else { // HACK: Docker 1.3 boot2docker image with client/daemon auth isoURL = "https://bfirsh.s3.amazonaws.com/boot2docker/boot2docker-1.3.1-identity-auth.iso" + + // todo: check latest release URL, download if it's new + // until then always use "latest" + // isoURL, err = getLatestReleaseURL() // if err != nil { // return err // } - } - // todo: check latest release URL, download if it's new - // until then always use "latest" + // todo: use real constant for .docker + rootPath := filepath.Join(drivers.GetHomeDir(), ".docker") + imgPath := filepath.Join(rootPath, "images") + commonIsoPath := filepath.Join(imgPath, "boot2docker.iso") + if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) { + log.Infof("Downloading boot2docker.iso to %s...", commonIsoPath) + + // just in case boot2docker.iso has been manually deleted + if _, err := os.Stat(imgPath); os.IsNotExist(err) { + if err := os.Mkdir(imgPath, 0700); err != nil { + return err + } + } - // todo: use real constant for .docker - rootPath := filepath.Join(drivers.GetHomeDir(), ".docker") - imgPath := filepath.Join(rootPath, "images") - commonIsoPath := filepath.Join(imgPath, "boot2docker.iso") - if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) { - log.Infof("Downloading boot2docker.iso to %s...", commonIsoPath) - if err := os.Mkdir(imgPath, 0700); err != nil { - return err + if err := downloadISO(imgPath, "boot2docker.iso", isoURL); err != nil { + return err + } } - if err := downloadISO(imgPath, "boot2docker.iso", isoURL); err != nil { + + isoDest := filepath.Join(d.storePath, "boot2docker.iso") + if err := cpIso(commonIsoPath, isoDest); err != nil { return err } } - isoDest := filepath.Join(d.storePath, "boot2docker.iso") - if err := cpIso(commonIsoPath, isoDest); err != nil { - return err - } - log.Infof("Creating SSH key...") if err := ssh.GenerateSSHKey(d.sshKeyPath()); err != nil {