Skip to content

Commit

Permalink
Merge pull request docker#105 from nathanleclaire/cache_b2d_iso
Browse files Browse the repository at this point in the history
Only download boot2docker.iso one time
  • Loading branch information
bfirsh committed Dec 22, 2014
2 parents b86c37a + 154d71e commit 8296502
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions drivers/virtualbox/virtualbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -116,17 +127,45 @@ 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
// }
}
log.Infof("Downloading boot2docker...")
if err := downloadISO(d.storePath, "boot2docker.iso", isoURL); 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)

// 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
}
}

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
}
}

log.Infof("Creating SSH key...")
Expand Down

0 comments on commit 8296502

Please sign in to comment.