Skip to content

Commit

Permalink
Merge pull request #11 from areed/areed/ch568/vendor-cli-release
Browse files Browse the repository at this point in the history
install script for linux
  • Loading branch information
areed authored Jul 14, 2017
2 parents 1a9b0a6 + 175f2db commit 31e4d4e
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
92 changes: 81 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# 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/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
```
Expand All @@ -15,6 +25,70 @@ Set the following env vars to avoid passing them as arguments to each command.
* 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
[GoDoc](https://godoc.org/github.com/replicatedhq/replicated/client)
Expand Down Expand Up @@ -53,20 +127,16 @@ func main() {

## Development
```make build``` installs the binary to ```$GOPATH/bin```
The models are generated from the API's swagger spec.

### Tests
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
#### Environment
* ```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 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.
```
git tag -a v0.1.0 -m "First release" && git push origin v0.1.0
make release
```
31 changes: 31 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions replicated.rb

This file was deleted.

0 comments on commit 31e4d4e

Please sign in to comment.