Skip to content

Instantly share code, notes, and snippets.

@paulca
Created February 20, 2012 22:46
Show Gist options
  • Save paulca/1872050 to your computer and use it in GitHub Desktop.
Save paulca/1872050 to your computer and use it in GitHub Desktop.
Quick Deploy for Rails 3.1 on Engine Yard Cloud
# Place this file in the root of your project directory
# eg. APPNAME=tito
APPNAME=
# eg. APP_SERVERS=(deploy@app1.tito.io deploy@app2.tito.io)
APP_SERVERS=()
# eg. CACHE_DIRS=(public/cache)
CACHE_DIRS=()

Engine Yard Cloud Quick Deploy

This is a bash script for doing super quick deploys on Engine Yard Cloud. Perfect for when you just need to fix a quick typo. Deploys quick changes to a single app server in typically <~2s.

Install

Run this:

mkdir -p ~/bin && curl https://raw.github.com/gist/1872050/086475dcbc8e7d92d55ce0757d3692d77793f4b1/ey_deploy.sh > ~/bin/ey_deploy && chmod +x ~/bin/ey_deploy

Then create a .ey file in your project root directory. See .ey-example

How to use it

Deploy changes (using rsync):

ey_deploy

Deploy changes with migrations:

ey_deploy -m

Deploy changes and run asset precompilation:

ey_deploy -p

Deploy changes and clear the page cache:

ey_deploy -c

What does it do?

All this does is rsyncs your local code to your Engine Yard Cloud servers. It doesn't do any sanity checks or anything, so you'll still want to run ey deploy once in a while. But for day to day deploying, you won't get much faster than this.

#!/bin/sh
# Place this file in ~/bin/ey_deploy
source .ey
echo "deploying ${APPNAME}"
for server in "${APP_SERVERS[@]}"
do
echo "Syncing code on $server"
rsync -arvH * $server:/data/$APPNAME/current/ --exclude 'log' --exclude 'config/database.yml' --exclude 'tmp' --exclude 'public/uploads' --exclude 'public/cache' $RSYNCFLAGS
ssh $server "touch /data/$APPNAME/current/tmp/restart.txt"
done
#
#
while getopts ":mpc" opt; do
case $opt in
m)
echo "migrating" >&2
ssh $APP_SERVERS[0] "cd /data/$APPNAME/current/ && RAILS_ENV=production bundle exec rake db:migrate"
;;
p)
echo "precompiling assets" >&2
for server in "${APP_SERVERS[@]}"
do
"precompiling assets on $server"
ssh $server "cd /data/$APPNAME/current/ && RAILS_ENV=production bundle exec rake assets:precompile"
done
;;
c)
echo "clearing cache" >&2
for server in "${APP_SERVERS[@]}"
do
echo "clearing cache on $server"
for cache_dir in "${CACHE_DIRS[@]}"
do
ssh $server "cd /data/$APPNAME/current/ && rm -r $cache_dir"
done
done
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment