It’s a good practice to send a notification to certain people when a new version is deployed. This process can easily be automated in Capistrano. Add the following file to the ‘lib’ directory with the filename ‘cap_mailer.rb’:
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 | require 'rubygems' require 'actionmailer' ActionMailer::Base.smtp_settings = {:address => "localhost", :port => 25, :domain => 'example.com'} class CapMailer < ActionMailer::Base def deploy_notification(options) message = "Deployment\n\n" options.each_pair do |k,v| message << " #{k}: #{v}\n" end recipients "notify-deployment@example.com" from 'noreply@example.com' subject "Deployment to #{options[:rails_env]}" body message end end module CapistranoMailer def send(options) CapMailer.deliver_deploy_notification(options) end end Capistrano.plugin :mailer, CapistranoMailer |
In the ‘deploy.rb’ file, add the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | require 'lib/cap_mailer' require 'etc' namespace :deploy do desc "Sends an email upon successful deployment" task :notify do mailer.send( :rails_env => rails_env, :deploy_to => deploy_to, :branch => branch, :application => application, :repository => repository, :deployment_time => Time.new.to_s, :deployer_username => Etc.getlogin) end end after "deploy", "deploy:notify" after "deploy:migrations", "deploy:notify" |

There is already CapGun for this – http://github.com/relevance/cap_gun – it even made 2009′s list of must-have plugins here: http://blog.thinkrelevance.com/2009/9/30/10-must-have-rails-plugins-and-gems-2009-edition