From d6901529770cb119071adf3e8fcea9de00f2efbd Mon Sep 17 00:00:00 2001 From: Andrew Reed Date: Fri, 14 Jul 2017 11:06:47 -0700 Subject: [PATCH 1/2] install script for linux README example for CI --- Dockerfile | 3 -- Makefile | 7 ---- README.md | 94 ++++++++++++++++++++++++++++++++++++++++++++++++------ install.sh | 31 ++++++++++++++++++ 4 files changed, 116 insertions(+), 19 deletions(-) create mode 100755 install.sh diff --git a/Dockerfile b/Dockerfile index 0d2f5d8ef..6e6a29976 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,6 @@ RUN go get github.com/spf13/cobra/cobra RUN go get github.com/go-swagger/go-swagger/cmd/swagger -RUN curl --location -o goreleaser.deb https://github.com/goreleaser/goreleaser/releases/download/v0.24.0/goreleaser_Linux_x86_64.deb -RUN dpkg -i goreleaser.deb - WORKDIR $PROJECTPATH CMD ["/bin/bash"] diff --git a/Makefile b/Makefile index 6de9717b3..80d658c28 100644 --- a/Makefile +++ b/Makefile @@ -54,13 +54,6 @@ build: go build -o replicated cli/main.go mv replicated ${GOPATH}/bin -# release the latest tag -release: - docker run --rm -it \ - --volume `pwd`:/go/src/github.com/replicatedhq/replicated \ - --env GITHUB_TOKEN=${GITHUB_TOKEN} \ - replicatedhq.replicated goreleaser - docs: go run docs/generate.go --path ./gen/docs diff --git a/README.md b/README.md index 91e8a53be..798f26ce2 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,93 @@ # replicated This repository provides a client and CLI for interacting with the Replicated Vendor API. -The models are generated from the API's swagger spec. ## CLI -Grab the latest [release](https://github.com/replicatedhq/replicated/releases) and extract it to your path. +### Mac Install +``` +brew install replicatedhq/replicated +``` + +### Linux Install +``` +curl -sSL https://raw.githubusercontent.com/replicatedhq/replicated/master/install.sh +sudo bash ./install.sh +``` + +### Getting Started ``` replicated channel ls --app my-app-slug --token e8d7ce8e3d3278a8b1255237e6310069 ``` Set the following env vars to avoid passing them as arguments to each command. -* REPLICATED_APP_SLUG -* REPLICATED_API_TOKEN +* ```REPLICATED_APP_SLUG``` +* ```REPLICATED_API_TOKEN``` + +Then the above command would be simply +``` +replicated channel ls +``` + +### CI Example +Creating a new release for every tagged build is a common use of the ```replicated``` command. + +Assume the app's yaml config is checked in at replicated.yaml and you have configured TravisCI or CircleCI with your ```REPLICATED_APP_SLUG``` and ```REPLICATED_API_TOKEN``` environment variables, as well as ```UNSTABLE_CHANNEL_ID```. + +Then add a release.sh script to your project looking something like this: + +```bash +#!/bin/bash + +# Create a new release from replicated.yaml and promote the Unstable channel to use it. +# Aborts if version tag is empty. + +set -e + +VERSION=$1 +INSTALL_SCRIPT=https://raw.githubusercontent.com/replicatedhq/replicated/master/install.sh + +if [ -z "$VERSION" ]; then +echo "No version; skipping replicated release" + exit +fi + +unstable_channel_id() { + replicated channel ls | grep Unstable | awk '{print $1}' +} + +new_sequence() { + replicated release create --yaml "$(< replicated.yaml)" | grep 'SEQUENCE:' | grep -Eo '[0-9]+' +} + +# install replicated +curl -sSL "$INSTALL_SCRIPT" > install.sh +sudo bash ./install.sh + +replicated release promote $(new_sequence) $(unstable_channel_id) --version "$VERSION" +# Channel ee9d99e87b4a5acc2863f68cb2a0c390 successfully promoted to release 15 +``` + +Now you can automate tagged releases in TravisCI or CircleCI: + +```yaml +# .travis.yml +sudo: required +after_success: + - ./release.sh "$TRAVIS_TAG" + +``` + +```yaml +# circle.yml +deployment: + tag: + tag: /v.*/ + owner: replicatedcom + commands: + - ./release.sh "$CIRCLE_TAG" +``` ## Client @@ -53,8 +127,12 @@ func main() { ## Development ```make build``` installs the binary to ```$GOPATH/bin``` +The models are generated from the API's swagger spec. ### Tests + +#### Environment + REPLICATED_API_ORIGIN may be set for testing an alternative environment. Since apps can only be deleted in a login session, set these to cleanup garbage from the tests. @@ -62,11 +140,9 @@ VENDOR_USER_EMAIL should be set to delete app VENDOR_USER_PASSWORD should be set to delete app ### Releases -Releases are created locally with [goreleaser](https://github.com/goreleaser/goreleaser). -Tag the commit to release then run goreleaser. -Ensure GITHUB_TOKEN is [set](https://github.com/settings/tokens/new). - +Releases are created on Travis when a tag is pushed. This will also update the docs container. +* ```REPLICATED_API_ORIGIN``` may be set to override the API endpoint +* ```VENDOR_USER_EMAIL``` and ```VENDOR_USER_PASSWORD``` should be set to delete apps created for testing ``` git tag -a v0.1.0 -m "First release" && git push origin v0.1.0 -make release ``` diff --git a/install.sh b/install.sh new file mode 100755 index 000000000..bdd120ab1 --- /dev/null +++ b/install.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +TAR_FILE="/tmp/replicated.tar.gz" + +RELEASES_URL="https://github.com/replicatedhq/replicated/releases" + +test -z "$TMPDIR" && TMPDIR="$(mktemp -d)" + +last_version() { + curl --silent --location --output /dev/null --write-out %{url_effective} ${RELEASES_URL}/latest | + grep -Eo '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]$' +} + +download() { + if [[ $(uname -m) =~ '64$' ]]; then + ARCH=amd64 + else + ARCH=386 + fi + VERSION="$(last_version)" + # https://github.com/replicatedhq/replicated/releases/download/v0.1.1/replicated_0.1.1_linux_amd64.tar.gz + URL="${RELEASES_URL}/download/v${VERSION}/replicated_${VERSION}_$(uname -s)_${ARCH}.tar.gz" + + rm -f "$TAR_FILE" + curl -s -L -o "$TAR_FILE" "$URL" +} + +download +tar -xf "$TAR_FILE" -C "$TMPDIR" +mv "${TMPDIR}/replicated" /usr/local/bin From 175f2dbb41b39713498777cb24b3e4a9c53089f4 Mon Sep 17 00:00:00 2001 From: Andrew Reed Date: Fri, 14 Jul 2017 15:16:03 -0700 Subject: [PATCH 2/2] No triple tildes inline Remove generated brew formula from this repo. Configure goreleaser to generate brew formula in replicatedhq/homebrew-replicated. --- .goreleaser.yml | 3 ++- README.md | 20 +++++++------------- replicated.rb | 11 ----------- 3 files changed, 9 insertions(+), 25 deletions(-) delete mode 100644 replicated.rb diff --git a/.goreleaser.yml b/.goreleaser.yml index 6b7b3b858..01525e936 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -6,7 +6,8 @@ release: brew: github: owner: replicatedhq - name: replicated + name: homebrew-replicated + folder: HomebrewFormula install: bin.install "replicated" homepage: https://replicated.com description: "Manage your app's channels and releases from the command line" diff --git a/README.md b/README.md index 798f26ce2..1de11ed37 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This repository provides a client and CLI for interacting with the Replicated Ve ### Mac Install ``` -brew install replicatedhq/replicated +brew install replicatedhq/replicated/replicated ``` ### Linux Install @@ -22,8 +22,8 @@ replicated channel ls --app my-app-slug --token e8d7ce8e3d3278a8b1255237e6310069 ``` Set the following env vars to avoid passing them as arguments to each command. -* ```REPLICATED_APP_SLUG``` -* ```REPLICATED_API_TOKEN``` +* REPLICATED_APP_SLUG +* REPLICATED_API_TOKEN Then the above command would be simply ``` @@ -31,9 +31,9 @@ replicated channel ls ``` ### CI Example -Creating a new release for every tagged build is a common use of the ```replicated``` command. +Creating a new release for every tagged build is a common use of the replicated command. -Assume the app's yaml config is checked in at replicated.yaml and you have configured TravisCI or CircleCI with your ```REPLICATED_APP_SLUG``` and ```REPLICATED_API_TOKEN``` environment variables, as well as ```UNSTABLE_CHANNEL_ID```. +Assume the app's yaml config is checked in at replicated.yaml and you have configured TravisCI or CircleCI with your REPLICATED_APP_SLUG and REPLICATED_API_TOKEN environment variables, as well as UNSTABLE_CHANNEL_ID```. Then add a release.sh script to your project looking something like this: @@ -132,17 +132,11 @@ The models are generated from the API's swagger spec. ### Tests #### Environment - -REPLICATED_API_ORIGIN may be set for testing an alternative environment. - -Since apps can only be deleted in a login session, set these to cleanup garbage from the tests. -VENDOR_USER_EMAIL should be set to delete app -VENDOR_USER_PASSWORD should be set to delete app +* ```REPLICATED_API_ORIGIN``` may be set to override the API endpoint +* ```VENDOR_USER_EMAIL``` and ```VENDOR_USER_PASSWORD``` should be set to delete apps created for testing ### Releases Releases are created on Travis when a tag is pushed. This will also update the docs container. -* ```REPLICATED_API_ORIGIN``` may be set to override the API endpoint -* ```VENDOR_USER_EMAIL``` and ```VENDOR_USER_PASSWORD``` should be set to delete apps created for testing ``` git tag -a v0.1.0 -m "First release" && git push origin v0.1.0 ``` diff --git a/replicated.rb b/replicated.rb deleted file mode 100644 index c86e119a2..000000000 --- a/replicated.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Replicated < Formula - desc "Manage your app's channels and releases from the command line" - homepage "https://replicated.com" - url "https://github.com/replicatedhq/replicated/releases/download/v0.1.1/replicated_0.1.1_darwin_amd64.tar.gz" - version "0.1.1" - sha256 "ccda0dbf9da532fbfb339cc4fbfd2c113adda00f58cb712a139482a305e9be51" - - def install - bin.install "replicated" - end -end