Created
August 20, 2015 22:43
-
-
Save skwp/92c569cb622c47d3a1b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Fail if any commands fail | |
set -e | |
set -o pipefail | |
# These are ec2 tags from which we will determine where to deploy | |
ec2_stage=$DEPLOY_STAGE | |
ec2_app="core" | |
ec2_role="app" | |
# What env to use to compile ember app? | |
ember_env=$EMBER_ENV | |
# What bucket to put it into on S3 | |
bucket="bucket-for-my-ember-app" | |
destination="/path/to/where/ember/lives" | |
rails_app="/path/to/my/rails/app" | |
deploy_cmd="mkdir -p $destination && wget -qO- https://s3.amazonaws.com/$bucket/$ec2_stage/release.tgz | tar xzvf - -C $destination && cd $rails_app/public && ln -nfs $destination ." | |
function build_app() { | |
npm install | |
node_modules/.bin/bower install | |
node_modules/.bin/ember build --environment $ember_env | |
cd dist | |
tar -czf ../release.tgz . | |
cd - | |
echo "Created release: `ls -alh release.tgz`" | |
# Uploading our artifact | |
aws s3 cp release.tgz s3://$bucket/$ec2_stage/ --acl public-read | |
} | |
# using aws cli hit up the api and return the nodes we want to deploy to | |
function fetch_ips() { | |
ips=$(aws ec2 describe-instances \ | |
--filters "[{\"Name\":\"tag:app\", \"Values\":[\"$ec2_app\"]},{\"Name\":\"tag:stage\", \"Values\":[\"$ec2_stage\"]}, {\"Name\":\"tag:role\", \"Values\":[\"$ec2_role\"]}]" \ | |
--query="Reservations[*].Instances[*].PrivateIpAddress" \ | |
--output text) | |
} | |
# loop through ips returned from aws and run our deploy_cmd | |
function deploy { | |
echo "Deploying to $ips" | |
for ip in $ips; do | |
echo "ssh someuser@$ip \"$deploy_cmd\"" | |
ssh reverb@$ip "$deploy_cmd" | |
done | |
} | |
build_app | |
fetch_ips | |
deploy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment