Skip to content

Instantly share code, notes, and snippets.

@bparanj
Forked from danchoi/deploy.sh
Created June 8, 2022 17:41
Show Gist options
  • Save bparanj/9b0c4e50d0fbf2ef7dbe00afcaf9f844 to your computer and use it in GitHub Desktop.
Save bparanj/9b0c4e50d0fbf2ef7dbe00afcaf9f844 to your computer and use it in GitHub Desktop.
Simple Rails deploy bash script
#!/bin/bash
# deploy.sh
# Put this script on your production server and make it executable with chmod
# +x.
# Set the deploy_dir variable to the path on the production server to
# deployment directory. The script assumes the deployment directory is a git
# clone of the codebase from an upstream git repo. This script also assumes
# you are using Passenger.
deploy_dir=~/current # deploy dir
# You then can run deploy.sh remotely with ssh:
#
# ssh user@deployserver "~/deploy.sh"
echo "=======> Deploying to $deploy_dir <========"
cd $deploy_dir && git stash && git pull
# Run migrations if any are pulled down
if find db/migrate -type f -mmin -3 | grep '.*'
then
echo New migrations found
RAILS_ENV=production bundle exec rake db:migrate
else
echo No new migrations
fi
# Uncomment if using ThinkingSphinx
# RAILS_ENV=production bundle exec rake ts:rebuild
# Restart if any new Rails code
if find app config lib db/migrate -type f -mmin -3 | grep '.*'
then
echo Restarting Rails
touch tmp/restart.txt
else
echo No need to restart
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment