Skip to content
This repository has been archived by the owner on Feb 27, 2018. It is now read-only.

Add configuration flag allowing the use of a custom b2d ISO source URL #267

Merged
merged 1 commit into from
Oct 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
21 changes: 14 additions & 7 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For regexps that MustCompile, it is typical to make a var outside the function so that the failure will happen immediately at startup... but probably not a big deal in this case.
Otherwise, LGTM.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo it would be better if the custom iso was not saved as 'boot2docker.iso' - for extra credit, having the b2d.iso's each save to a versioned file would be very awesome, but don't mind me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we turn around that PR as discussed just above so that the flag is --iso-url supporting a 1- or 2-steps process rather than a 1-step override, how we would qualify an ISO as "custom" (and therefore give it another B2D.ISO default)? Would matching github.com/repos/boot2docker/boot2docker/releases be enough to tell it's "official"? It seems a little brittle. Plus, that introduces a coupling between the remote/local ISO configuration flags. Did you have any specific use-cases/flows in mind?

return fmt.Errorf("Failed to download ISO image: %s", err)
}
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down