Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Basic git post-receive hook file to deploy a Rails app.
# Production environment
export RAILS_ENV="production"
# This loads RVM into a shell session. Uncomment if you're using RVM system wide.
# [[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm"
exit_with_error() {
echo "[DEPLOY] !!!!!!!!!!!!!!!!!!!! An error has occurred !!!!!!!!!!!!!!!!!!!!!!!"
exit 1
# Initial directory is .git, so go to the working copy directory
cd ${APP_PATH}/current
echo "**********************************************************************"
echo " Deploying application... "
echo "**********************************************************************"
# Add everything to the index and then reset hard to both sweep changed files
# (like cached pages) and update the working copy.
echo "[DEPLOY] - * Updating application working tree"
env -i git add .
env -i git reset --hard || exit_with_error
env -i git pull origin master
echo "[DEPLOY] - * Linking Configuration and directories"
ln -nfs ${APP_PATH}/shared/config/database.yml ${APP_PATH}/current/config/database.yml || exit_with_error
ln -nfs ${APP_PATH}/shared/log/ ${APP_PATH}/current/log || exit_with_error
ln -nfs ${APP_PATH}/shared/bundle/ ${APP_PATH}/current/vendor/bundle || exit_with_error
echo "[DEPLOY] - * Running bundle"
bundle install --deployment --without development test || exit_with_error
echo "[DEPLOY] - * Migrating database"
bundle exec rake db:migrate || exit_with_error
echo "[DEPLOY] - * Restarting application"
mkdir -p tmp/
touch tmp/restart.txt
echo "[DEPLOY] - * Successfully deployed application to ${APP_PATH}/current"

This comment has been minimized.

Copy link

commented Jan 21, 2014

Thanks for posting this file! Could you explain how line 9 works with rvm being used globally?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.