Skip to content

Instantly share code, notes, and snippets.

@egoens
Created March 31, 2016 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egoens/e6781a2c55e11cb154e68fc1e05e8d5a to your computer and use it in GitHub Desktop.
Save egoens/e6781a2c55e11cb154e68fc1e05e8d5a to your computer and use it in GitHub Desktop.
post-receive
#!/bin/bash
GIT_DIR=/home/deploy/[app_name]
WORK_TREE=/var/www/[app_name]
export DATABASE_USER=''
export DATABASE_PASSWORD=''
export RAILS_ENV=staging
. ~/.zshrc
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production..."
mkdir -p $WORK_TREE
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log
# start deploy tasks
cd $WORK_TREE
bundle install
rake db:create
rake db:migrate
rake assets:precompile
sudo restart puma-manager
sudo service nginx restart
# end deploy tasks
echo "Git hooks deploy complete"
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment