Skip to content

Instantly share code, notes, and snippets.

@cupnoodle
Last active February 9, 2017 05:19
Show Gist options
  • Select an option

  • Save cupnoodle/0faef2c737ebb7eb988e2a56b4fe1bad to your computer and use it in GitHub Desktop.

Select an option

Save cupnoodle/0faef2c737ebb7eb988e2a56b4fe1bad to your computer and use it in GitHub Desktop.
Post receive with unicorn/nginx, deploy script
#!/bin/bash -l
#The -l parameter executes the command in a login shell
GIT_DIR=/home/rails/repo/fox_sample.git
WORK_TREE=/home/rails/fox_sample
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production"
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
# start deploy tasks
cd $WORK_TREE
echo "work tree is located at"
echo $WORK_TREE
bundle install --deployment
rake db:create RAILS_ENV=production
rake db:migrate RAILS_ENV=production
rake assets:precompile RAILS_ENV=production
sudo service unicorn restart
sudo service nginx restart
# end deploy tasks
echo "Git post-receive deploy complete"
else
echo "Ref $ref received successfully. No action performed: only the master branch can 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