• Stars
    star
    245
  • Rank 165,304 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created about 10 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Deployment tool with consul/serf event notification.

Stretcher

A deployment tool with Consul / Serf 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

$ stretcher -h
Usage of stretcher:
  -max-bandwidth string
        max bandwidth for download src archives (Bytes/sec)
  -random-delay float
        sleep [0,random-delay) sec on start
  -retry int
        retry count for download src archives
  -retry-wait int
        wait for retry download src archives (sec) (default 3)
  -rsync-verbose string
        rsync verbose option (default -v)
  -timeout int
        timeout for download src archives (sec)
  -v    show version
  -version
        show version

with Consul

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

$ consul watch -type event -name deploy /path/to/stretcher
  • -name: your deployment identity name.

with Serf

A stretcher agent can be running as Serf event handler.

$ serf agent -event-handler="user:deploy=/path/to/stretcher >> /path/to/stretcher.log 2>&1"

Load AWS credentials

When you specify a S3 URL in the manifest, requires AWS regions and credentials configuration as the same of aws-sdk-go.

for regions,

  1. AWS_REGION or AWS_DEFAULT_REGION environment variable.

for credentials,

  1. Environment variables.
  2. Shared credentials file.
  3. If your application is running on an Amazon EC2 instance, IAM role for Amazon EC2.

See also Configuring the AWS SDK for Go.

Load GCP credentials

When you specify a GS(Google Cloud Storage) URL in the manifest, requires a GCP credential setting one of below.

  • ServiceAccount
    • requires GOOGLE_APPLICATION_CREDENTIALS=[PATH] environment variable.
    • Replace [PATH] with the file path of the JSON file that contains your service account key.
  • DefaultAccount
    • If the environment variable isn't set, load the default service account that Compute Engine provide, for applications that run on those services.

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 with Consul

Create a consul event to kick stretcher agents.

$ consul event -name [event_name] [manifest_url]
$ consul event -name deploy s3://example.com/deploy-20141117-112233.yml
  • -name: consul event name (specified by consul watch -name)

Executing with Serf

Create a serf user event to kick stretcher agents.

$ serf event [event_name] [manifest_url]
$ serf event deploy s3://example.com/deploy-20141117-112233.yml
  • event_name: user event name (specified by serf event handler).

Executing as command

Stretcher can read a manifest URL from stdin simply.

$ echo s3://example.com/deploy-20141117-112233.yml | stretcher

You can execute stretcher via ssh or any other methods.

Deployment process

A stretcher agent executes a following process.

  1. Receive a manifest URL as Consul/Serf event's payload.
  2. Get a manifest.
  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.
  • use rsync -a --delete or mv
  • sync strategy is switched by sync_strategy
  1. Invoke post commands.
  • Invoke success commands when the deployment process succeeded.
  • Invoke failure commands when the deployment process failed.

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

sync_strategy

A strategy for syncing src extracted directory to dest directory.

  • rsync: Default
    • Use rsync(1) command with option -av --delete
  • mv
    • Use os.Rename() of Golang.
    • Deployment will be failed if dest directory is already exists.

Requirements

  • tar
  • rsync

tar and rsync must be exist in PATH environment.

If you use stretcher under systemd, You can see unfinished stdout with journald. You should add RateLimitBurst=0 into /etc/systemd/journald.conf for getting stdout completely.

Commands execution only mode

If src is not defined in a manifest, Stretcher runs pre/post and success/failure commands simply.

LICENSE

The MIT License (MIT)

Copyright (c) 2014 FUJIWARA Shunichiro / (c) 2014 KAYAC Inc.

More Repositories

1

lambroll

lambroll is a minimal deployment tool for AWS Lambda.
Go
330
star
2

shapeio

Traffic shaper for Golang io.Reader and io.Writer
Go
126
star
3

awslim

A simplified alternative to the AWS CLI for limited use cases.
Go
114
star
4

fluent-agent-hydra

A Fluentd log agent.
Go
108
star
5

tracer

ECS task event/log tracer CLI
Go
95
star
6

tfstate-lookup

Lookup resource attributes in tfstate.
Go
87
star
7

ecsta

ECS Task Assistant tool.
Go
59
star
8

ridge

AWS Lambda HTTP Proxy integration event bridge to Go net/http.
Go
55
star
9

ecrm

A command line tool for managing ECR repositories.
Go
54
star
10

consul-kv-dashboard

Consul KVS based dashboard web application.
Go
49
star
11

fluent-plugin-zabbix

fluentd out plugin to zabbix
Ruby
49
star
12

kinesis-tailf

tail -f command for Amazon Kinesis Stream
Go
38
star
13

go-zabbix-get

zabbix-get compatible command (Golang version)
Go
28
star
14

Rin

Rin is a Redshift data Importer by SQS messaging.
Go
26
star
15

chef-solo-with-capistrano

chef-solo by capistrano
Ruby
26
star
16

cfft

cfft is a testing tool for CloudFront Functions.
Go
26
star
17

nssh

Go
22
star
18

aswrap

AWS assume role credential wrapper
Perl
21
star
19

tfstate-merge

A tool to merge tfstate files.
Ruby
20
star
20

mysql-slave-healthcheck-agent

Go
17
star
21

tuggle

Distributed file mirroring proxy in Consul cluster
Go
16
star
22

zabbix-aggregate-agent

Data aggregator for multiple zabbix-agent
Go
15
star
23

fluent-plugin-suppress

fluentd plugin to suppress same messages.
Ruby
14
star
24

isucon11-f

Vue
13
star
25

raus

Raus: Ranged unique id supplier
Go
12
star
26

MHA-AWS

A support script for MySQL MasterHA which running on Amazon Web Service.
Perl
12
star
27

lamblocal

Go
12
star
28

go-redis-setlock

Like the setlock command using Redis.
Perl
11
star
29

sailtrim

A minimal deployment tool for Amazon Lightsail.
Go
11
star
30

ohai-plugin-consul

Ohai plugin for Consul API
Ruby
10
star
31

maprobe

Mackerel external probe agent
Go
9
star
32

perl-queue-q4pg-lite

simple message queue using PostgreSQL.
Perl
8
star
33

p5-Parallel-Benchmark

Perl
8
star
34

Urume

Perl
7
star
35

AWS-XRay

AWS X-Ray tracing library for Perl5
Perl
6
star
36

isucon11-q

Go
6
star
37

knockrd

HTTP knocker daemon
Go
6
star
38

riex

AWS RI expiration detector
Go
5
star
39

go-amzn-oidc

Validator for x-amzn-oidc-data header values.
Go
5
star
40

sardine

Mackerel plugin metrics aggregator with CloudWatch.
Go
4
star
41

maws-cli

A multiplexing wrapper for aws cli.
Go
4
star
42

isucon5q

C
4
star
43

mackerel-plugin-prometheus-query

Prometheus query plugin for Mackerel
Go
4
star
44

go-simple-kvs

simple and tiny key value store
Go
4
star
45

consul-lock

runs another program with a Consul session/kv locked.
Go
4
star
46

fluent-plugin-imkayac

Fluentd plugin to post im.kayac.com
Ruby
4
star
47

iam-policy-finder

iam-policy-finder is finder of AWS IAM Policies.
Go
4
star
48

rrdialer

round robin net dialer.
Go
3
star
49

sirbot

Slack IRC relay bot
Go
3
star
50

Redis-Setlock

Like the setlock command using Redis.
Perl
3
star
51

Acore

Perl
3
star
52

fluent-plugin-firelens-tag-filter

fluent plugin for AWS firelens
Ruby
3
star
53

s32cs

Amazon CloudSearch document uploader via S3 event notification.
Go
3
star
54

go-http-transport-firehose

Go HTTP Transport to dump a request to Firehose
Go
3
star
55

isucon7q

HTML
3
star
56

cfn-lookup

Lookup outputs and exports for CloudFormation stacks.
Go
3
star
57

cloudwatch-to-mackerel

Copy metrics from Amazon CloudWatch to Mackerel.
Go
2
star
58

go-jsqlite

SQL query runner for JSONL
Go
2
star
59

lamux

Lamux is a HTTP multiplexer for AWS Lambda Function aliases.
Go
2
star
60

ssm-lookup

Lookup values in AWS SSM Parameter store.
Go
2
star
61

norikra-listener-mackerel

Norikra listener plugin to post service metrics for Mackerel.
Ruby
2
star
62

Devel-KYTProf-Profiler-Redis-Fast

KYTProf profiler for Redis::Fast
Perl
1
star
63

isucon5

Perl
1
star
64

Plack-Middleware-XRay

Plack middleware for AWS X-Ray tracing
Perl
1
star
65

redisqs

redisqs is a delayed queue manager using Amazon SQS and Redis.
Go
1
star
66

Plack-Middleware-GTop-ProcMem

Plack middleware for mesuring process memory.
Perl
1
star
67

macaroni

macaroni is a reporter for Songmu/horenso.
Go
1
star
68

Plack-Middleware-SetLocalEnv

Set localized environment variables(Perl's %ENV) from the value of PSGI environment.
Perl
1
star
69

ktlog2memcached

KyotoTycoon's slave agent, replicate updates to memcached.
Perl
1
star
70

mkr2oncall-cloudflare-workers

A port of mackerel-to-grafana-oncall for Cloudflare Workers.
TypeScript
1
star
71

Test-UNIXSock

testing UNIX domain socket program
Perl
1
star
72

go-template

Go
1
star
73

distdin

Distribute stdin to multiple sub commands.
Go
1
star
74

mirage-ecs-example

Dockerfile
1
star
75

go-s3concat

Concat S3 objects
Go
1
star
76

lambroll_test

Makefile
1
star
77

p5-dbix-couchlike

Perl
1
star