stretcher

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2015 License: MIT Imports: 20 Imported by: 5

README

stretcher

A deployment tool with consul event.

Example manifest

src: s3://example.com/app.tar.gz
checksum: e0840daaa97cd2cf2175f9e5d133ffb3324a2b93
dest: /home/stretcher/app
commands:
  pre:
    - echo 'staring deploy'
  post:
    - echo 'deploy done'
  success:
    - echo 'deploy success'
  failure:
    - echo 'deploy failed!!'
    - cat >> /path/to/failure.log
excludes:
  - "*.pid"
  - "*.socket"

Run

stretcher agent

A stretcher agent is designed as running under "consul watch" and will be kicked by consul event.

When you specify a S3 URL, requires AWS_CONFIG_FILE environment variable.

$ export AWS_CONFIG_FILE=/path/to/.aws/config
$ consul watch -type event -name deploy /path/to/stretcher
  • -name: your deployment identifiy name.

AWS_DEFAULT_PROFILE is also supported to select a profile from multiple aws profiles in AWS_CONFIG_FILE.

Deployment process
Preparing

This process is not included in a stretcher agent.

  1. Create a tar(or tar.gz) archive for deployment.
  2. Upload the archive file to remote server (S3 or HTTP(S)).
  3. Create a manifest file (YAML) and upload it to remote server.
Executing

Create a consul event to kick stretcher agents.

$ consul event -name deploy s3://example.com/deploy-20141117-112233.yml
  • -name: Same as stretcher agent event name.
  • payload: Manifest URL.

stretcher agent executes a following process.

  1. Recieve a consul event from consul watch.
  2. Get manifest URL.
  3. Get src URL and store it to a temporary file, and Check checksum.
  4. Invoke pre commands.
  5. Extract src archive to a temporary directory.
  6. Sync files from extracted archive to dest directory
  • using rsync -a --delete
  1. Invoke post commands.

Manifest spec

src

Source archive URL.

  • URL schema: 's3', 'http', 'file'
  • Format: 'tar', 'tar.gz'
src: http://example.com/src/archive.tar.gz
checksum

Checksum of source archive.

  • Type: 'md5', 'sha1', 'sha256', 'sha512'
checksum: e0840daaa97cd2cf2175f9e5d133ffb3324a2b93
dest

Destination directory.

dest: /home/stretcher/app
dest_mode

Destination directory mode. Default: 0755

dest_mode: 0711

Destination directory mode will be set as...

  1. src archive includes . => same as . in the archive.
  2. src archive does not include . => dest_mode
commands
  • pre: Commands which will be invoked at before src archive extracted.
  • post: Commands which will be invoked at after dest directory synced.
  • success: Commands which will be invoked at deployment process is succeeded.
  • failure: Commands which will be invoked at deployment process is failed.
commands:
  pre:
    - echo 'staring deploy'
  post:
    - echo 'deploy done'
  success:
    - echo 'deploy success'
  failure:
    - echo 'deploy failed!!'
    - cat >> /path/to/failure.log

stretcher agent logs will be passed to STDIN of success and failure commands.

excludes

Pass to rsync --exclude arguments.

excludes:
  - "*.pid"
  - "*.socket"
exclude_from

Pass to rsync --exclude-from arguments. The file must be included in src archive.

exclude_from: exclude.list

Requirements

  • Consul version 0.4.1 or later.
  • tar
  • rsync

tar and rsync must be exist in PATH environment.

LICENSE

The MIT License (MIT)

Copyright (c) 2014 FUJIWARA Shunichiro

Documentation

Index

Constants

View Source
const (
	AWSDefaultRegionName  = "us-east-1"
	AWSDefaultProfileName = "default"
)

Variables

View Source
var (
	AWSAuth   aws.Auth
	AWSRegion aws.Region
	LogBuffer bytes.Buffer
)
View Source
var DefaultDestMode = os.FileMode(0755)
View Source
var RsyncDefaultOpts = []string{"-av", "--delete"}

Functions

func Init added in v0.0.5

func Init()

func LoadAWSConfigFile

func LoadAWSConfigFile(fileName string, profileName string) error

func Run

func Run()

Types

type CommandLine added in v0.0.4

type CommandLine string

func (CommandLine) Invoke added in v0.0.4

func (c CommandLine) Invoke() error

func (CommandLine) InvokePipe added in v0.0.4

func (c CommandLine) InvokePipe(src io.Reader) error

func (CommandLine) String added in v0.0.4

func (c CommandLine) String() string

type CommandLines added in v0.0.4

type CommandLines []CommandLine

func (CommandLines) Invoke added in v0.0.4

func (cs CommandLines) Invoke() error

func (CommandLines) InvokePipe added in v0.0.4

func (cs CommandLines) InvokePipe(src *bytes.Buffer) error

type Commands

type Commands struct {
	Pre     CommandLines `yaml:"pre"`
	Post    CommandLines `yaml:"post"`
	Success CommandLines `yaml:"success"`
	Failure CommandLines `yaml:"failure"`
}

type ConsulEvent

type ConsulEvent struct {
	ID      string `json:"ID"`
	Name    string `json:"Name"`
	Payload string `json:"Payload"`
	LTime   int    `json:"LTime"`
}

func ParseConsulEvents

func ParseConsulEvents(in io.Reader) (*ConsulEvent, error)

func (ConsulEvent) PayloadString

func (ev ConsulEvent) PayloadString() string

type ConsulEvents

type ConsulEvents []ConsulEvent

type Manifest

type Manifest struct {
	Src         string       `yaml:"src"`
	CheckSum    string       `yaml:"checksum"`
	Dest        string       `yaml:"dest"`
	DestMode    *os.FileMode `yaml:"dest_mode"`
	Commands    Commands     `yaml:"commands"`
	Excludes    []string     `yaml:"excludes"`
	ExcludeFrom string       `yaml:"exclude_from"`
}

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

func (*Manifest) Deploy

func (m *Manifest) Deploy() error

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

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