Make your Capistrano Growl
Last week, while trying to find some fancy recipes and snippets for Capistrano, I had an idea to use Growl for deployment notifications to let everyone important know about any deployments or rollbacks.
After digging around the web a bit, I discovered a sweet ruby gem called ruby-growl by Eric R. Hodel. Around 10-15 minutes later I ended up with the code below in our deployment recipes file:
require 'ruby-growl'
# define two types of messages we are going to use
GROWL_TYPES = {:deploy => "Capistrano deploy", :rollback => "Capistrano rollback"}
# define hosts who will receive messages
GROWL_HOSTS = ["192.168.1.100", "192.168.1.101", "192.168.1.102"]
after "deploy" do
GROWL_HOSTS.each do |host|
Growl.new(host, "Capistrano", GROWL_TYPES.values).
notify(GROWL_TYPES[:deploy], "Message from Capistrano", "#{application} deployed to #{stage}")
end
end
after "rollback" do
GROWL_HOSTS.each do |host|
Growl.new(host, "Capistrano", GROWL_TYPES.values).
notify(GROWL_TYPES[:rollback], "Message from Capistrano", "#{application} rollbacked at #{stage}")
end
end
rescue
# do nothing (you can of course handle any exceptions thrown here if you want to
end
It defines two hooks: after deploy and after rollback and sends predefined messages on each event to given IP addresses.
The ruby-growl gem has to be installed on any computer where the deploy process is ran on, as notification sending is invoked on the local computer, not on the deployment target one.
Theoretically these messages could also be sent from the remote (deployment target) computer, this can be easily achieved doing something like this:
GROWL_HOSTS.each do |host|
run "growl -H #{host} -m 'Message from Capistrano: #{application} deployed to #{stage}'"
end
end
This example makes use of the nice command line feature of ruby-growl which is also bundled with the gem.
As a prequisite each target computer is required to have Growl installed with “Listen for incoming notifications” option enabled.
Comments are closed here.