A simple way to deploy your Rails applications
When I have a very simple Rails app, I avoid adding Capistrano or any other complex tool to deploy it.
Instead, I use a simple shell script, which access the server via SHH and do what needs to be done:
bash
#! /bin/bash
# script/deploy.sh
TAG=deployed_at_$(date +"%F_%H-%M")
git tag -m '' -a $TAG
git push --tags
ssh user@your_domain.com << 'SSH'
cd /var/rails_apps/my_app
rm -rf public/assets
git pull
bundle install --without development test
bundle exec rake db:migrate db:seed assets:clean assets:precompile
touch tmp/restart.txt
git describe > public/version
SSH
After that, a tag will be created in the git repository.
Now, you know exactly the date and time when it was deployed.
Also, you can find out which version (tag from git) is in production by accessing the URL http://your_domain.com/version.
Update from March 8, 2013:
I've created another script which accepts a
-q
(quick) flag:bash
#! /bin/bash
# script/deploy.sh
create_tag(){
TAG=deployed_at_$(date +"%F_%H-%M")
git tag -m '' -a $TAG
git push --tags
}
quick_deploy(){
echo 'Starting quick deploy...'
create_tag
ssh yourserver.com << 'SSH'
cd /var/rails_apps/app_name
git pull
bundle install --without development test
touch tmp/restart.txt
git describe > public/version
SSH
}
complete_deploy(){
echo 'Starting complete deploy...'
create_tag
ssh yourserver.com << 'SSH'
cd /var/rails_apps/app_name
rm -rf public/assets
git pull
bundle install --without development test
bundle exec rake db:migrate db:seed assets:clean assets:precompile
touch tmp/restart.txt
git describe > public/version
SSH
}
if [ $1 ]; then
if [ "$1" == '-q' ] || [ "$1" == '--quick' ]; then
quick_deploy
else
echo -e 'Usage: script/deploy [OPTIONS]\n\nOptions:\n-q --quick: Deploy without running migrations nor re-precompiling assets.\n'
fi
else
complete_deploy
fi