A deployment tool with Consul / Serf event.
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"$ stretcher -h
Usage of stretcher:
-random-delay float
sleep [0,random-delay) sec on start
-v show version
-version
show version
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.
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"
When you specify a S3 URL in manifest, requires a AWS credential setting one of below.
- ~/.aws/config and ~/.aws/credentials (overridden by
AWS_CONFIG_FILEenvironment variable.)AWS_DEFAULT_PROFILEis supported to select a profile from multiple credentials in file.
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_DEFAULT_REGIONenvironment variable.- EC2 IAM role.
- requires
AWS_DEFAULT_REGIONenvironment variable.
- requires
This process is not included in a stretcher agent.
- Create a tar(or tar.gz) archive for deployment.
- Upload the archive file to remote server (S3 or HTTP(S)).
- Create a manifest file (YAML) and upload it to remote server.
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)
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).
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.
A stretcher agent executes a following process.
- Receive a manifest URL as Consul/Serf event's payload.
- Get a manifest.
- Get src URL and store it to a temporary file, and Check
checksum. - Invoke
precommands. - Extract
srcarchive to a temporary directory. - Sync files from extracted archive to
destdirectory.
- use
rsync -a --delete
- Invoke
postcommands.
- Invoke
successcommands when the deployment process succeeded. - Invoke
failurecommands when the deployment process failed.
Source archive URL.
- URL schema: 's3', 'http', 'file'
- Format: 'tar', 'tar.gz'
src: http://example.com/src/archive.tar.gzChecksum of source archive.
- Type: 'md5', 'sha1', 'sha256', 'sha512'
checksum: e0840daaa97cd2cf2175f9e5d133ffb3324a2b93Destination directory.
dest: /home/stretcher/appDestination directory mode. Default: 0755
dest_mode: 0711Destination directory mode will be set as...
srcarchive includes.=> same as.in the archive.srcarchive does not include.=>dest_mode
pre: Commands which will be invoked at beforesrcarchive extracted.post: Commands which will be invoked at afterdestdirectory 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.logstretcher agent logs will be passed to STDIN of success and failure commands.
Pass to rsync --exclude arguments.
excludes:
- "*.pid"
- "*.socket"Pass to rsync --exclude-from arguments.
The file must be included in src archive.
exclude_from: exclude.list- 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.
The MIT License (MIT)
Copyright (c) 2014- FUJIWARA Shunichiro