Skip to content

Instantly share code, notes, and snippets.

@allspiritseve
Last active December 15, 2015 05:19
Show Gist options
  • Save allspiritseve/5208034 to your computer and use it in GitHub Desktop.
Save allspiritseve/5208034 to your computer and use it in GitHub Desktop.
Capistrano-like git deployment with symlinked release folders.
#!/bin/bash -l
export RACK_ENV="production"
export RAILS_ENV="production"
APP_PATH=/var/www/townstage
CURRENT="$APP_PATH/releases/$(date +"%Y%m%d%H%M")"
exit_with_error() {
echo "Error..."
exit 1
}
mkdir $CURRENT
git archive master | tar -x -C $CURRENT || exit_with_error
cd $CURRENT
ln -nsf $APP_PATH/shared/config/database.yml config/database.yml || exit_with_error
ln -nsf $APP_PATH/shared/log log || exit_with_error
ln -nsf $APP_PATH/shared/public/assets public/assets || exit_with_error
ln -nsf $APP_PATH/shared/public/uploads public/uploads || exit_with_error
ln -nsf $APP_PATH/shared/vendor/bundle vendor/bundle || exit_with_error
bundle install --deployment --without development test || exit_with_error
bundle exec rake db:migrate || exit_with_error
bundle exec rake assets:precompile || exit_with_error
bundle exec whenever --write-crontab || exit_with_error
ln -nsf $CURRENT $APP_PATH/current
kill -USR2 $(cat $APP_PATH/shared/pids/unicorn.pid) || exit_with_err
echo -e "\nLadies and gentlemen, we have successfully deployed to Linode!\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment