replicated

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2017 License: MIT

README

replicated

This repository provides a client and CLI for interacting with the Replicated Vendor API.

CLI

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

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:

#!/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:

# .travis.yml
sudo: required
after_success:
  - ./release.sh "$TRAVIS_TAG"

# circle.yml
deployment:
  tag:
    tag: /v.*/
    owner: replicatedcom
    commands:
      - ./release.sh "$CIRCLE_TAG"

Client

GoDoc

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/replicatedhq/replicated/client"
)

func main() {
	token := os.Getenv("REPLICATED_API_TOKEN")
	appSlug := os.Getenv("REPLICATED_APP_SLUG")

	api := client.New(token)

	app, err := api.GetAppBySlug(appSlug)
	if err != nil {
		log.Fatal(err)
	}

	channels, err := api.ListChannels(app.Id)
	if err != nil {
		log.Fatal(err)
	}
	for _, c := range channels {
		fmt.Printf("channel %s is on release %d\n", c.Name, c.ReleaseSequence)
	}
}

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 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.

git tag -a v0.1.0 -m "First release" && git push origin v0.1.0

Directories

Path Synopsis
cli
cmd
print
Package print contains templates for printing Vendor API types.
Package print contains templates for printing Vendor API types.
Package client manages channels and releases through the Replicated Vendor API.
Package client manages channels and releases through the Replicated Vendor API.
cmdgen
cmdgen is a tool for generating pages from a cobra command for a Hugo site.
cmdgen is a tool for generating pages from a cobra command for a Hugo site.
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL