Capistrano 2.0 is out. Check the announcement here.
Capistrano is great for automating tasks via SSH on remote servers, like software installation, application deployment, configuration management, ad hoc server monitoring, and more.
Learn more about capistrano on it’s website.
I like to share my deployment recipe. After running “capify .” on the app directory, I got the file config/deploy.rb. Initially it looks like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
set :application, "set your application name here" set :repository, "set your repository location here" # If you aren't deploying to /u/apps/#{application} on the target # servers (which is the default), you can specify the actual location # via the :deploy_to variable: # set :deploy_to, "/var/www/#{application}" # If you aren't using Subversion to manage your source code, specify # your SCM below: # set :scm, :subversion role :app, "your app-server here" role :web, "your web-server here" role :db, "your db-server here", :primary => true |
After putting in the values and adding some tasks, my deploy.rb looks like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
set :application, "topsecret" set :repository, "http://svn.example.com/topsecret/trunk" # If you aren't deploying to /u/apps/#{application} on the target # servers (which is the default), you can specify the actual location # via the :deploy_to variable: set :deploy_to, "/home/topher/apps/#{application}" role :app, "topher.88-mph.net" role :web, "topher.88-mph.net" role :db, "topher.88-mph.net", :primary => true set :mongrel_config, "/etc/mongrel_cluster/#{application}.yml" namespace :deploy do desc "Link in the *.yml files and rails." task :after_update_code do run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml" run "ln -nfs #{deploy_to}/shared/config/mongrel_cluster.yml #{release_path}/config/mongrel_cluster.yml" run "ln -nfs /home/topher/rails_src/rails_1_2_stable #{release_path}/vendor/rails" end desc "Restart the mongrels." task :restart do sudo "mongrel_rails cluster::restart -C #{mongrel_config}" end end |
- :application is the app name
- :repository is the svn repository
- :deploy_to is the path to the app in the server
- roles :app, :web, and :db is the server. I’m using one server for the app, web, and db so they’re all the same.
- :mongrel_config is config file to be used by the mongrel_cluster gem
- I create symlinks to config/database.yml and config/mongrel_cluster.yml.
- I use rails 1.2.3 for this app but the server has 1.1.6 installed. You can check in vendor/rails to svn (or svn externals) but I decided to put rails to a directory outside of the app so it can be shared by multiple apps. I just create a symlink.
- I restart my mongrel cluster using the cluster::restart. The mongrel_cluster gem includes a recipe but so far it only works with capistrano 1.4. (Thanks to topfunky for this.)
To deploy I just run “cap deploy” on my development machine. To deploy with migrations run “cap deploy:migrations”.
