Capistrano – Deploying 2.0
15
Jul
2009
…because ssh’in and updating all this code manually is so 2006.
Enter Capistrano! It’s for web what make is for c. It’s simple, widely used and even those php kids begin likein’ it!
A tool which make subsequent deployments to your webserver much easier.
Installation
Capostrano runs on your machine. You don’t need it on your server to work!
‘Capistranize’ your application
Then setup the config/deploy.rb file. There are many guides on the net.
Deploy your app
cap deploy:setup # creates directories on the server
cap deploy:cold # copies code + db migration
cap deploy # update code (normal call)
Capistrano + local git repo
deploy.rb:
set :repository, "file:///file/localrepo.git"
set :scm, :git
set :branch, "master"
set :deploy_via, :copy
The “copy” deployment strategy is the only working one, as your server does not has direct access to your repo. If you have a possibility to remote-upload the repo, do so, and choose the remote_cache strategy, which is much faster.
My config
#############################################################
# Application
#############################################################
set :application, "app"
set :deploy_to, "/var/www/#{application}_src"
#############################################################
# Settings
#############################################################
# we don't have sudo rights
set :use_sudo, false
# set to production environment
set :rails_env, 'production'
#############################################################
# Servers
#############################################################
set :user, "user"
set :domain, "server"
role :app, domain
role :web, domain
role :db, domain, :primary => true
#############################################################
# Git
#############################################################
# we are using a local copy of the git repository
set :repository, "file:///..........git"
set :scm, :git
set :branch, "master"
set :deploy_via, :copy
#############################################################
# Override Tasks
#############################################################
namespace :deploy do
task :finalize_update, :except => { :no_release => true } do
logger.info 'do nothing - overridden finalize_update'
end
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do
end
end
end
Links
http://capitate.rubyforge.org/recipes/deploy.html
http://www.softiesonrails.com/2007/4/5/the-absolute-moron-s-guide-to-capistrano
http://github.com/guides/deploying-with-capistrano
The Capistrano Peepcode Screencast
http://jimneath.org/2008/05/10/using-capistrano-with-passenger-mod_rails/
Related posts:
- Add a version timestamp with capistrano
- HowTo update rake 0.8.1 -> 0.8.4 on debian
- Snippet: copy ssh key to server in one line