[ANN] Capistrano Mailer Plugin

24 views
Skip to first unread message

Peter Boling

unread,
Feb 4, 2008, 12:23:43 PM2/4/08
to Capistrano, bmis...@gmail.com
I have written a capistrano plugin that will send emails when new
releases are deployed using capistrano. It is released under the MIT
license.

Here's the readme:

Capistrano Mailer
=================

Ever wanted to be emailed whenever someone on the team does a cap
deploy of trunk or some tag to some server.
Wouldn't it be nice to know about it every time a release was
deployed? For large rails projects this type of coordination is
essential,
and this plugin makes sure everyone on the need to know list is
notified when something new is deployed.

This plugin is an extension to Capistrano.

That means it registers itself with Capistrano as a plugin and is
therefore available to call in your recipes.

Home Page
=========

http://code.google.com/p/capistrano-mailer/

Installation
============

./script/plugin install http://capistrano-mailer.googlecode.com/svn/trunk/capistrano_mailer

Usage
=====

1. Install the plugin.

2. Add this line to the top of your deploy.rb:

require 'vendor/plugins/capistrano_mailer/lib/capistrano_mailer'

3. Add a cap_mailer_settings.rb file to your config/ directory:

require 'vendor/plugins/capistrano_mailer/lib/cap_mailer'

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "mail.default.com",
:port => 25,
:domain => 'default.com',
:perform_deliveries => true,
:user_name => "rele...@default.com",
:password => "mypassword",
:authentication => :login }
ActionMailer::Base.default_charset = "latin1"

CapMailer.recipient_addresses = ["de...@default.com"]
CapMailer.sender_address = %("Capistrano Deployment"
<rele...@default.com>)
CapMailer.email_prefix = "[MYSITE-CAP-DEPLOY]"
CapMailer.site_name = "MySite.com"
CapMailer.email_content_type = "text/html"

4. Add these two tasks to your deploy.rb:

namespace :show do
desc "Show some internal Cap-Fu: What's mah NAYM?!?"
task :me do
set :command, task_call_frames.first.task.fully_qualified_name
puts "echo 'Running #{command} task'"
end
end

namespace :deploy do
...

desc "Send email notification of deployment"
task :notify, :roles => :app do
show.me
mailer.send(rails_env, repository, command, deploy_to, host)
end

...
end

Make sure you've defined rails_env, repository, deploy_to and host.
command is defined by the show:me task above.

The only parameters to mailer.send that are required are rails_env,
repository, command and deploy_to.
The complete set of possible parameters is:
mailer.send(rails_env, repository, command, deploy_to, host = nil,
ip_address = nil, output = nil)

If anyone has a cool way of recording the output into a capistrano
accessible variable,
so that it can be shoved into the release email that would be an
excellent contribution!

5. Then add the hook somewhere in your deploy.rb:

after "deploy", "deploy:notify"

6. Enjoy and Happy Capping!

----------------------------------------------------------------------------------
This plugin is a creation of Sagebit, LLC. (http://www.sagebit.com)

Author: Peter Boling, peter.boling at gmail dot com

Copyright (c) 2007 Sagebit LLC, released under the MIT license

Peter Boling

unread,
Mar 26, 2008, 2:00:23 PM3/26/08
to Capistrano
I have just released a new version of Capistrano Mailer, v1.0.1.

Changes are:

- Now works with Capistrano 2.2.0 or 2.1.0 (previously ONLY Capistrano
2.1.0)
- I have verified that it does work with Deprec2 Preview Release

Homepage:
http://code.google.com/p/capistrano-mailer/

Install:
./script/plugin install http://capistrano-mailer.googlecode.com/svn/trunk/capistrano_mailer

Download:
http://capistrano-mailer.googlecode.com/files/capistrano_mailer_v_1.0.1.zip

David Masover

unread,
Mar 26, 2008, 2:10:35 PM3/26/08
to capis...@googlegroups.com
Looks very interesting...  but it looks like a Rails/Capistrano plugin, not purely Capistrano.

I'm also curious, how do you decide when to send the email?

I've got a hook sending mail after deploy:symlink, but it's a bit simpler; it just runs the "sendmail" command on the remote host. (It's actually Postfix, but it works well enough.)

Peter Boling

unread,
Mar 27, 2008, 10:04:08 AM3/27/08
to Capistrano
> Looks very interesting... but it looks like a Rails/Capistrano plugin, not
> purely Capistrano.

Correct, it is both a Rails plugin and a Capistrano plugin. It
leverages ActionMailer for easy setup. It might be easy to unhook
from the rest of rails, but I have no reason to try... all I do is
rails. All day, all night, every day ;)

> I'm also curious, how do you decide when to send the email?

You add a task to your deploy script, I call mine deploy:notify and
add a hook to it wherever you want. I hook mine so it is the last
thing that runs, so I know the deploy actually did all work.
Basically it gives you a method that you could call from any task, so
you don't really need deploy:notify, or a hook. You could just call
the method from another pre-existing task.

> I've got a hook sending mail after deploy:symlink, but it's a bit simpler;
> it just runs the "sendmail" command on the remote host. (It's actually
> Postfix, but it works well enough.)

Yeah, that is the idea behind the pastie Mislav posted that is linked
from the plugin homepage. I don't like re-rolling my own stuff every
time I do a new site though, so I prefer having a shake 'n bake
solution that I can reuse everywhere with little or no change.

David Masover

unread,
Mar 27, 2008, 2:03:33 PM3/27/08
to capis...@googlegroups.com
On Thu, Mar 27, 2008 at 9:04 AM, Peter Boling <peter....@gmail.com> wrote:


Yeah, that is the idea behind the pastie Mislav posted that is linked
from the plugin homepage.  I don't like re-rolling my own stuff every
time I do a new site though, so I prefer having a shake 'n bake
solution that I can reuse everywhere with little or no change.


Right, and I don't mean to imply it's not useful.

Right now, we're hosting everything on Amazon EC2, and it doesn't seem likely we'll be putting anything on a purely hosted environment anytime soon. And anywhere I have root, I can setup Postfix relatively quickly -- and I want to do that anyway, so I get cron emails.
Reply all
Reply to author
Forward
0 new messages