views:

202

answers:

2

I have a Capistrano deploy file (Capfile) that is rather large, contains a few namespaces and generally has a lot of information already in it. My ultimate goal is, using the Tinder gem, paste the output of the entire deployment into Campfire. I have Tinder setup properly already.

I looked into using the Capistrano capture method, but that only works for the first host. Additionally that would be a lot of work to go through and add something like:

output << capture 'foocommand'

Specifically, I am looking to capture the output of any deployment from that file into a variable (in addition to putting it to STDOUT so I can see it), then pass that output in the variable into a function called notify_campfire. Since the notify_campfire function is getting called at the end of a task (every task regardless of the namespace), it should have the task name available to it and the output (which is stored in that output variable). Any thoughts on how to accomplish this would be greatly appreciated.

+1  A: 

It's sort of a hackish means of solving your problem, but you could try running the deploy task in a Rake task and capturing the output using %x.

# ...in your Rakefile...
task :deploy_and_notify do
  output = %x[ cap deploy ]  # Run your deploy task here.
  notify_campfire(output)
  puts output                # Echo the output.
end
Oshuma
The majority of this code isn't even Ruby. Most of what's being deployed is either Perl or Python. I know that doesn't negate using rake, but it's not really in the same spirit.
Eric Lubow
The code above is just an example. You can write that same wrapper script in pretty much any language.
Oshuma
The idea is to get it only within the Capfile itself. I want to have access to it from a variable within the Capfile so I can send the contents of that variable to Campfire (the chatroom).
Eric Lubow
You might want to try my railsless deploy gem, it's designed for your usecase. http://github.com/leehambley/railsless-deploy/
Beaks
You can setup Capistrano task dependencies (much like Rake). Capture the output in an instance variable to be used in a later task.
Oshuma
+1  A: 

Hi,

I recommend not messing with the Capistrano logger, Instead use what unix gives you and use pipes:

$ cap deploy | my_logger.rb

Where your logger reads STDIN and STDOUT and both records, and pipes it back to the appropriate stream.

For an alternative, the Engineyard cap recipies [ http://github.com/engineyard/eycap ] have a logger [ http://github.com/engineyard/eycap/blob/master/lib/eycap/lib/ey_logger.rb ] – this might be a useful reference if you do need to edit the code, but I recommend not doing.

Beaks