diff --git a/.travis.yml b/.travis.yml index efb2310..79dff23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: linux language: go go: - - 1.7 + - 1.9 - tip matrix: @@ -12,9 +12,6 @@ matrix: allow_failures: - go: tip -env: - - GO15VENDOREXPERIMENT="0" - before_install: cd cli script: diff --git a/Dockerfile b/Dockerfile index c6a4b61..720954c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,17 @@ -FROM golang:1.7-alpine +FROM golang:1.9-alpine RUN apk add --no-cache \ ca-certificates \ git \ gcc \ + libffi-dev \ + make \ musl-dev \ - && go get github.com/tools/godep \ - && go get github.com/mitchellh/gox + rpm \ + ruby \ + ruby-dev \ + tar \ + && go get -u github.com/golang/dep/... \ + && go get -u github.com/goreleaser/goreleaser + +RUN gem install --no-rdoc --no-ri fpm \ No newline at end of file diff --git a/README.md b/README.md index 8f45ef1..8a6d04b 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,15 @@ See the [documentation for more details](http://docs.outrigger.sh). Use this readme when you want to develop the Outrigger CLI. 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`) @@ -27,71 +30,78 @@ Checkout the code into your `$GOPATH` in `$GOPATH/src/github.com/phase2/rig` Get all the dependencies ```bash -# Go Dependency Manager -go get github.com/tools/godep - -# Go Cross Platform Build Tool -go get github.com/mitchellh/gox - # Install the project dependencies into $GOPATH cd $GOPATH/src/github.com/phase2/rig/cli -godep restore +dep ensure ``` -Code ----- +Developing Locally +------------------- -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 - -Build ------ - -If you want to build `rig` for all platforms, simply execute the `build.sh` script from the root -directory. This script will build the binary for Darwin, Linux and Windows and put it in the appropriate - `dist/[PLATFORM]` directory for each operating system. - -For development, sometimes you will just want to build for your target platform because it is faster. TO -do that, simply run the following command. +If you want to build `rig` locally for your target platform, simply run the following command: ```bash -gox -osarch="Darwin/amd64" -output="build/{{.OS}}/rig" +GOARCH=amd64 GOOS=darwin go build -o ../build/darwin/rig ``` -This command targets an OS/Architecture (Darwin/Mac and 64bit) and puts the resultant file in the `bin/` -directory for the appropriate OS with the name `rig`. +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 Rig with Docker [Experimental] ------------------------------------------ +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 build +docker-compose run --rm compile ``` This will produce a working OSX binary at `build/darwin/rig`. -Deploy to Homebrew ------------------- +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: -We now manage the Mac / OSX version of the binaries via `brew`. To publish a new build to `brew` you must -perform the following operations. +```bash +docker-compose run --rm update +``` + + +Release +------- + +We use [GoReleaser](https://goreleaser.com) to handle nearly all of our release concerns. GoReleaser will handle - - Change the code :) - - When changing the code make sure to update the VERSION variable in main.go - - Build all the code via `build.sh` - - Make sure you have https://github.com/phase2/homebrew-outrigger cloned into ~/Projects/homebrew-outrigger - - Prepare a new `brew` version via `brew-publish.sh` - - Part of this will write a new formula into homebrew-outrigger - - Commit & push the updated formula to publish the new version +* 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 + +To create a new release of rig: +* Get all the code committed to `master` +* Tag master with the new version number +* Run `docker-compose run --rm goreleaser` +* ... +* Profit! + + +Dependencies +------------- + +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 diff --git a/brew-publish.sh b/brew-publish.sh deleted file mode 100755 index c758613..0000000 --- a/brew-publish.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bash -# -# Publish a release of Rig. -# -# This entails -# 1) Creating an archive of the correct files -# 2) Getting a checksum of the archive -# 3) Publishing the archive to S3 -# 4) Generating a Homebrew formula for the release -# -# Once completed, the only thing that remains is committing/pushing the -# changes in the homebrew-outrigger repo. -# - -BASE_DIR=${PWD} -BIN_DIR="${BASE_DIR}/build/darwin" -VERSION=`${BIN_DIR}/rig --version | awk '{print $3}'` - -FILENAME="rig-${VERSION}.tar.gz" -DIST_DIR="${BASE_DIR}/dist" -DIST="${DIST_DIR}/${FILENAME}" -S3_BUCKET="phase2.outrigger" - -HOMEBREW_DIR="${HOME}/Projects/homebrew-outrigger" -HOMEBREW_FORMULA="${HOMEBREW_DIR}/Formula/rig.rb" - -# Make sure the Homebrew Tap is present -if [ ! -f "$HOMEBREW_FORMULA" ]; then - echo "[ERROR] Could not find Rig Homebrew formula in: ${HOMEBREW_FORMULA}" - exit 1 -fi - -# Package rig and any additional scripts -echo "[INFO] Packaging rig ${VERSION} for publishing" -mkdir -p $DIST_DIR -cp ${BASE_DIR}/scripts/docker-machine-watch-rsync.sh $BIN_DIR/. -#cp ${BASE_DIR}/scripts/bash_autocomplete $BIN_DIR/. -#cp ${BASE_DIR}/scripts/zsh_autocomplete $BIN_DIR/. -pushd $BIN_DIR -#tar czf $DIST rig docker-machine-watch-rsync.sh bash_autocomplete zsh_autocomplete -tar czf $DIST rig docker-machine-watch-rsync.sh -popd - -# Generate the checksum -SHA=`shasum -a 256 $DIST | awk '{print $1}'` -echo "[INFO] Rig ${VERSION} checksum is ${SHA}" - -# Move the file to S3 for distribution -echo "[INFO] Deploying ${VERSION}" -aws s3 ls $S3_BUCKET | grep "${FILENAME}" && { - read -p "[WARN] Version ${VERSION} is already published to S3. Overwrite? " prompt - if [[ ! $prompt =~ [yY](es)* ]]; then - echo "Publish cancelled." - exit 1 - fi -} - -echo "[INFO] Writing to AWS/S3" -aws s3 cp $DIST s3://${S3_BUCKET}/${FILENAME} --acl public-read - -# Write out the Homebrew formula -echo "[INFO] Writing Homebrew formula" -cat < $HOMEBREW_FORMULA -class Rig < Formula - desc "Containerized platform environment for projects. See https://outrigger.sh for documentation. " - homepage "https://outrigger.sh" - url "https://s3.amazonaws.com/${S3_BUCKET}/${FILENAME}" - version "${VERSION}" - sha256 "${SHA}" - - depends_on "docker" - depends_on "docker-machine" - depends_on "docker-compose" - depends_on "docker-machine-nfs" - depends_on "unison" - depends_on "eugenmayer/dockersync/unox" - - def install - bin.install "rig" - bin.install "docker-machine-watch-rsync.sh" - - #bash_completion.install "bash_autocomplete" => "rig" - #zsh_completion.install "zsh_autocomplete" => "_rig" - end - - test do - system "#{bin}/rig", "--version" - end -end -EOF - -echo "[NOTICE] Remember that you need to commit the formula change to homebrew-outrigger" diff --git a/build.sh b/build.sh deleted file mode 100755 index c4871e2..0000000 --- a/build.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# To use this you will need to: go get github.com/mitchellh/gox - -go get github.com/tools/godep -go get github.com/mitchellh/gox - -pushd cli - -godep restore - -# Build for platforms -gox -osarch="Darwin/amd64" -output="../build/darwin/rig" -gox -osarch="Linux/amd64" -output="../build/linux/rig" -gox -osarch="Windows/amd64" -output="../build/windows/rig" - -popd - -# Get version -VERSION=`build/darwin/rig --version 2>&1 | grep 'rig version' | awk '{print $3}'` - -# Create archives for publishing to GitHub -cp scripts/docker-machine-watch-rsync.sh build/darwin/. -pushd build/darwin -tar czf ../rig-${VERSION}-darwin-amd64.tar.gz rig docker-machine-watch-rsync.sh -popd -pushd build/linux -tar czf ../rig-${VERSION}-linux-amd64.tar.gz rig -popd -pushd build/windows -zip ../rig-${VERSION}-windows-amd64.zip rig.exe -popd \ No newline at end of file diff --git a/cli/.goreleaser.yml b/cli/.goreleaser.yml new file mode 100644 index 0000000..6326038 --- /dev/null +++ b/cli/.goreleaser.yml @@ -0,0 +1,73 @@ +# One release file to rule them all + +# Platforms/architectures to target +builds: + - binary: rig + 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 + +# Publishing Homebrew Formula to the Tap repo +brew: + github: + owner: phase2 + name: homebrew-outrigger + + # Git author used to commit to the repository. + # Defaults are shown. + commit_author: + name: Outrigger + email: outrigger@phase2technology.com + + folder: Formula + homepage: "https://outrigger.sh/" + description: "Containerized development environment for projects. See https://docs.outrigger.sh for documentation." + dependencies: + - docker + - docker-machine + - docker-compose + - docker-machine-nfs + - unison + - eugenmayer/dockersync/unox + + # So you can `brew test` your formula. + # Default is empty. + test: | + system "#{bin}/rig", "--version" + + # Custom install script for brew. + # Default is 'bin.install "program"'. + install: | + bin.install "rig" + +# Build linux packages +fpm: + vendor: Phase2 + homepage: https://outrigger.sh/ + maintainer: Outrigger + description: Containerized development environment for projects. See https://docs.outrigger.sh for documentation. + license: MIT + formats: + - deb + - rpm + dependencies: + - docker-ce diff --git a/cli/Godeps/Godeps.json b/cli/Godeps/Godeps.json deleted file mode 100644 index fbc03bf..0000000 --- a/cli/Godeps/Godeps.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "ImportPath": "github.com/phase2/rig/cli", - "GoVersion": "go1.7", - "GodepVersion": "v79", - "Deps": [ - { - "ImportPath": "github.com/bitly/go-simplejson", - "Comment": "v0.5.0", - "Rev": "aabad6e819789e569bd6aabf444c935aa9ba1e44" - }, - { - "ImportPath": "github.com/fatih/color", - "Comment": "v0.1-12-g9aae6aa", - "Rev": "9aae6aaa22315390f03959adca2c4d395b02fcef" - }, - { - "ImportPath": "github.com/hashicorp/go-version", - "Rev": "03c5bf6be031b6dd45afec16b1cf94fc8938bc77" - }, - { - "ImportPath": "github.com/kardianos/osext", - "Rev": "29ae4ffbc9a6fe9fb2bc5029050ce6996ea1d3bc" - }, - { - "ImportPath": "github.com/mattn/go-colorable", - "Rev": "4af63d73f5bea08b682ad2cd198b1e607afd6be0" - }, - { - "ImportPath": "github.com/mattn/go-isatty", - "Rev": "56b76bdf51f7708750eac80fa38b952bb9f32639" - }, - { - "ImportPath": "github.com/urfave/cli", - "Comment": "v1.18.0", - "Rev": "1efa31f08b9333f1bd4882d61f9d668a70cd902e" - }, - { - "ImportPath": "golang.org/x/sys/unix", - "Rev": "eb2c74142fd19a79b3f237334c7384d5167b1b46" - }, - { - "ImportPath": "gopkg.in/yaml.v2", - "Rev": "cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b" - } - ] -} diff --git a/cli/Godeps/Readme b/cli/Godeps/Readme deleted file mode 100644 index 4cdaa53..0000000 --- a/cli/Godeps/Readme +++ /dev/null @@ -1,5 +0,0 @@ -This directory tree is generated automatically by godep. - -Please do not edit. - -See https://github.com/tools/godep for more information. diff --git a/cli/Gopkg.lock b/cli/Gopkg.lock new file mode 100644 index 0000000..6dda64e --- /dev/null +++ b/cli/Gopkg.lock @@ -0,0 +1,63 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/bitly/go-simplejson" + packages = ["."] + revision = "aabad6e819789e569bd6aabf444c935aa9ba1e44" + version = "v0.5.0" + +[[projects]] + name = "github.com/fatih/color" + packages = ["."] + revision = "570b54cabe6b8eb0bc2dfce68d964677d63b5260" + version = "v1.5.0" + +[[projects]] + branch = "master" + name = "github.com/hashicorp/go-version" + packages = ["."] + revision = "fc61389e27c71d120f87031ca8c88a3428f372dd" + +[[projects]] + branch = "master" + name = "github.com/kardianos/osext" + packages = ["."] + revision = "ae77be60afb1dcacde03767a8c37337fad28ac14" + +[[projects]] + name = "github.com/mattn/go-colorable" + packages = ["."] + revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" + version = "v0.0.9" + +[[projects]] + name = "github.com/mattn/go-isatty" + packages = ["."] + revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" + version = "v0.0.3" + +[[projects]] + name = "github.com/urfave/cli" + packages = ["."] + revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1" + version = "v1.20.0" + +[[projects]] + branch = "master" + name = "golang.org/x/sys" + packages = ["unix"] + revision = "92ac112afc6efd90284acda2b046fc0e351228f6" + +[[projects]] + branch = "v2" + name = "gopkg.in/yaml.v2" + packages = ["."] + revision = "eb3733d160e74a9c7e442f435eb3bea458e1d19f" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "9866632c6655f2b13c5a6567e87d824685c882e40fc4a1a7513bdf9d4710045a" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cli/Gopkg.toml b/cli/Gopkg.toml new file mode 100644 index 0000000..58d6728 --- /dev/null +++ b/cli/Gopkg.toml @@ -0,0 +1,50 @@ + +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" + + +[[constraint]] + name = "github.com/bitly/go-simplejson" + version = "0.5.0" + +[[constraint]] + name = "github.com/fatih/color" + version = "1.5.0" + +[[constraint]] + name = "github.com/mattn/go-isatty" + version = "0.0.3" + +[[constraint]] + name = "github.com/hashicorp/go-version" + branch = "master" + +[[constraint]] + name = "github.com/kardianos/osext" + branch = "master" + +[[constraint]] + name = "github.com/urfave/cli" + version = "1.20.0" + +[[constraint]] + name = "gopkg.in/yaml.v2" + branch = "v2" diff --git a/cli/main.go b/cli/main.go index f5ccd5d..2512a40 100644 --- a/cli/main.go +++ b/cli/main.go @@ -8,14 +8,14 @@ import ( "github.com/urfave/cli" ) -const VERSION = "1.3.2" +var version = "master" // It all starts here func main() { app := cli.NewApp() app.Name = "rig" app.Usage = "Containerized platform environment for projects" - app.Version = VERSION + app.Version = version app.EnableBashCompletion = true app.Flags = []cli.Flag{ diff --git a/docker-compose.yml b/docker-compose.yml index c04bedd..01abf85 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,15 +2,34 @@ version: '2.1' services: + # Install project dependencies. + goreleaser: + extends: base + environment: + - GOPATH=/go + - GITHUB_TOKEN + entrypoint: [ "goreleaser" ] + # Build rig, dropping off a working binary in build/darwin/rig. compile: extends: base - command: gox -osarch="Darwin/amd64" -output="../build/{{.OS}}/rig" + command: go build -o ../build/darwin/rig + environment: + - GOOS=darwin + - GOARCH=amd64 # Install project dependencies. install: extends: base - command: godep restore -v + command: dep ensure + + # Update project dependencies. + # Will update all if no arguments are provided. To update a particular package use: + # docker-compose run --rm update [PACKAGENAME] + update: + extends: base + entrypoint: [ "dep", "ensure", "-update" ] + command: "" # Foundational service to run commands within the container. base: