From 6cc72c4c5343ac7cab310a0ceee8fae126d8b938 Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Mon, 6 Oct 2014 19:59:07 +0200 Subject: [PATCH] Make the source URL for the b2d ISO customizable --- README.md | 7 +++++++ cmds.go | 21 ++++++++++++++------- config.go | 1 + driver/config.go | 1 + 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dc15748..5d7048a 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,13 @@ SSHKey = "/Users/sven/.ssh/id_boot2docker" # name of boot2docker virtual machine VM = "boot2docker-vm" +# URL pointing either to a Github "/releases" API endpoint to automatically +# retrieve the `boot2docker.iso` asset from the latest released version of a +# repo, or directly to an ISO image +ISOURL = "https://api.github.com/repos/boot2docker/boot2docker/releases" +#ISOURL = "https://github.com/boot2docker/boot2docker/releases/download/v1.0.0/boot2docker.iso" +#ISOURL = "https://internal.corp.org/b2d.iso" + # path to boot2docker ISO image ISO = "/Users/sven/.boot2docker/boot2docker.iso" diff --git a/cmds.go b/cmds.go index f82c979..fb0bac9 100644 --- a/cmds.go +++ b/cmds.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "regexp" "runtime" "strings" "time" @@ -406,15 +407,21 @@ func cmdIP() error { // Download the boot2docker ISO image. func cmdDownload() error { - fmt.Println("Downloading boot2docker ISO image...") - url := "https://api.github.com/repos/boot2docker/boot2docker/releases" - tag, err := getLatestReleaseName(url) - if err != nil { - return fmt.Errorf("Failed to get latest release: %s", err) + url := B2D.ISOURL + + re := regexp.MustCompile("https://api.github.com/repos/([^/]+)/([^/]+)/releases") + if matches := re.FindStringSubmatch(url); len(matches) == 3 { + tag, err := getLatestReleaseName(url) + if err != nil { + return fmt.Errorf("Failed to get latest release: %s", err) + } + org := matches[1] + repo := matches[2] + fmt.Printf("Latest release for %s/%s is %s\n", org, repo, tag) + url = fmt.Sprintf("https://github.com/%s/%s/releases/download/%s/boot2docker.iso", org, repo, tag) } - fmt.Printf("Latest release is %s\n", tag) - url = fmt.Sprintf("https://github.com/boot2docker/boot2docker/releases/download/%s/boot2docker.iso", tag) + fmt.Println("Downloading boot2docker ISO image...") if err := download(B2D.ISO, url); err != nil { return fmt.Errorf("Failed to download ISO image: %s", err) } diff --git a/config.go b/config.go index 99db276..2a3e90e 100644 --- a/config.go +++ b/config.go @@ -91,6 +91,7 @@ func config() (*flag.FlagSet, error) { // removed for now, requires re-parsing a new config file which is too messy //flags.StringVarP(&B2D.Dir, "dir", "d", dir, "boot2docker config directory.") B2D.Dir = dir + flags.StringVar(&B2D.ISOURL, "iso-url", "https://api.github.com/repos/boot2docker/boot2docker/releases", "source URL to provision the boot2docker ISO image.") flags.StringVar(&B2D.ISO, "iso", filepath.Join(dir, "boot2docker.iso"), "path to boot2docker ISO image.") // Sven disabled this, as it is broken - if I user with a fresh computer downloads diff --git a/driver/config.go b/driver/config.go index 5d11167..5133485 100644 --- a/driver/config.go +++ b/driver/config.go @@ -19,6 +19,7 @@ type MachineConfig struct { SSHKey string // SSH key to send to the vm VM string // virtual machine name Dir string // boot2docker directory + ISOURL string // Source URL to retrieve the ISO from ISO string // boot2docker ISO image path DiskSize uint // VM disk image size (MB) Memory uint // VM memory size (MB)