-
-
Save yortz/1047083 to your computer and use it in GitHub Desktop.
Basic git post-receive hook file to deploy a Rails app.
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_NAME="your-app-name-goes-here" | |
APP_PATH=/home/deploy/${APP_NAME} | |
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this file! Could you explain how line 9 works with rvm being used globally?