Update Boot2docker download, and consolitate util functions.

Signed-off-by: Jeff Mendoza <jeffmendoza@live.com>
This commit is contained in:
Jeff Mendoza 2015-01-29 16:43:39 -08:00 committed by Evan Hazlett
parent 6ff61d26c9
commit d47000ea3b
4 changed files with 48 additions and 39 deletions

View File

@ -137,17 +137,19 @@ func (d *Driver) Create() error {
if d.boot2DockerLoc == "" {
if d.boot2DockerURL != "" {
isoURL = d.boot2DockerURL
log.Infof("Downloading boot2docker.iso from %s...", isoURL)
if err := utils.DownloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil {
return err
}
} else {
isoURL, err = utils.GetLatestBoot2DockerReleaseURL()
commonIsoPath, err := utils.DownloadUpdateB2D()
if err != nil {
return err
}
}
log.Infof("Downloading boot2docker...")
// todo: use common iso location
if err := utils.DownloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil {
return err
isoDest := filepath.Join(d.storePath, "boot2docker.iso")
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err
}
}
} else {
if err := utils.CopyFile(d.boot2DockerLoc, filepath.Join(d.storePath, "boot2docker.iso")); err != nil {

View File

@ -101,17 +101,6 @@ 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) PreCreateCheck() error {
return nil
}
@ -139,38 +128,43 @@ func (d *Driver) Create() error {
log.Infof("Downloading boot2docker.iso from %s...", isoURL)
if err := b2dutils.DownloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil {
return err
}
} else {
// todo: check latest release URL, download if it's new
// until then always use "latest"
isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
if err != nil {
log.Warnf("Unable to check for the latest release: %s", err)
}
}
// todo: use real constant for .docker
rootPath := filepath.Join(utils.GetDockerDir())
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 := b2dutils.DownloadISO(imgPath, "boot2docker.iso", isoURL); err != nil {
return err
}
}
isoDest := filepath.Join(d.storePath, "boot2docker.iso")
if err := utils.CopyFile(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...")

View File

@ -141,43 +141,49 @@ func (d *Driver) Create() error {
)
b2dutils := utils.NewB2dUtils("", "")
if d.Boot2DockerURL != "" {
isoURL = d.Boot2DockerURL
log.Infof("Downloading boot2docker.iso from %s...", isoURL)
if err := b2dutils.DownloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil {
return err
}
} else {
// todo: check latest release URL, download if it's new
// until then always use "latest"
isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
if err != nil {
log.Warnf("Unable to check for the latest release: %s", err)
}
}
// todo: use real constant for .docker
rootPath := filepath.Join(utils.GetDockerDir())
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 := b2dutils.DownloadISO(imgPath, "boot2docker.iso", isoURL); err != nil {
return err
}
}
}
}
isoDest := filepath.Join(d.storePath, "boot2docker.iso")
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err
}
}
log.Infof("Creating SSH key...")

View File

@ -235,42 +235,49 @@ func (d *Driver) Create() error {
)
b2dutils := utils.NewB2dUtils("", "")
if d.Boot2DockerURL != "" {
isoURL = d.Boot2DockerURL
log.Infof("Downloading boot2docker.iso from %s...", isoURL)
if err := b2dutils.DownloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil {
return err
}
} else {
// todo: check latest release URL, download if it's new
// until then always use "latest"
isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
if err != nil {
log.Warnf("Unable to check for the latest release: %s", err)
}
rootPath := utils.GetDockerDir()
}
// todo: use real constant for .docker
rootPath := filepath.Join(utils.GetDockerDir())
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 := b2dutils.DownloadISO(imgPath, "boot2docker.iso", isoURL); err != nil {
return err
}
}
}
}
isoDest := filepath.Join(d.storePath, "boot2docker.iso")
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err
}
}
log.Infof("Generating SSH Keypair...")