Skip to content

Instantly share code, notes, and snippets.

@jasper-lyons
Created October 19, 2017 19:02
Show Gist options
  • Save jasper-lyons/c88f39a3c11cc4956772bc060345c6fc to your computer and use it in GitHub Desktop.
Save jasper-lyons/c88f39a3c11cc4956772bc060345c6fc to your computer and use it in GitHub Desktop.
Deploy rails app via git push
#! /bin/bash
while read oldrev newrev ref
do
# if we're on master branch
if [[ $ref =~ .*/master$ ]]; then
echo "Master ref received. Deploying master branch to production..."
git --work-tree=/srv/ageofai --git-dir=/home/git/ageofai checkout -f
source ~/.bash_profile
cd /srv/ageofai
if bundle install ; then
if bundle exec rake test ; then
if lsof -i tcp:5000 ; then
kill -9 $(lsof -i tcp:5000 | awk '{print $2}' | tail -n1)
fi
export SECRET_KEY_BASE='your key here'
export RAILS_SERVE_STATIC_FILES=true
RAILS_ENV=production bundle exec rails assets:precompile
bundle exec rails s -e production -p 5000 -d &
sudo /bin/systemctl restart nginx
fi
else
echo "Bundle install failed!"
fi
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