Created
September 20, 2012 19:18
-
-
Save rpanachi/3757789 to your computer and use it in GitHub Desktop.
Forrest Deployer Shell
This file contains 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 | |
APP_DIR=/var/local/apps/app | |
RAILS_ENV=production | |
function step | |
{ | |
if [ "$step_count" = "" ]; then | |
step_count=0 | |
fi | |
step_count=`expr $step_count + 1` | |
last_step="#$step_count $1" | |
echo "" | |
echo $last_step | |
} | |
function step_done | |
{ | |
echo "$last_step [DONE]" | |
} | |
function run | |
{ | |
echo "$ $1" | |
$1 | |
if [ $? -ne 0 ]; then | |
echo "$last_step [FAIL]" | |
exit -1; | |
fi | |
} | |
function usage | |
{ | |
echo "usage: script/deploy -t tag [-h | --skip \"db gems assets\"]" | |
} | |
tag="" | |
skip="" | |
while [ "$1" != "" ]; do | |
case $1 in | |
-t | --tag ) shift | |
tag=$1 | |
;; | |
-s | --skip ) shift | |
skip=$1 | |
;; | |
-h | --help ) usage | |
exit | |
;; | |
* ) usage | |
exit 1 | |
esac | |
shift | |
done | |
if [ "$tag" = "" ]; then | |
usage | |
exit 1 | |
fi | |
skip_db=false | |
if [[ $skip =~ db ]]; then | |
skip_db=true | |
fi | |
skip_gems=false | |
if [[ $skip =~ gems ]]; then | |
skip_gems=true | |
fi | |
skip_assets=false | |
if [[ $skip =~ assets ]]; then | |
skip_assets=true | |
fi | |
## Main | |
step "Deploying Application tag $tag $RAILS_ENV" | |
run "cd $APP_DIR" | |
run "export RAILS_ENV=$RAILS_ENV" | |
step_done | |
if ! $skip_db ; then | |
step "Backup... " | |
run "script/backup $tag" | |
step_done | |
fi | |
step "Updating code version $tag" | |
run "git fetch origin master --tags" | |
run "git reset --hard $tag" | |
step_done | |
step "Enabling maintenance page" | |
run "touch public/maintenance.html" | |
step_done | |
step "Stopping services..." | |
run "sudo service app-web stop" | |
run "sudo service app-worker stop" | |
run "sudo service app-memcached stop" | |
step_done | |
if ! $skip_gems ; then | |
step "Installing gems" | |
run "bundle install --deployment --without development test" | |
step_done | |
fi | |
if ! $skip_db ; then | |
step "Migrating database" | |
run "bundle exec rake db:migrate" | |
step_done | |
fi | |
if ! $skip_assets ; then | |
step "Pre-compiling Assets" | |
run "bundle exec rake assets:clean assets:precompile" | |
step_done | |
fi | |
step "Starting services..." | |
run "sudo service app-memcached start" | |
run "sudo service app-worker start" | |
run "sudo service app-web start" | |
step_done | |
step "Disabling maintenance page" | |
run "rm public/maintenance.html" | |
step_done | |
echo "Have fun! [D O N E]" |
This file contains 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 | |
# | |
# Executa o script/deploy no servidor do http://minhaapp.com | |
# $ script/forrest -t tag1 | |
# | |
# Skip options: | |
# $ script/forrest -t tag1 --skip db # nao executa backup e rake db:migrate | |
# $ scritp/forrest -t tag1 --skip gems # nao executa bundle install ... | |
# $ scritp/forrest -t tag1 --skip assets # nao executa rake assets precompile ... | |
# | |
# Voce pode passar mais de um skip, usando a "trick": | |
# $ script/forrest -t tag1 --skip db-gems-assets # ou --skip gems-assets ... etc. | |
echo "Deploying on Application Server" | |
echo "$ ssh [email protected] \"/var/local/apps/app/script/deploy $@\"" | |
ssh [email protected] "/var/local/apps/app/script/deploy $@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment