Skip to content

Commit

Permalink
Merge pull request #131 from phase2/develop
Browse files Browse the repository at this point in the history
2.1.0
  • Loading branch information
febbraro authored Jan 8, 2018
2 parents 9794851 + 7f4c4be commit b1a93f6
Show file tree
Hide file tree
Showing 31 changed files with 621 additions and 337 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dist
build
vendor
vendor.orig
.idea
.outrigger.yml
.DS_Store
Expand Down
45 changes: 45 additions & 0 deletions .goreleaser.rc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# One release file to rule them all
project_name: outrigger-cli

# Platforms/architectures to target
builds:
- binary: rig
main: ./cmd/main.go
env:
- CGO_ENABLED=0
goos:
- windows
- darwin
- linux
goarch:
- amd64

# Generating the archives
archive:
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
format: tar.gz
format_overrides:
- goos: windows
format: zip
replacements:
darwin: macOS

# Publishing releases to GitHub
release:
github:
owner: phase2
name: rig
prerelease: true

# Build linux packages
fpm:
vendor: Phase2
homepage: https://outrigger.sh/
maintainer: Outrigger <[email protected]>
description: Containerized development environment for projects. See https://docs.outrigger.sh for documentation.
license: MIT
formats:
- deb
- rpm
dependencies:
- docker-ce
126 changes: 126 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# CONTRIBUTING

Thank you for considering contributing to the Outrigger CLI!

## Quality Contributions

* Make sure your branch will compile.
* Make sure your branch passes our static analysis checks.
* Make sure your branch conforms with go fmt standards.
* Manually test your changes.

## User Interactions

One of the key goals of this project is to promote a positive developer
experience. Every interaction should be thought of with the following points:

* Are you providing the user with enough context about what's being asked or being done?
* Does the user expect to wait? Might the user think the tool stalled?
* Is there black box business happening that could be made more transparent?

We have a slightly complex logging API to support addressing these concerns.
(See ./util/logging.go)

Here are a few conventions:

* **Starting a task that could take more than 5 seconds:**
* `cmd.out.Spin("Preparing the sauce")`
* **Use the correct method to log operational results: (Pick one)**
* `cmd.out.Info("Sauce is Ready.")`
* `cmd.out.Warning("Sauce is burnt on the bottom.")`
* `cmd.out.Error("Discard this sauce and try again.")`
* **Going to send some contextual notes to the user**:
1. `cmd.out.NoSpin()` if currently using the spinner.
2. `cmd.out.Info("Sauce exists.")`
4. `cmd.out.Verbose("The ingredients of the sauce include tomato, salt, black pepper, garlic...")`
* **Command has executed and is successful. Please no notification:**
```
cmd.out.Info("Enjoy your dinner.")
return cmd.Success("")
```
* **Command has executed and is successful. Get a notification too!**
```
return cmd.Success("Enjoy your dinner.")
```
* **Command failed:**
```
message := "Cooking sauce is hard, we failed"
cmd.out.Error("%s: %s", message, err.Error())
return cmd.Failure(message)
```

## Development Environment Setup

### Developing with Docker

You can use the Docker integration within this repository to facilitate development in lieu of setting up a
local golang environment. Using docker-compose, run the following commands:

```bash
docker-compose run --rm install
docker-compose run --rm compile
```

This will produce a working OSX binary at `build/darwin/rig`.

If you change a dependency in `Gopkg.toml` you can update an individual package dependency with:

```bash
docker-compose run --rm update [package]
```

If you want to update all packages use:

```bash
docker-compose run --rm update
```

If you want to run the static analysis checks:

```bash
docker-compose run --rm lint
```

If you want to run go fmt against the codebase:
```bash
docker-compose run --rm base go fmt ./...
```

### Developing Locally

Install go from homebrew using the flag to include common cross-compiler targets (namely Darwin, Linux, and Windows)

```bash
brew install go --with-cc-common
brew install dep
brew tap goreleaser/tap
brew install goreleaser/tap/goreleaser
```

Setup `$GOPATH` and `$PATH` in your favorite shell (`~/.bashrc` or `~/.zshrc`)

```bash
export GOPATH=$HOME/Projects
export PATH=$PATH:$GOPATH/bin
```

Checkout the code into your `$GOPATH` in `$GOPATH/src/github.com/phase2/rig`

Get all the dependencies

```bash
# Install the project dependencies into $GOPATH
cd $GOPATH/src/github.com/phase2/rig
dep ensure
```

#### Building Rig

If you want to build `rig` locally for your target platform, simply run the following command:

```bash
GOARCH=amd64 GOOS=darwin go build -o build/darwin/rig cmd/main.go
```

This command targets an OS/Architecture (Darwin/Mac and 64bit) and puts the resultant file in the `build/darwin/`
with the name `rig`. Change `GOARCH` and `GOOS` if you need to target a different platform
7 changes: 7 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@
name = "github.com/martinlindhe/notify"
branch = "master"

[[constraint]]
name = "github.com/slok/gospinner"
version = "0.1.0"

119 changes: 32 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,52 @@
# Rig - Outrigger CLI [![Build Status](https://travis-ci.org/phase2/rig.svg?branch=develop)](https://travis-ci.org/phase2/rig)

> A CLI for managing the Outrigger container-driven development stack.
> A CLI for managing the Outrigger's container-driven development stack.
See the [documentation for more details](http://docs.outrigger.sh).
See the [CONTRIBUTING.md](./CONTRIBUTING.md) for developer documentation.

Use this readme when you want to develop the Outrigger CLI.
## Built on Dependencies

Setup
------

Install go from homebrew using the flag to include common cross-compiler targets (namely Darwin, Linux, and Windows)

```bash
brew install go --with-cc-common
brew install dep
brew tap goreleaser/tap
brew install goreleaser/tap/goreleaser
```

Setup `$GOPATH` and `$PATH` in your favorite shell (`~/.bashrc` or `~/.zshrc`)

```bash
export GOPATH=$HOME/Projects
export PATH=$PATH:$GOPATH/bin
```

Checkout the code into your `$GOPATH` in `$GOPATH/src/github.com/phase2/rig`

Get all the dependencies

```bash
# Install the project dependencies into $GOPATH
cd $GOPATH/src/github.com/phase2/rig
dep ensure
```

Developing Locally
-------------------

If you want to build `rig` locally for your target platform, simply run the following command:

```bash
GOARCH=amd64 GOOS=darwin go build -o build/darwin/rig cmd/main.go
```

This command targets an OS/Architecture (Darwin/Mac and 64bit) and puts the resultant file in the `build/darwin/`
with the name `rig`. Change `GOARCH` and `GOOS` if you need to target a different platform

Developing with Docker
-----------------------

You can use the Docker integration within this repository to facilitate development in lieu of setting up a
local golang environment. Using docker-compose, run the following commands:

```bash
docker-compose run --rm install
docker-compose run --rm compile
```

This will produce a working OSX binary at `build/darwin/rig`.

If you change a dependency in `Gopkg.toml` you can update an individual package dependency with:

```bash
docker-compose run --rm update [package]
```

If you want to update all packages use:

```bash
docker-compose run --rm update
```
We make use of a few key libraries to do all the fancy stuff that the `rig` CLI will do.

* https://github.com/urfave/cli
* The entire CLI framework from helps text to flags.
This was an easy cli to build b/c of this library.
* https://github.com/fatih/color
* All the fancy terminal color output
* https://github.com/bitly/go-simplejson
* The JSON parse and access library used primarily with the output
of `docker-machine inspect`
* https://gopkg.in/yaml.v2
* The YAML library for parsing/reading YAML files
* https://github.com/martinlindhe/notify
* Cross-platform desktop notifications

Release
-------
## Release Instructions

We use [GoReleaser](https://goreleaser.com) to handle nearly all of our release concerns. GoReleaser will handle

* Building for all target platforms
* Create a GitHub release on our project page based on tag
* Create archive file for each target platform and attach it to the GitHub release
* Update the Homebrew formula and publish it
* Create .deb and .rpm packages for linux installations
* Creating a GitHub release on our project page based on tag
* Creating archive files for each target platform and attach it to the GitHub release
* Creating .deb and .rpm packages for linux installations and attaching those to the GitHub release
* Updating the Homebrew formula and publish it

### To create a new release of rig:

To create a new release of rig:
* Get all the code committed to `master`
* Tag master with the new version number
* Tag master with the new version number `git tag 2.1.0 && git push --tags`
* Run `docker-compose run --rm goreleaser`
* ...
* Profit!

### To create a new release candidate (RC) of rig:

Dependencies
-------------
If we want to roll out an RC to GitHub for folks to test, we simply need to run with a different GoReleaser
configuration that does not publish to homebrew, just to a GitHub release that is marked preproduction.

We make use of a few key libraries to do all the fancy stuff that the `rig` CLI will do.

* https://github.com/urfave/cli
* The entire CLI framework from helps text to flags. This was an easy cli to build b/c of this library
* https://github.com/fatih/color
* All the fancy terminal color output
* https://github.com/bitly/go-simplejson
* The JSON parse and access library used primarily with the output of `docker-machine inspect`
* https://gopkg.in/yaml.v2
* The YAML library for parsing/reading YAML files
* Get all the code committed to `develop`
* Tag develop with the new version number `git tag 2.1.0-rc1 && git push --tags`
* Run `docker-compose run --rm goreleaser --config .goreleaser.rc.yml`
* ...
* Profit!
18 changes: 14 additions & 4 deletions commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,26 @@ func (cmd *BaseCommand) Before(c *cli.Context) error {

// Success encapsulates the functionality for reporting command success
func (cmd *BaseCommand) Success(message string) error {
// Handle success messaging.
if message != "" {
cmd.out.Info.Println(message)
cmd.out.Info(message)
util.NotifySuccess(cmd.context, message)
}

// If there is an active spinner wrap it up. This is not placed before the logging above so commands can rely on
// cmd.Success to set the last spinner status in lieu of an extraneous log entry.
cmd.out.NoSpin()

return nil
}

// Error encapsulates the functionality for reporting command failure
func (cmd *BaseCommand) Error(message string, errorName string, exitCode int) error {
// Failure encapsulates the functionality for reporting command failure
func (cmd *BaseCommand) Failure(message string, errorName string, exitCode int) error {
// Make sure any running spinner halts.
cmd.out.NoSpin()
// Handle error messaging.
util.NotifyError(cmd.context, message)

return cli.NewExitError(fmt.Sprintf("ERROR: %s [%s] (%d)", message, errorName, exitCode), exitCode)
}

Expand All @@ -64,6 +74,6 @@ func (cmd *BaseCommand) NewContext(name string, flags []cli.Flag, parent *cli.Co
// SetContextFlag set a flag on the provided context
func (cmd *BaseCommand) SetContextFlag(ctx *cli.Context, name string, value string) {
if err := ctx.Set(name, value); err != nil {
cmd.out.Error.Fatal(err)
cmd.out.Channel.Error.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (cmd *Config) Run(c *cli.Context) error {
os.Stdout.Write(output)
}
} else {
return cmd.Error(fmt.Sprintf("No machine named '%s' exists.", cmd.machine.Name), "MACHINE-NOT-FOUND", 12)
return cmd.Failure(fmt.Sprintf("No machine named '%s' exists.", cmd.machine.Name), "MACHINE-NOT-FOUND", 12)
}

return cmd.Success("")
Expand Down
Loading

0 comments on commit b1a93f6

Please sign in to comment.