Over a million developers have joined DZone.

Capistrano: Deploy Rails Twice To The Same Machine

·
Capistrano is oriented so it deploys to the same directory on several machines. This means you can't deploy to two different locations on the same machine.  The following recipe in Capfile will allow you to duplicate your main rails app in a second directory. You can schedule it to run automatically with every deploy or just do it manually. I included database migrations by default. Remove the shared config line if you don't have it. Edit the directories to match yours.

namespace :yournamespace do
  desc "Synchronize main_app to second_app"
  task :sync_apps, :roles => [:app, :db, :web] do
    puts "synchronizing main_app to second_app"
    run "rsync -a /var/rails/main_app/ /var/rails/second_app --exclude=/shared --delete"
    run "for file in `find /var/rails/second_app -type l`; do TARGET=`readlink $file | sed -e \"s/main_app/second_app/\"`; rm $file; ln -s $TARGET $file; done;"
    run "cp /var/rails/second_app/shared/config/* /var/rails/second_app/current/config";
    run "cd /var/rails/second_app/current; /usr/local/bin/rake RAILS_ENV=production db:migrate;"
    run "touch tmp/restart.txt"
  end
end
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}