Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #437 from ehazlett/fix-warn-no-internet-b2d
Browse files Browse the repository at this point in the history
add timeout for b2d release check; warn instead of error if cannot check
  • Loading branch information
ehazlett committed Feb 2, 2015
2 parents 5b76400 + feb3403 commit 55ea356
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drivers/virtualbox/virtualbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (d *Driver) Create() error {
// until then always use "latest"
isoURL, err = utils.GetLatestBoot2DockerReleaseURL()
if err != nil {
return err
log.Warnf("Unable to check for the latest release: %s", err)
}

// todo: use real constant for .docker
Expand Down
2 changes: 1 addition & 1 deletion drivers/vmwarefusion/fusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (d *Driver) Create() error {
// until then always use "latest"
isoURL, err = utils.GetLatestBoot2DockerReleaseURL()
if err != nil {
return err
log.Warnf("Unable to check for the latest release: %s", err)
}

// todo: use real constant for .docker
Expand Down
2 changes: 1 addition & 1 deletion drivers/vmwarevsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (d *Driver) Create() error {
// until then always use "latest"
isoURL, err = utils.GetLatestBoot2DockerReleaseURL()
if err != nil {
return err
log.Warnf("Unable to check for the latest release: %s", err)
}

rootPath := utils.GetDockerDir()
Expand Down
30 changes: 28 additions & 2 deletions utils/b2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,39 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
"path/filepath"
"time"
)

const (
timeout = time.Second * 5
)

func defaultTimeout(network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, timeout)
}

func getClient() *http.Client {
transport := http.Transport{
Dial: defaultTimeout,
}

client := http.Client{
Transport: &transport,
}

return &client
}

// Get the latest boot2docker release tag name (e.g. "v0.6.0").
// FIXME: find or create some other way to get the "latest release" of boot2docker since the GitHub API has a pretty low rate limit on API requests
func GetLatestBoot2DockerReleaseURL() (string, error) {
rsp, err := http.Get("https://api.github.com/repos/boot2docker/boot2docker/releases")
client := getClient()

rsp, err := client.Get("https://api.github.com/repos/boot2docker/boot2docker/releases")
if err != nil {
return "", err
}
Expand All @@ -36,7 +60,9 @@ func GetLatestBoot2DockerReleaseURL() (string, error) {

// Download boot2docker ISO image for the given tag and save it at dest.
func DownloadISO(dir, file, url string) error {
rsp, err := http.Get(url)
client := getClient()

rsp, err := client.Get(url)
if err != nil {
return err
}
Expand Down

0 comments on commit 55ea356

Please sign in to comment.