Let’s start off with a few aliases that speed things up. The commands are pretty self explanatory. I’ve got my deployment down to a simple acd command, which will add and commit to svn, then deploy to the server. To add a migration before deployment I use acmd. The following commands go into your ~/.bash_login file (assuming you’re using OS X or Linux).
1 2 3 4 5 6 7 | alias svna='svn add * --force' alias svnc='svn commit . -m ""' alias capd='cap deploy' alias capm='cap deploy:migrate' alias acd='svna; svnc; capd;' alias acmd='svna; svnc; capm; capd;' alias rors='script/server -b localhost' |
If you don’t already have capistrano setup, it’s as easy as
1 | $ gem install -y capistrano |
When I first setup an new rails project I follow these steps
1 2 3 4 5 6 7 8 | $ rails -d mysql PROJECT_NAME $ cd PROJECT_NAME $ capify . $ svn import PROJECT_PATH SVN_PATH -m 'Initial import' $ cd .. $ rm -Rf PROJECT_PATH $ svn co SVN_PATH $ mate PROJECT_PATH |
This initial setup process will create the rails project, setup Capistrano, add it to svn, and open it in TextMate. You can of course leave that last line out and use any IDE you wish.
Next open the config/deploy.rb file that Capistrano created for you. This is where you will put all your Capistrano instructions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | set :user, "SUDO_USER" set :password, "SUDO_USER_PASS" set :domain, "example.com" server domain, :app, :web role :db, domain, :primary => true set :application, "example" set :deploy_to, "/home/example/public_html/#{application}.sandbox.#{domain}/#{application}/" default_run_options[:pty] = true set :use_sudo, true set :runner, :user set :repository, "http://#{domain}/svn/#{application}" set :scm_username, "SVN_USER" set :scm_password, "SVN_USER_PASS" set :checkout, "export" namespace :deploy do desc "Restart Application" task :restart, :roles => :app do run "touch #{current_path}/tmp/restart.txt" end end |
Just change all the capitalized tokens to reflect your own settings. Then deploying should be as simple as typing acd in the Terminal. I created a blank file at /tmp/restart.txt and added it to svn so passenger will restart the rails app when you deploy. Also, you may not want to put your sudo password into deploy.rb.
I entountered various struggles in getting everything to work correctly. If you need help with something specific, post it in a comment. I can probably tell you what the problem is.
You can find help for Passenger here: http://www.modrails.com/ and help for Capistrano here: http://www.capify.org/