Created
October 27, 2011 13:10
-
-
Save felipeelias/1319502 to your computer and use it in GitHub Desktop.
Deploy with git's post-receive hook
This file contains hidden or 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_PATH=/home/applicake/app | |
# Production environment | |
export RAILS_ENV="production" | |
export PATH="/opt/ruby/bin:$PATH" | |
exit_with_error() { | |
echo "[DEPLOY] !!!!!!!!!!!!!!!!!!!! An error has occurred !!!!!!!!!!!!!!!!!!!!!!!" | |
exit 1 | |
} | |
# Initial directory is .git, so go to the working copy directory | |
mkdir -p ${APP_PATH}/current | |
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] - * Ensuring directories" | |
mkdir -p ${APP_PATH}/shared/config | |
mkdir -p ${APP_PATH}/shared/log | |
mkdir -p ${APP_PATH}/shared/bundle | |
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] - * Compiling assets" | |
bundle exec rake assets:precompile || 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