Skip to content

Commit a74abd6

Browse files
author
Adam Ross
committed
Merge remote-tracking branch 'origin/develop' into feature/spinners
* origin/develop: Display executed commands via Verbose Logging (#111) Better cross platform builds (#118) Fixing Outrigger Dashboard on Linux (#117) Fixed bug in libnss-resolver DNS resolution (#116) Added rpm to build, well, rpms Transitioned to different go base to try to head off problems with dynamically linked go binaries tweaking some build flags tweaking CGO messing with ldflags tweaked goreleaser config
2 parents 7a1f991 + 80aaf4e commit a74abd6

19 files changed

+234
-176
lines changed

.goreleaser.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# One release file to rule them all
2+
project_name: outrigger-cli
23

34
# Platforms/architectures to target
45
builds:
56
- binary: rig
67
main: ./cmd/main.go
8+
env:
9+
- CGO_ENABLED=0
710
goos:
811
- windows
912
- darwin
@@ -26,6 +29,7 @@ release:
2629
github:
2730
owner: phase2
2831
name: rig
32+
draft: true
2933

3034
# Publishing Homebrew Formula to the Tap repo
3135
brew:

Dockerfile

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
FROM golang:1.9-alpine
22

33
RUN apk add --no-cache \
4-
ca-certificates \
5-
git \
6-
gcc \
7-
libffi-dev \
8-
make \
9-
musl-dev \
10-
rpm \
11-
ruby \
12-
ruby-dev \
13-
tar \
14-
&& go get -u github.com/golang/dep/... \
4+
ca-certificates \
5+
git \
6+
gcc \
7+
libffi-dev \
8+
make \
9+
musl-dev \
10+
rpm \
11+
ruby \
12+
ruby-dev \
13+
tar
14+
15+
RUN go get -u github.com/golang/dep/... \
1516
&& go get -u github.com/alecthomas/gometalinter \
1617
&& go get -u github.com/goreleaser/goreleaser
1718

1819
RUN gometalinter --install --update
19-
RUN gem install --no-rdoc --no-ri fpm
20+
RUN gem install --no-rdoc --no-ri fpm

commands/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package commands
33
import (
44
"fmt"
55
"os"
6-
"os/exec"
76
"strings"
87

98
"github.com/phase2/rig/util"
@@ -44,13 +43,13 @@ func (cmd *Config) Run(c *cli.Context) error {
4443
}
4544

4645
// Clear out any previous environment variables
47-
if output, err := exec.Command("docker-machine", "env", "-u").Output(); err == nil {
46+
if output, err := util.Command("docker-machine", "env", "-u").Output(); err == nil {
4847
os.Stdout.Write(output)
4948
}
5049

5150
if cmd.machine.Exists() {
5251
// Setup new values if machine is running
53-
if output, err := exec.Command("docker-machine", "env", cmd.machine.Name).Output(); err == nil {
52+
if output, err := util.Command("docker-machine", "env", cmd.machine.Name).Output(); err == nil {
5453
os.Stdout.Write(output)
5554
}
5655
} else {

commands/dashboard.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package commands
22

33
import (
44
"fmt"
5-
"os/exec"
65

76
"github.com/phase2/rig/util"
87
"github.com/urfave/cli"
@@ -59,11 +58,11 @@ func (cmd *Dashboard) LaunchDashboard(machine Machine) error {
5958
}
6059

6160
cmd.out.Verbose.Printf("Attempting to update %s", dashboardImageName)
62-
if err := util.StreamCommand(exec.Command("docker", "pull", dashboardImageName)); err != nil {
61+
if err := util.StreamCommand("docker", "pull", dashboardImageName); err != nil {
6362
cmd.out.Verbose.Println("Failed to update dashboard image. Will use local cache if available.")
6463
}
6564

66-
dockerAPIVersion, _ := util.GetDockerServerAPIVersion(cmd.machine.Name)
65+
dockerAPIVersion, _ := util.GetDockerServerAPIVersion()
6766
args := []string{
6867
"run",
6968
"-d",
@@ -76,12 +75,11 @@ func (cmd *Dashboard) LaunchDashboard(machine Machine) error {
7675
dashboardImageName,
7776
}
7877

79-
util.StreamCommand(exec.Command("docker", args...))
80-
78+
util.ForceStreamCommand("docker", args...)
8179
if util.IsMac() {
82-
exec.Command("open", "http://dashboard.outrigger.vm").Run()
80+
util.Command("open", "http://dashboard.outrigger.vm").Run()
8381
} else if util.IsWindows() {
84-
exec.Command("start", "http://dashboard.outrigger.vm").Run()
82+
util.Command("start", "http://dashboard.outrigger.vm").Run()
8583
} else {
8684
cmd.out.Info.Println("Outrigger Dashboard is now available at http://dashboard.outrigger.vm")
8785
}
@@ -91,6 +89,6 @@ func (cmd *Dashboard) LaunchDashboard(machine Machine) error {
9189

9290
// StopDashboard stops and removes the dashboard container
9391
func (cmd *Dashboard) StopDashboard() {
94-
exec.Command("docker", "stop", dashboardContainerName).Run()
95-
exec.Command("docker", "rm", dashboardContainerName).Run()
92+
util.Command("docker", "stop", dashboardContainerName).Run()
93+
util.Command("docker", "rm", dashboardContainerName).Run()
9694
}

commands/data_backup.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package commands
33
import (
44
"fmt"
55
"os"
6-
"os/exec"
76

8-
"github.com/fatih/color"
97
"github.com/phase2/rig/util"
108
"github.com/urfave/cli"
119
)
@@ -54,7 +52,7 @@ func (cmd *DataBackup) Run(c *cli.Context) error {
5452
backupFile := fmt.Sprintf("%s%c%s.tgz", backupDir, os.PathSeparator, cmd.machine.Name)
5553
if _, err := os.Stat(backupDir); err != nil {
5654
cmd.out.Info.Printf("Creating backup directory: %s...", backupDir)
57-
if mkdirErr := exec.Command("mkdir", "-p", backupDir).Run(); mkdirErr != nil {
55+
if mkdirErr := util.Command("mkdir", "-p", backupDir).Run(); mkdirErr != nil {
5856
cmd.out.Error.Println(mkdirErr)
5957
return cmd.Error(fmt.Sprintf("Could not create backup directory %s", backupDir), "BACKUP-DIR-CREATE-FAILED", 12)
6058
}
@@ -68,16 +66,9 @@ func (cmd *DataBackup) Run(c *cli.Context) error {
6866
// Stream the archive to stdout and capture it in a local file so we don't waste
6967
// space storing an archive on the VM filesystem. There may not be enough space.
7068
archiveCmd := fmt.Sprintf("sudo tar czf - -C %s .", dataDir)
71-
backup := exec.Command("docker-machine", "ssh", cmd.machine.Name, archiveCmd, ">", backupFile)
72-
backup.Stderr = os.Stderr
73-
74-
color.Set(color.FgCyan)
75-
err := backup.Run()
76-
color.Unset()
77-
78-
if err != nil {
79-
cmd.progress.Fail("Backup failed")
80-
return cmd.Error(err.Error(), "COMMAND-ERROR", 13)
69+
if err := util.StreamCommand("docker-machine", "ssh", cmd.machine.Name, archiveCmd, ">", backupFile); err != nil {
70+
cmd.progress.Fail(fmt.Sprintf("Backup failed: %s", err.Error()))
71+
return cmd.Error("Backup failed", "COMMAND-ERROR", 13)
8172
}
8273

8374
cmd.progress.Complete(fmt.Sprintf("Backup complete: %s", backupFile))

commands/data_restore.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package commands
33
import (
44
"fmt"
55
"os"
6-
"os/exec"
76
"strings"
87

9-
"github.com/fatih/color"
108
"github.com/phase2/rig/util"
119
"github.com/urfave/cli"
1210
)
@@ -63,17 +61,9 @@ func (cmd *DataRestore) Run(c *cli.Context) error {
6361

6462
// Send the archive via stdin and extract inline. Saves on disk & performance
6563
extractCmd := fmt.Sprintf("cat %s | docker-machine ssh %s \"sudo tar xzf - -C %s\"", backupFile, cmd.machine.Name, dataDir)
66-
cmd.out.Info.Printf(extractCmd)
67-
backup := exec.Command("bash", "-c", extractCmd)
68-
backup.Stderr = os.Stderr
69-
70-
color.Set(color.FgCyan)
71-
err := backup.Run()
72-
color.Unset()
73-
74-
if err != nil {
75-
cmd.progress.Fail("Data restore failed")
76-
return cmd.Error(err.Error(), "COMMAND-ERROR", 13)
64+
if err := util.StreamCommand("bash", "-c", extractCmd); err != nil {
65+
cmd.progress.Fail(fmt.Sprintf("Data restore failed: %s", err.Error()))
66+
return cmd.Error("Data restore failed", "COMMAND-ERROR", 13)
7767
}
7868

7969
cmd.progress.Complete("Data restore complete")

commands/dns-records.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"fmt"
55
"io/ioutil"
66
"net/http"
7-
"os/exec"
87
"strings"
98

109
"github.com/bitly/go-simplejson"
1110
"github.com/urfave/cli"
11+
12+
"github.com/phase2/rig/util"
1213
)
1314

1415
// DNSRecords is the command for exporting all DNS Records in Outrigger DNS in `hosts` file format
@@ -51,7 +52,7 @@ func (cmd *DNSRecords) Run(c *cli.Context) error {
5152

5253
// LoadRecords retrieves the records from DNSDock and processes/return them
5354
func (cmd *DNSRecords) LoadRecords() ([]map[string]interface{}, error) {
54-
ip, err := exec.Command("docker", "inspect", "--format", "{{.NetworkSettings.IPAddress}}", "dnsdock").Output()
55+
ip, err := util.Command("docker", "inspect", "--format", "{{.NetworkSettings.IPAddress}}", "dnsdock").Output()
5556
if err != nil {
5657
return nil, fmt.Errorf("failed to discover dnsdock IP address: %s", err)
5758
}

commands/dns.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package commands
33
import (
44
"fmt"
55
"os"
6-
"os/exec"
76
"regexp"
87
"strings"
98

@@ -76,24 +75,24 @@ func (cmd *DNS) configureMacRoutes(machine Machine) {
7675
if machine.IsXhyve() {
7776
cmd.removeHostFilter(machineIP)
7877
}
79-
exec.Command("sudo", "route", "-n", "delete", "-net", "172.17.0.0").Run()
80-
util.StreamCommand(exec.Command("sudo", "route", "-n", "add", "172.17.0.0/16", machineIP))
78+
util.Command("sudo", "route", "-n", "delete", "-net", "172.17.0.0").Run()
79+
util.StreamCommand("sudo", "route", "-n", "add", "172.17.0.0/16", machineIP)
8180
if _, err := os.Stat("/usr/sbin/discoveryutil"); err == nil {
8281
// Put this here for people running OS X 10.10.0 to 10.10.3 (oy vey.)
8382
cmd.out.Verbose.Println("Restarting discoveryutil to flush DNS caches")
84-
util.StreamCommand(exec.Command("sudo", "launchctl", "unload", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist"))
85-
util.StreamCommand(exec.Command("sudo", "launchctl", "load", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist"))
83+
util.StreamCommand("sudo", "launchctl", "unload", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist")
84+
util.StreamCommand("sudo", "launchctl", "load", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist")
8685
} else {
8786
// Reset DNS cache. We have seen this suddenly make /etc/resolver/vm work.
8887
cmd.out.Verbose.Println("Restarting mDNSResponder to flush DNS caches")
89-
util.StreamCommand(exec.Command("sudo", "killall", "-HUP", "mDNSResponder"))
88+
util.StreamCommand("sudo", "killall", "-HUP", "mDNSResponder")
9089
}
9190
}
9291

9392
// removeHostFilter removes the host filter from the xhyve bridge interface
9493
func (cmd *DNS) removeHostFilter(ipAddr string) {
9594
// #1: route -n get <machineIP> to find the interface name
96-
routeData, err := exec.Command("route", "-n", "get", ipAddr).CombinedOutput()
95+
routeData, err := util.Command("route", "-n", "get", ipAddr).CombinedOutput()
9796
if err != nil {
9897
cmd.out.Warning.Println("Unable to determine bridge interface to remove hostfilter")
9998
return
@@ -102,7 +101,7 @@ func (cmd *DNS) removeHostFilter(ipAddr string) {
102101
iface := ifaceRegexp.FindStringSubmatch(string(routeData))[1]
103102

104103
// #2: ifconfig <interface name> to get the details
105-
ifaceData, err := exec.Command("ifconfig", iface).CombinedOutput()
104+
ifaceData, err := util.Command("ifconfig", iface).CombinedOutput()
106105
if err != nil {
107106
cmd.out.Warning.Println("Unable to determine member to remove hostfilter")
108107
return
@@ -111,13 +110,13 @@ func (cmd *DNS) removeHostFilter(ipAddr string) {
111110
member := memberRegexp.FindStringSubmatch(string(ifaceData))[1]
112111

113112
// #4: ifconfig <bridge> -hostfilter <member>
114-
util.StreamCommand(exec.Command("sudo", "ifconfig", iface, "-hostfilter", member))
113+
util.StreamCommand("sudo", "ifconfig", iface, "-hostfilter", member)
115114
}
116115

117116
// ConfigureWindowsRoutes configures network routing
118117
func (cmd *DNS) configureWindowsRoutes(machine Machine) {
119-
exec.Command("runas", "/noprofile", "/user:Administrator", "route", "DELETE", "172.17.0.0").Run()
120-
util.StreamCommand(exec.Command("runas", "/noprofile", "/user:Administrator", "route", "-p", "ADD", "172.17.0.0/16", machine.GetIP()))
118+
util.Command("runas", "/noprofile", "/user:Administrator", "route", "DELETE", "172.17.0.0").Run()
119+
util.StreamCommand("runas", "/noprofile", "/user:Administrator", "route", "-p", "ADD", "172.17.0.0/16", machine.GetIP())
121120
}
122121

123122
// StartDNS will start the dnsdock service
@@ -153,8 +152,8 @@ func (cmd *DNS) StartDNS(machine Machine, nameservers string) error {
153152
for _, server := range dnsServers {
154153
args = append(args, "--nameserver="+server)
155154
}
156-
util.StreamCommand(exec.Command("docker", args...))
157155

156+
util.ForceStreamCommand("docker", args...)
158157
// Configure the resolvers based on platform
159158
var resolverReturn error
160159
if util.IsMac() {
@@ -174,21 +173,21 @@ func (cmd *DNS) configureMacResolver(machine Machine) error {
174173
cmd.out.Verbose.Print("Configuring DNS resolution for macOS")
175174
bridgeIP := machine.GetBridgeIP()
176175

177-
if err := exec.Command("sudo", "mkdir", "-p", "/etc/resolver").Run(); err != nil {
176+
if err := util.Command("sudo", "mkdir", "-p", "/etc/resolver").Run(); err != nil {
178177
return err
179178
}
180-
if err := exec.Command("bash", "-c", fmt.Sprintf("echo 'nameserver %s' | sudo tee /etc/resolver/vm", bridgeIP)).Run(); err != nil {
179+
if err := util.Command("bash", "-c", fmt.Sprintf("echo 'nameserver %s' | sudo tee /etc/resolver/vm", bridgeIP)).Run(); err != nil {
181180
return err
182181
}
183182
if _, err := os.Stat("/usr/sbin/discoveryutil"); err == nil {
184183
// Put this here for people running OS X 10.10.0 to 10.10.3 (oy vey.)
185184
cmd.out.Verbose.Println("Restarting discoveryutil to flush DNS caches")
186-
util.StreamCommand(exec.Command("sudo", "launchctl", "unload", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist"))
187-
util.StreamCommand(exec.Command("sudo", "launchctl", "load", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist"))
185+
util.StreamCommand("sudo", "launchctl", "unload", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist")
186+
util.StreamCommand("sudo", "launchctl", "load", "-w", "/System/Library/LaunchDaemons/com.apple.discoveryd.plist")
188187
} else {
189188
// Reset DNS cache. We have seen this suddenly make /etc/resolver/vm work.
190189
cmd.out.Verbose.Println("Restarting mDNSResponder to flush DNS caches")
191-
util.StreamCommand(exec.Command("sudo", "killall", "-HUP", "mDNSResponder"))
190+
util.StreamCommand("sudo", "killall", "-HUP", "mDNSResponder")
192191
}
193192
return nil
194193
}
@@ -204,18 +203,18 @@ func (cmd *DNS) configureLinuxResolver() error {
204203
// Is NetworkManager in use
205204
if _, err := os.Stat("/etc/NetworkManager/dnsmasq.d"); err == nil {
206205
// Install for NetworkManager/dnsmasq connection to dnsdock
207-
util.StreamCommand(exec.Command("bash", "-c", fmt.Sprintf("echo 'server=/vm/%s' | sudo tee /etc/NetworkManager/dnsmasq.d/dnsdock.conf", bridgeIP)))
206+
util.StreamCommand("bash", "-c", fmt.Sprintf("echo 'server=/vm/%s' | sudo tee /etc/NetworkManager/dnsmasq.d/dnsdock.conf", bridgeIP))
208207

209208
// Restart NetworkManager if it is running
210-
if err := exec.Command("systemctl", "is-active", "NetworkManager").Run(); err != nil {
211-
util.StreamCommand(exec.Command("sudo", "systemctl", "restart", "NetworkManager"))
209+
if err := util.Command("systemctl", "is-active", "NetworkManager").Run(); err != nil {
210+
util.StreamCommand("sudo", "systemctl", "restart", "NetworkManager")
212211
}
213212
}
214213

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

221220
return nil
@@ -230,6 +229,6 @@ func (cmd *DNS) configureWindowsResolver(machine Machine) error {
230229

231230
// StopDNS stops the dnsdock service and cleans up
232231
func (cmd *DNS) StopDNS() {
233-
exec.Command("docker", "stop", "dnsdock").Run()
234-
exec.Command("docker", "rm", "dnsdock").Run()
232+
util.Command("docker", "stop", "dnsdock").Run()
233+
util.Command("docker", "rm", "dnsdock").Run()
235234
}

0 commit comments

Comments
 (0)