Skip to content

Instantly share code, notes, and snippets.

@felipeelias
Created October 27, 2011 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipeelias/1319502 to your computer and use it in GitHub Desktop.
Save felipeelias/1319502 to your computer and use it in GitHub Desktop.
Deploy with git's post-receive hook
#!/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