Skip to content

Commit

Permalink
Add boot2docker url as a flag to the start command (#179) (#180)
Browse files Browse the repository at this point in the history
* added boot2docker url as a parameter to the start command
* added nolint comments for gosec linter errors
  • Loading branch information
febbraro authored Dec 11, 2018
1 parent 169de82 commit a2be2bc
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 77 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ func main() {
app.Commands = append(app.Commands, (&commands.Dev{}).Commands()...)
app.Commands = append(app.Commands, (&commands.SSH{}).Commands()...)

app.Run(os.Args)
app.Run(os.Args) // nolint: gosec
}
4 changes: 2 additions & 2 deletions commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (cmd *BaseCommand) Before(c *cli.Context) error {
cmd.out = util.Logger()
cmd.machine = Machine{Name: c.GlobalString("name"), out: util.Logger()}

util.NotifyInit(fmt.Sprintf("Outrigger (rig) %s", c.App.Version))
util.NotifyInit(fmt.Sprintf("Outrigger (rig) %s", c.App.Version)) // nolint: gosec

// Hold onto Context so that we can use it later without having to pass it around everywhere
cmd.context = c
Expand Down Expand Up @@ -62,7 +62,7 @@ func (cmd *BaseCommand) Failure(message string, errorName string, exitCode int)
}

// Handle error messaging.
util.NotifyError(cmd.context, message)
util.NotifyError(cmd.context, message) // nolint: gosec
// Print expanded troubleshooting guidance.
if !cmd.context.GlobalBool("power-user") {
util.PrintDebugHelp(message, errorName, exitCode)
Expand Down
6 changes: 3 additions & 3 deletions commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ func (cmd *Config) Run(c *cli.Context) error {
if !util.IsMac() {
// Add stuff to PATH only once
path := os.Getenv("PATH")
dir, _ := util.GetExecutableDir()
dir, _ := util.GetExecutableDir() // nolint: gosec
if !strings.Contains(path, dir) {
fmt.Printf("export PATH=%s%c$PATH\n", dir, os.PathListSeparator)
}
}

// Clear out any previous environment variables
if output, err := util.Command("docker-machine", "env", "-u").Output(); err == nil {
os.Stdout.Write(output)
os.Stdout.Write(output) // nolint: gosec
}

if cmd.machine.Exists() {
// Setup new values if machine is running
if output, err := util.Command("docker-machine", "env", cmd.machine.Name).Output(); err == nil {
os.Stdout.Write(output)
os.Stdout.Write(output) // nolint: gosec
}
} else {
return cmd.Failure(fmt.Sprintf("No machine named '%s' exists.", cmd.machine.Name), "MACHINE-NOT-FOUND", 12)
Expand Down
12 changes: 6 additions & 6 deletions commands/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (cmd *Dashboard) LaunchDashboard(machine Machine) error {
cmd.out.Verbose("Successfully updated dashboard.")
}

dockerAPIVersion, _ := util.GetDockerServerAPIVersion()
dockerAPIVersion, _ := util.GetDockerServerAPIVersion() // nolint: gosec
args := []string{
"run",
"-d",
Expand All @@ -78,11 +78,11 @@ func (cmd *Dashboard) LaunchDashboard(machine Machine) error {
dashboardImageName,
}

util.ForceStreamCommand("docker", args...)
util.ForceStreamCommand("docker", args...) // nolint: gosec
if util.IsMac() {
util.Command("open", "http://dashboard.outrigger.vm").Run()
util.Command("open", "http://dashboard.outrigger.vm").Run() // nolint: gosec
} else if util.IsWindows() {
util.Command("start", "http://dashboard.outrigger.vm").Run()
util.Command("start", "http://dashboard.outrigger.vm").Run() // nolint: gosec
} else {
cmd.out.Info("Outrigger Dashboard is now available at http://dashboard.outrigger.vm")
}
Expand All @@ -92,6 +92,6 @@ func (cmd *Dashboard) LaunchDashboard(machine Machine) error {

// StopDashboard stops and removes the dashboard container
func (cmd *Dashboard) StopDashboard() {
util.Command("docker", "stop", dashboardContainerName).Run()
util.Command("docker", "rm", dashboardContainerName).Run()
util.Command("docker", "stop", dashboardContainerName).Run() // nolint: gosec
util.Command("docker", "rm", dashboardContainerName).Run() // nolint: gosec
}
2 changes: 1 addition & 1 deletion commands/dns-records.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (cmd *DNSRecords) LoadRecords() ([]map[string]interface{}, error) {
return nil, fmt.Errorf("failed to parse dnsdock JSON: %s", err)
}

dnsdockMap, _ := js.Map()
dnsdockMap, _ := js.Map() // nolint: gosec
records := []map[string]interface{}{}
for id, value := range dnsdockMap {
record := value.(map[string]interface{})
Expand Down
34 changes: 17 additions & 17 deletions commands/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ func (cmd *DNS) configureMacRoutes(machine Machine) {
if machine.IsXhyve() {
cmd.removeHostFilter(machineIP)
}
util.Command("sudo", "route", "-n", "delete", "-net", "172.17.0.0").Run()
util.StreamCommand("sudo", "route", "-n", "add", "172.17.0.0/16", machineIP)
util.Command("sudo", "route", "-n", "delete", "-net", "172.17.0.0").Run() // nolint: gosec
util.StreamCommand("sudo", "route", "-n", "add", "172.17.0.0/16", machineIP) // nolint: gosec
if _, err := os.Stat("/usr/sbin/discoveryutil"); err == nil {
// Put this here for people running OS X 10.10.0 to 10.10.3 (oy vey.)
cmd.out.Verbose("Restarting discoveryutil to flush DNS caches")
util.StreamCommand("sudo", "launchctl", "unload", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist")
util.StreamCommand("sudo", "launchctl", "load", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist")
util.StreamCommand("sudo", "launchctl", "unload", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist") // nolint: gosec
util.StreamCommand("sudo", "launchctl", "load", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist") // nolint: gosec
} else {
// Reset DNS cache. We have seen this suddenly make /etc/resolver/vm work.
cmd.out.Verbose("Restarting mDNSResponder to flush DNS caches")
util.StreamCommand("sudo", "killall", "-HUP", "mDNSResponder")
util.StreamCommand("sudo", "killall", "-HUP", "mDNSResponder") // nolint: gosec
}
}

Expand All @@ -109,13 +109,13 @@ func (cmd *DNS) removeHostFilter(ipAddr string) {
member := memberRegexp.FindStringSubmatch(string(ifaceData))[1]

// #4: ifconfig <bridge> -hostfilter <member>
util.StreamCommand("sudo", "ifconfig", iface, "-hostfilter", member)
util.StreamCommand("sudo", "ifconfig", iface, "-hostfilter", member) // nolint: gosec
}

// ConfigureWindowsRoutes configures network routing
func (cmd *DNS) configureWindowsRoutes(machine Machine) {
util.Command("runas", "/noprofile", "/user:Administrator", "route", "DELETE", "172.17.0.0").Run()
util.StreamCommand("runas", "/noprofile", "/user:Administrator", "route", "-p", "ADD", "172.17.0.0/16", machine.GetIP())
util.Command("runas", "/noprofile", "/user:Administrator", "route", "DELETE", "172.17.0.0").Run() // nolint: gosec
util.StreamCommand("runas", "/noprofile", "/user:Administrator", "route", "-p", "ADD", "172.17.0.0/16", machine.GetIP()) // nolint: gosec
}

// StartDNS will start the dnsdock service
Expand Down Expand Up @@ -152,7 +152,7 @@ func (cmd *DNS) StartDNS(machine Machine, nameservers string) error {
args = append(args, "--nameserver="+server)
}

util.StreamCommand("docker", args...)
util.StreamCommand("docker", args...) // nolint: gosec
// Configure the resolvers based on platform
var resolverReturn error
if util.IsMac() {
Expand Down Expand Up @@ -181,12 +181,12 @@ func (cmd *DNS) configureMacResolver(machine Machine) error {
if _, err := os.Stat("/usr/sbin/discoveryutil"); err == nil {
// Put this here for people running OS X 10.10.0 to 10.10.3 (oy vey.)
cmd.out.Verbose("Restarting discoveryutil to flush DNS caches")
util.StreamCommand("sudo", "launchctl", "unload", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist")
util.StreamCommand("sudo", "launchctl", "load", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist")
util.StreamCommand("sudo", "launchctl", "unload", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist") // nolint: gosec
util.StreamCommand("sudo", "launchctl", "load", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist") // nolint: gosec
} else {
// Reset DNS cache. We have seen this suddenly make /etc/resolver/vm work.
cmd.out.Verbose("Restarting mDNSResponder to flush DNS caches")
util.StreamCommand("sudo", "killall", "-HUP", "mDNSResponder")
util.StreamCommand("sudo", "killall", "-HUP", "mDNSResponder") // nolint: gosec
}
return nil
}
Expand All @@ -202,18 +202,18 @@ func (cmd *DNS) configureLinuxResolver() error {
// Is NetworkManager in use
if _, err := os.Stat("/etc/NetworkManager/dnsmasq.d"); err == nil {
// Install for NetworkManager/dnsmasq connection to dnsdock
util.StreamCommand("bash", "-c", fmt.Sprintf("echo 'server=/vm/%s' | sudo tee /etc/NetworkManager/dnsmasq.d/dnsdock.conf", bridgeIP))
util.StreamCommand("bash", "-c", fmt.Sprintf("echo 'server=/vm/%s' | sudo tee /etc/NetworkManager/dnsmasq.d/dnsdock.conf", bridgeIP)) // nolint: gosec

// Restart NetworkManager if it is running
if err := util.Command("systemctl", "is-active", "NetworkManager").Run(); err != nil {
util.StreamCommand("sudo", "systemctl", "restart", "NetworkManager")
util.StreamCommand("sudo", "systemctl", "restart", "NetworkManager") // nolint: gosec
}
}

// Is libnss-resolver in use
if _, err := os.Stat("/etc/resolver"); err == nil {
// Install for libnss-resolver connection to dnsdock
util.Command("bash", "-c", fmt.Sprintf("echo 'nameserver %s:53' | sudo tee /etc/resolver/vm", bridgeIP)).Run()
util.Command("bash", "-c", fmt.Sprintf("echo 'nameserver %s:53' | sudo tee /etc/resolver/vm", bridgeIP)).Run() // nolint: gosec
}

return nil
Expand All @@ -228,6 +228,6 @@ func (cmd *DNS) configureWindowsResolver(machine Machine) error {

// StopDNS stops the dnsdock service and cleans up
func (cmd *DNS) StopDNS() {
util.Command("docker", "stop", "dnsdock").Run()
util.Command("docker", "rm", "dnsdock").Run()
util.Command("docker", "stop", "dnsdock").Run() // nolint: gosec
util.Command("docker", "rm", "dnsdock").Run() // nolint: gosec
}
4 changes: 2 additions & 2 deletions commands/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (cmd *Doctor) Run(c *cli.Context) error {
cmd.out.Spin("Checking Docker version...")
clientAPIVersion := util.GetDockerClientAPIVersion()
serverAPIVersion, err := util.GetDockerServerAPIVersion()
serverMinAPIVersion, _ := util.GetDockerServerMinAPIVersion()
serverMinAPIVersion, _ := util.GetDockerServerMinAPIVersion() // nolint: gosec

// Older clients can talk to newer servers, and when you ask a newer server
// it's version in the presence of an older server it will downgrade it's
Expand All @@ -116,7 +116,7 @@ func (cmd *Doctor) Run(c *cli.Context) error {
if serverMinAPIVersion != nil {
constraintString = fmt.Sprintf(">= %s", serverMinAPIVersion)
}
apiConstraint, _ := version.NewConstraint(constraintString)
apiConstraint, _ := version.NewConstraint(constraintString) // nolint: gosec

if err != nil {
cmd.out.Error("Could not determine Docker Machine Docker versions: ", err)
Expand Down
4 changes: 2 additions & 2 deletions commands/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func (cmd *Kill) Run(c *cli.Context) error {
}

cmd.out.Spin(fmt.Sprintf("Killing machine '%s'...", cmd.machine.Name))
util.StreamCommand("docker-machine", "kill", cmd.machine.Name)
util.StreamCommand("docker-machine", "kill", cmd.machine.Name) // nolint: gosec

// Ensure the underlying virtualization has stopped
driver := cmd.machine.GetDriver()
switch driver {
case util.VirtualBox:
util.StreamCommand("controlvm", cmd.machine.Name, "poweroff")
util.StreamCommand("controlvm", cmd.machine.Name, "poweroff") // nolint: gosec
case util.VMWare:
cmd.out.Warning("Add vmrun suspend command.")
case util.Xhyve:
Expand Down
23 changes: 13 additions & 10 deletions commands/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ type Machine struct {
}

// Create will generate a new Docker Machine configured according to user specification
func (m *Machine) Create(driver string, cpuCount string, memSize string, diskSize string) error {
func (m *Machine) Create(driver string, cpuCount string, memSize string, diskSize string, isoURL string) error {
m.out.Info("Creating a %s machine named '%s' with CPU(%s) MEM(%s) DISK(%s)...", driver, m.Name, cpuCount, memSize, diskSize)

boot2dockerURL := "https://github.com/boot2docker/boot2docker/releases/download/v" + util.GetRawCurrentDockerVersion() + "/boot2docker.iso"
boot2dockerURL := isoURL
if boot2dockerURL == "" {
boot2dockerURL = "https://github.com/boot2docker/boot2docker/releases/download/v" + util.GetRawCurrentDockerVersion() + "/boot2docker.iso"
}

var create util.Executor

Expand Down Expand Up @@ -144,19 +147,19 @@ func (m *Machine) SetEnv() {
if js.Get("HostOptions").Get("EngineOptions").Get("TlsVerify").MustBool() {
tlsVerify = 1
}
os.Setenv("DOCKER_TLS_VERIFY", fmt.Sprintf("%d", tlsVerify))
os.Setenv("DOCKER_HOST", fmt.Sprintf("tcp://%s:2376", js.Get("Driver").Get("IPAddress").MustString()))
os.Setenv("DOCKER_MACHINE_NAME", js.Get("Driver").Get("MachineName").MustString())
os.Setenv("DOCKER_CERT_PATH", js.Get("HostOptions").Get("AuthOptions").Get("StorePath").MustString())
os.Setenv("DOCKER_TLS_VERIFY", fmt.Sprintf("%d", tlsVerify)) // nolint: gosec
os.Setenv("DOCKER_HOST", fmt.Sprintf("tcp://%s:2376", js.Get("Driver").Get("IPAddress").MustString())) // nolint: gosec
os.Setenv("DOCKER_MACHINE_NAME", js.Get("Driver").Get("MachineName").MustString()) // nolint: gosec
os.Setenv("DOCKER_CERT_PATH", js.Get("HostOptions").Get("AuthOptions").Get("StorePath").MustString()) // nolint: gosec
}
}

// UnsetEnv will remove the Docker proxy variables
func (m *Machine) UnsetEnv() {
os.Unsetenv("DOCKER_TLS_VERIFY")
os.Unsetenv("DOCKER_HOST")
os.Unsetenv("DOCKER_CERT_PATH")
os.Unsetenv("DOCKER_MACHINE_NAME")
os.Unsetenv("DOCKER_TLS_VERIFY") // nolint: gosec
os.Unsetenv("DOCKER_HOST") // nolint: gosec
os.Unsetenv("DOCKER_CERT_PATH") // nolint: gosec
os.Unsetenv("DOCKER_MACHINE_NAME") // nolint: gosec
}

// Exists determines if the Docker Machine exist
Expand Down
4 changes: 2 additions & 2 deletions commands/project_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewProjectConfig() *ProjectConfig {
projectConfigFile := os.Getenv("RIG_PROJECT_CONFIG_FILE")

if projectConfigFile == "" {
projectConfigFile, _ = FindProjectConfigFilePath()
projectConfigFile, _ = FindProjectConfigFilePath() // nolint: gosec
}

if projectConfigFile != "" {
Expand Down Expand Up @@ -83,7 +83,7 @@ func FindProjectConfigFilePath() (string, error) {
// nolint: gocyclo
func NewProjectConfigFromFile(filename string) (*ProjectConfig, error) {
logger := util.Logger()
filepath, _ := filepath.Abs(filename)
filepath, _ := filepath.Abs(filename) // nolint: gosec
config := &ProjectConfig{
File: filename,
Path: filepath,
Expand Down
2 changes: 1 addition & 1 deletion commands/project_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ func (p *ProjectScript) addCommandPath() {
if binDir != "" {
p.out.Verbose("Adding project bin directory to $PATH: %s", binDir)
path := os.Getenv("PATH")
os.Setenv("PATH", fmt.Sprintf("%s%c%s", binDir, os.PathListSeparator, path))
os.Setenv("PATH", fmt.Sprintf("%s%c%s", binDir, os.PathListSeparator, path)) // nolint: gosec
}
}
10 changes: 5 additions & 5 deletions commands/project_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (cmd *ProjectSync) StartUnisonSync(ctx *cli.Context, volumeName string, con

// Ensure the processes can handle a large number of watches
if err := cmd.machine.SetSysctl("fs.inotify.max_user_watches", maxWatches); err != nil {
cmd.Failure(fmt.Sprintf("Failure configuring file watches on Docker Machine: %v", err), "INOTIFY-WATCH-FAILURE", 12)
cmd.Failure(fmt.Sprintf("Failure configuring file watches on Docker Machine: %v", err), "INOTIFY-WATCH-FAILURE", 12) // nolint: gosec
}

cmd.out.SpinWithVerbose("Starting sync volume: %s", volumeName)
Expand All @@ -326,7 +326,7 @@ func (cmd *ProjectSync) StartUnisonSync(ctx *cli.Context, volumeName string, con
unisonMinorVersion := util.GetUnisonMinorVersion()

cmd.out.Verbose("Local Unison version for compatibility: %s", unisonMinorVersion)
util.Command("docker", "container", "stop", volumeName).Run()
util.Command("docker", "container", "stop", volumeName).Run() // nolint: gosec
containerArgs := []string{
"container", "run", "--detach", "--rm",
"-v", fmt.Sprintf("%s:/unison", volumeName),
Expand All @@ -337,7 +337,7 @@ func (cmd *ProjectSync) StartUnisonSync(ctx *cli.Context, volumeName string, con
fmt.Sprintf("outrigger/unison:%s", unisonMinorVersion),
}
if err := util.Command("docker", containerArgs...).Run(); err != nil {
cmd.Failure(fmt.Sprintf("Failure starting sync container %s: %v", volumeName, err), "SYNC-CONTAINER-START-FAILED", 13)
cmd.Failure(fmt.Sprintf("Failure starting sync container %s: %v", volumeName, err), "SYNC-CONTAINER-START-FAILED", 13) // nolint: gosec
}

ip, err := cmd.WaitForUnisonContainer(volumeName, ctx.Int("initial-sync-timeout"))
Expand Down Expand Up @@ -393,7 +393,7 @@ func (cmd *ProjectSync) StartUnisonSync(ctx *cli.Context, volumeName string, con
// SetupBindVolume will create minimal Docker Volumes for systems that have native container/volume support
func (cmd *ProjectSync) SetupBindVolume(volumeName string, workingDir string) error {
cmd.out.SpinWithVerbose("Starting local bind volume: %s", volumeName)
util.Command("docker", "volume", "rm", volumeName).Run()
util.Command("docker", "volume", "rm", volumeName).Run() // nolint: gosec

volumeArgs := []string{
"volume", "create",
Expand Down Expand Up @@ -476,7 +476,7 @@ func (cmd *ProjectSync) WaitForUnisonContainer(containerName string, timeoutSeco
cmd.out.Verbose("Attempt #%d...", i)
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", ip, unisonPort))
if err == nil {
conn.Close()
conn.Close() // nolint: gosec
cmd.out.Verbose("Connected to unison on %s", containerName)
return ip, nil
}
Expand Down
15 changes: 10 additions & 5 deletions commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (cmd *Start) Commands() []cli.Command {
Value: 2,
Usage: "Number of CPU to allocate to the VM. Defaults to 2. Only used if start needs to create a machine.",
},
cli.StringFlag{
Name: "boot2docker-url",
Usage: "Fully qualified URL for a specific boot2docker ISO.",
},
cli.StringFlag{
Name: "nameservers",
Value: "8.8.8.8:53",
Expand Down Expand Up @@ -82,7 +86,8 @@ func (cmd *Start) Run(c *cli.Context) error {
diskSize := strconv.Itoa(c.Int("disk-size") * 1000)
memSize := strconv.Itoa(c.Int("memory-size"))
cpuCount := strconv.Itoa(c.Int("cpu-count"))
cmd.machine.Create(driver, cpuCount, memSize, diskSize)
isoURL := c.String("boot2docker-url")
cmd.machine.Create(driver, cpuCount, memSize, diskSize, isoURL) // nolint: gosec
}

if err := cmd.machine.Start(); err != nil {
Expand All @@ -95,7 +100,7 @@ func (cmd *Start) Run(c *cli.Context) error {
cmd.out.Info("Docker Machine (%s) Created", cmd.machine.Name)

dns := DNS{cmd.BaseCommand}
dns.StartDNS(cmd.machine, c.String("nameservers"))
dns.StartDNS(cmd.machine, c.String("nameservers")) // nolint: gosec

// NFS mounts are Mac-only.
if util.IsMac() {
Expand Down Expand Up @@ -142,7 +147,7 @@ func (cmd *Start) Run(c *cli.Context) error {

cmd.out.Spin("Launching Dashboard...")
dash := Dashboard{cmd.BaseCommand}
dash.LaunchDashboard(cmd.machine)
dash.LaunchDashboard(cmd.machine) // nolint: gosec
cmd.out.Info("Dashboard is ready")

// Check for availability of a rig upgrade
Expand All @@ -159,10 +164,10 @@ func (cmd *Start) Run(c *cli.Context) error {
// a virtual machine and networking is not required or managed by Outrigger.
func (cmd *Start) StartMinimal(nameservers string) error {
dns := DNS{cmd.BaseCommand}
dns.StartDNS(cmd.machine, nameservers)
dns.StartDNS(cmd.machine, nameservers) // nolint: gosec

dash := Dashboard{cmd.BaseCommand}
dash.LaunchDashboard(cmd.machine)
dash.LaunchDashboard(cmd.machine) // nolint: gosec

return cmd.Success("Outrigger services started")
}
Loading

0 comments on commit a2be2bc

Please sign in to comment.