Skip to content

Commit fd8c63f

Browse files
authored
Merge pull request #15 from phase2/develop
Release 1.2.0
2 parents cc38caa + 7a27b05 commit fd8c63f

36 files changed

+784
-589
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 1.2.0
4+
5+
- Added Docker-based development support
6+
- Trimmed output and added a global verbose flag to get it all back
7+
- Refactored the entire codebase for better design
8+
- Deprecated code cleanup
9+
310
## 1.1.0
411

512
- Renamed from `devtools` to `rig`.

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:1.7-alpine
2+
3+
RUN apk add --no-cache \
4+
ca-certificates \
5+
git \
6+
gcc \
7+
musl-dev \
8+
&& go get github.com/tools/godep \
9+
&& go get github.com/mitchellh/gox

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Rig - Outrigger CLI
22

3+
> A CLI for managing the Outrigger container-driven development stack.
4+
5+
See the [documentation for more details](http://docs.outrigger.sh).
6+
37
Use this readme when you want to develop the Outrigger CLI.
48

59
Setup
@@ -68,6 +72,19 @@ NOTE: the `-cgo` in the above command is only relevant for building on OSX as th
6872
to use the OSX DNS Resolver instead of the built in Go resolver. This is needed in order to resolve DNS names
6973
that end in things like *.vm* Using `-cgo` for Linux and Windows architectures will result in a failed build.
7074

75+
Developing Rig with Docker [Experimental]
76+
-----------------------------------------
77+
78+
You can use the Docker integration within this repository to facilitate development in lieu of setting up a
79+
local golang environment. Using docker-compose, run the following commands:
80+
81+
```bash
82+
docker-compose run --rm install
83+
docker-compose run --rm build
84+
```
85+
86+
This will produce a working OSX binary with partially limited functionality at `build/darwin/rig`.
87+
7188
Deploy to Homebrew
7289
------------------
7390

@@ -81,8 +98,3 @@ perform the following operations.
8198
- Prepare a new `brew` version via `brew-publish.sh`
8299
- Part of this will write a new formula into homebrew-outrigger
83100
- Commit & push the updated formula to publish the new version
84-
85-
86-
87-
88-

build.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
go get github.com/tools/godep
66
go get github.com/mitchellh/gox
77

8+
pushd cli
9+
810
godep restore
911

1012
# Build for platforms
11-
gox -cgo -osarch="Darwin/amd64" -output="build/darwin/rig"
12-
gox -osarch="Linux/amd64" -output="build/linux/rig"
13-
gox -osarch="Windows/amd64" -output="build/windows/rig"
13+
gox -osarch="Darwin/amd64" -output="../build/darwin/rig"
14+
gox -osarch="Linux/amd64" -output="../build/linux/rig"
15+
gox -osarch="Windows/amd64" -output="../build/windows/rig"
1416

15-
# Bundle for GitHub
17+
popd
1618

1719
# Get version
1820
VERSION=`build/darwin/rig --version 2>&1 | grep 'rig version' | awk '{print $3}'`
1921

20-
# Create archives for publishing to github
22+
# Create archives for publishing to GitHub
2123
cp scripts/docker-machine-watch-rsync.sh build/darwin/.
2224
pushd build/darwin
2325
tar czf ../rig-${VERSION}-darwin-amd64.tar.gz rig docker-machine-watch-rsync.sh
File renamed without changes.
File renamed without changes.

cli/commands/command.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package commands
2+
3+
import (
4+
"flag"
5+
"github.com/phase2/rig/cli/util"
6+
"github.com/urfave/cli"
7+
)
8+
9+
type RigCommand interface {
10+
Commands() cli.Command
11+
}
12+
13+
type BaseCommand struct {
14+
RigCommand
15+
out *util.RigLogger
16+
machine Machine
17+
}
18+
19+
// Run before all commands to setup core services
20+
func (cmd *BaseCommand) Before(c *cli.Context) error {
21+
cmd.out = util.Logger()
22+
cmd.machine = Machine{Name: c.GlobalString("name"), out: util.Logger()}
23+
return nil
24+
}
25+
26+
func (cmd *BaseCommand) NewContext(name string, flags []cli.Flag, parent *cli.Context) *cli.Context {
27+
flagSet := flag.NewFlagSet(name, flag.ContinueOnError)
28+
for _, f := range flags {
29+
f.Apply(flagSet)
30+
}
31+
return cli.NewContext(parent.App, flagSet, parent)
32+
}
33+
34+
func (cmd *BaseCommand) SetContextFlag(ctx *cli.Context, name string, value string) {
35+
if err := ctx.Set(name, value); err != nil {
36+
cmd.out.Error.Fatal(err)
37+
}
38+
}

config.go renamed to cli/commands/config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package commands
22

33
import (
44
"fmt"
@@ -7,15 +7,19 @@ import (
77
"runtime"
88
"strings"
99

10+
"github.com/phase2/rig/cli/util"
1011
"github.com/urfave/cli"
1112
)
1213

13-
type Config struct{}
14+
type Config struct {
15+
BaseCommand
16+
}
1417

1518
func (cmd *Config) Commands() cli.Command {
1619
return cli.Command{
1720
Name: "config",
1821
Usage: "Echo the config to setup the Rig environment. Run: eval \"$(rig config)\"",
22+
Before: cmd.Before,
1923
Action: cmd.Run,
2024
}
2125
}
@@ -25,7 +29,7 @@ func (cmd *Config) Run(c *cli.Context) error {
2529
if runtime.GOOS != "darwin" {
2630
// Add stuff to PATH only once
2731
path := os.Getenv("PATH")
28-
dir, _ := GetExecutableDir()
32+
dir, _ := util.GetExecutableDir()
2933
if !strings.Contains(path, dir) {
3034
fmt.Printf("export PATH=%s%c$PATH\n", dir, os.PathListSeparator)
3135
}
@@ -36,13 +40,13 @@ func (cmd *Config) Run(c *cli.Context) error {
3640
os.Stdout.Write(output)
3741
}
3842

39-
if machine.Exists() {
43+
if cmd.machine.Exists() {
4044
// Setup new values if machine is running
41-
if output, err := exec.Command("docker-machine", "env", machine.Name).Output(); err == nil {
45+
if output, err := exec.Command("docker-machine", "env", cmd.machine.Name).Output(); err == nil {
4246
os.Stdout.Write(output)
4347
}
4448
} else {
45-
out.Error.Fatalf("No machine named '%s' exists.", machine.Name)
49+
cmd.out.Error.Fatalf("No machine named '%s' exists.", cmd.machine.Name)
4650
}
4751

4852
return nil
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
1-
package main
1+
package commands
22

33
import (
44
"fmt"
55
"os"
66
"os/exec"
77
"runtime"
88

9+
"github.com/phase2/rig/cli/util"
910
"github.com/urfave/cli"
1011
)
1112

12-
type Dashboard struct{}
13+
type Dashboard struct {
14+
BaseCommand
15+
}
1316

1417
func (cmd *Dashboard) Commands() cli.Command {
1518
return cli.Command{
1619
Name: "dashboard",
1720
Usage: "Start Dashboard services on the docker-machine",
21+
Before: cmd.Before,
1822
Action: cmd.Run,
1923
}
2024
}
2125

2226
func (cmd *Dashboard) Run(c *cli.Context) error {
23-
if machine.IsRunning() {
24-
out.Info.Println("Launching Dashboard")
25-
cmd.LaunchDashboard(machine)
27+
if cmd.machine.IsRunning() {
28+
cmd.out.Info.Println("Launching Dashboard")
29+
cmd.LaunchDashboard(cmd.machine)
2630
} else {
27-
out.Error.Fatalf("Machine '%s' is not running.", machine.Name)
31+
cmd.out.Error.Fatalf("Machine '%s' is not running.", cmd.machine.Name)
2832
}
2933

3034
return nil
3135
}
3236

33-
func (cmd Dashboard) LaunchDashboard(machine Machine) {
37+
func (cmd *Dashboard) LaunchDashboard(machine Machine) {
3438
machine.SetEnv()
3539

3640
home := os.Getenv("HOME")
3741

38-
StreamCommand(exec.Command("docker", "stop", "outrigger-dashboard"))
39-
StreamCommand(exec.Command("docker", "rm", "outrigger-dashboard"))
42+
exec.Command("docker", "stop", "outrigger-dashboard").Run()
43+
exec.Command("docker", "rm", "outrigger-dashboard").Run()
4044

41-
dockerApiVersion, _ := GetDockerServerApiVersion()
45+
dockerApiVersion, _ := util.GetDockerServerApiVersion(cmd.machine.Name)
4246

4347
args := []string{
4448
"run",
@@ -53,13 +57,13 @@ func (cmd Dashboard) LaunchDashboard(machine Machine) {
5357
"outrigger/dashboard:latest",
5458
}
5559

56-
StreamCommand(exec.Command("docker", args...))
60+
util.ForceStreamCommand(exec.Command("docker", args...))
5761

5862
if runtime.GOOS == "darwin" {
59-
StreamCommand(exec.Command("open", "http://dashboard.outrigger.vm"))
63+
exec.Command("open", "http://dashboard.outrigger.vm").Run()
6064
} else if runtime.GOOS == "windows" {
61-
StreamCommand(exec.Command("start", "http://dashboard.outrigger.vm"))
65+
exec.Command("start", "http://dashboard.outrigger.vm").Run()
6266
} else {
63-
out.Info.Println("Outrigger Dashboard is now available at http://dashboard.outrigger.vm")
67+
cmd.out.Info.Println("Outrigger Dashboard is now available at http://dashboard.outrigger.vm")
6468
}
6569
}

data_backup.go renamed to cli/commands/data_backup.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package commands
22

33
import (
44
"fmt"
@@ -9,7 +9,9 @@ import (
99
"github.com/urfave/cli"
1010
)
1111

12-
type DataBackup struct{}
12+
type DataBackup struct {
13+
BaseCommand
14+
}
1315

1416
func (cmd *DataBackup) Commands() cli.Command {
1517
return cli.Command{
@@ -27,43 +29,44 @@ func (cmd *DataBackup) Commands() cli.Command {
2729
Usage: "Specify the local directory to store the backup zip.",
2830
},
2931
},
32+
Before: cmd.Before,
3033
Action: cmd.Run,
3134
}
3235
}
3336

3437
func (cmd *DataBackup) Run(c *cli.Context) error {
35-
if !machine.Exists() {
36-
out.Error.Fatalf("No machine named '%s' exists.", machine.Name)
38+
if !cmd.machine.Exists() {
39+
cmd.out.Error.Fatalf("No machine named '%s' exists.", cmd.machine.Name)
3740
}
3841

3942
dataDir := c.String("data-dir")
4043
backupDir := c.String("backup-dir")
41-
backupFile := fmt.Sprintf("%s%c%s.tgz", backupDir, os.PathSeparator, machine.Name)
44+
backupFile := fmt.Sprintf("%s%c%s.tgz", backupDir, os.PathSeparator, cmd.machine.Name)
4245
if _, err := os.Stat(backupDir); err != nil {
43-
out.Info.Printf("Creating backup directory: %s...", backupDir)
46+
cmd.out.Info.Printf("Creating backup directory: %s...", backupDir)
4447
if mkdirErr := exec.Command("mkdir", "-p", backupDir).Run(); mkdirErr != nil {
45-
out.Error.Println(mkdirErr)
46-
out.Error.Fatalf("Could not create backup directory %s", backupDir)
48+
cmd.out.Error.Println(mkdirErr)
49+
cmd.out.Error.Fatalf("Could not create backup directory %s", backupDir)
4750
}
4851
} else if _, err := os.Stat(backupFile); err == nil {
4952
// If the backup dir already exists, make sure the backup file does not exist.
50-
out.Error.Fatalf("Backup archive %s already exists.", backupFile)
53+
cmd.out.Error.Fatalf("Backup archive %s already exists.", backupFile)
5154
}
5255

53-
out.Info.Printf("Backing up %s on '%s' to %s...", dataDir, machine.Name, backupFile)
56+
cmd.out.Info.Printf("Backing up %s on '%s' to %s...", dataDir, cmd.machine.Name, backupFile)
5457

5558
// Stream the archive to stdout and capture it in a local file so we don't waste
5659
// space storing an archive on the VM filesystem. There may not be enough space.
5760
archiveCmd := fmt.Sprintf("sudo tar czf - -C %s .", dataDir)
58-
backup := exec.Command("docker-machine", "ssh", machine.Name, archiveCmd, ">", backupFile)
61+
backup := exec.Command("docker-machine", "ssh", cmd.machine.Name, archiveCmd, ">", backupFile)
5962
backup.Stderr = os.Stderr
6063

6164
color.Set(color.FgCyan)
6265
err := backup.Run()
6366
color.Unset()
6467

6568
if err != nil {
66-
out.Warning.Println("There may have been problems. See above for any errors")
69+
cmd.out.Warning.Println("There may have been problems. See above for any errors")
6770
}
6871

6972
return nil

0 commit comments

Comments
 (0)