To configure Capistrano for the most basic staging environment, I modified my deploy.rb like so:
ENV['STAGE'] ||= "staging"
paths = {
:staging => "stage01.mydomain.com",
:production => "mydomain.com"
}
set :application, "mydomain.com"
set :dir, paths[ENV['STAGE'].to_sym]
set :user, "..."
role :web, application
role :app, application
role :db, application, :primary => true
set :deploy_to, "/home/#{user}/#{dir}"
set :use_sudo, false
As you can see, it defaults to “staging” so any calls like “cap deploy” or “cap update_code” will be performed in a safe sandbox. To go live, I have a “cap_production.bat” in the root folder:
SET STAGE=production cap %1 %2 %3 %4 %5
Guy Naor has a nice tip to help with large file uploading in Capistrano.
class Capistrano::Actor
# A saner put replacement that doesn't read the whole file into memory...
def put_file(path, remote_path, options = {})
raise "put_file can only be used with SFTP" unless Capistrano::SFTP && options.fetch(:sftp, true)
execute_on_servers(options) do |servers|
servers.each do |server|
logger.info "uploading #{File.basename(path)} to #{server}"
sftp = sessions[server].sftp
sftp.connect unless sftp.state == :open
sftp.put_file path, remote_path
logger.debug "done uploading #{File.basename(path)} to #{server}"
end
end
end
end
and I had to update it for Capistrano 2.0:
module Capistrano
class Configuration
module Actions
module FileTransfer
# A saner put replacement that doesn't read the whole file into memory...
def put_file(path, remote_path, options = {})
execute_on_servers(options) do |servers|
servers.each do |server|
logger.info "uploading #{File.basename(path)} to #{server}"
sftp = sessions[server].sftp
sftp.connect unless sftp.state == :open
sftp.put_file path, remote_path
logger.debug "done uploading #{File.basename(path)} to #{server}"
end
end
end
end
end
end
end

