When application needs to be set on different environment like staging and development question comes how to manage cap deploy ?
Here are easy steps which will guide to setup and manage with SVN and Capistrano
Setup multistage deployment with Capistrano
1) Install capistrano and capistrano multistage
2) Capify your project
3) Prepare the deploy / directory
4) Create the deployment recipes
For my project i have created development and production environment. Name your stages whatever you want. but, never name one of your stages stage — it’s a reserved word. We Can name it “staging”.
1) Install capistrano and capistrano multistage
gem install capistrano –no-ri –no-rdoc
gem install capistrano-ext –no-ri –no-rdoc
2) Capify your project
capify you project with following command in project root folder
capify .
3) Prepare the deploy / directory
mkdir config/deploy
touch config/deploy/development.rb
touch config/deploy/production.rb
4) Create the deployment recipes
require ‘capistrano/ext/multistage’
set :stages, %w(development production)
set :default_stage, “development”
set :application, “application”
set :user, “username”
set :password, “password”
set :repository, “https://domain/svn/project/trunk”
set :scm, :subversion
set :scm_username, “repository_username”
set :scm_username, “repository_password”
set :deploy_via, :export
# deploy using “ssh-add”, then “cap deploy”
ssh_options[:forward_agent] = true
set :ssh_options, {:forward_agent => true}
set :use_sudo, false
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :install_configs
#perform specify operations like set path or other stuff here
end
task :restart, :roles => :app, :except => { :no_release => true } do
run “#{try_sudo} touch #{File.join(current_path,’tmp’,’restart.txt’)}”
end
end
after(‘deploy:update_code’, “deploy:cleanup”, ‘deploy:install_configs’)
Now it’s turn to set both files which we have created in config/deploy 1) development.rb 2) production.rb
Set your development.rb
server “development.domain.com”, :app, :web, :db, :primary => true
set :deploy_to, “/var/www/development.domain.com” #path where you want to deploy application on server
set :db_config, “database-development.yml”
namespace :perform do
task :install_configs
#perform specify operations like set path or other stuff here
end
end
after(“deploy”, “perform:install_configs”)
Set your production.rb
server “production.domain.com”, :app, :web, :db, :primary => true
set :deploy_to, “/var/www/production.domain.com” #path where you want to deploy application on server
set :db_config, “database-production.yml”
namespace :perform do
task :install_configs
#perform specify operations like set path or other stuff here
end
end
after(“deploy”, “perform:install_configs”)
Great, you are ready to deploy with both environments
When you deploy recipe with cap deploy it will start deploying default environment whatever is set, if you want to deploy specific for environment please run command cap “environment” deploy in our case cap production deploy .
All set with multistage Capistrano deployment with minimal configuration.Lot more for rails 3 and RVM configuration.