April 4, 2013 - No Comments!

Don Your Cape: Becoming a Deploy Hero

hero.and.lolcat

It's a day like any other. You're sitting at your desk, building a web application in Rails, when suddenly disaster strikes! You find yourself in need of something that Rails simply can't do on its own. Maybe you need to run Resque or Delayed::Job to add some asynchronous behavior to your app. Maybe you need to add a daemon or a cron job of your own for an even more customized process. Whatever the case, you know that you're going to need to write and run some rake tasks.

You're making good progress, but you find yourself edging closer and closer to dangerous, forbidden territory—the Capistrano deploy scripts! You've been warned not to touch them. You've heard the whispered rumors of a young developer, his sanity claimed all too early by the tangled code lurking deep within those recipes. You have a decision to make...

Do you choose Option A, retreating to the safety of your application code? After all, you can always ssh onto the server after each deploy and do whatever cleanup you need to do. It'll only take a few minutes, right? Besides, those recipes are just so...scary.

No! You've come this far already, there's no turning back now! You've taken a few hesitant steps and peeked around a corner or two; it doesn't look that bad in here. So maybe you'll choose Option B, and define your own Capistrano tasks! You move ahead, and end up with something that looks like this:

It's not...terrible. In fact, it's okay. Sure, you're manually defining a Capistrano task for each Rake task you need to run on deploy, but at least you're using bundler, and you even made your rake calls nice and DRY!

But what if I told you there's an Option C? What if I told you that there's a way you can become a deploy hero, striking down your recipe complexity once and for all? There is.

Introducing: cape! By day, a must-have fashion accessory for superheroes of all ilk; by night, a small gem dedicated to cleaning up repetition in your deploy files. Add cape to your gemfile, and the same deploy script from above is transformed into the following:

Cape helps keep your deploy scripts nice and clean, by allowing you to write your rake tasks once and run them on your remote servers painlessly via Capistrano. It's the Robin to your Batman, tackling hordes of henchmen so you can focus on bringing down the big baddie. It's the Arthur to your Tick, bringing a voice of reason and pragmatism to temper your cavalier sense of adventure. It's the Snarf to your Lion-O...okay, maybe not so much.

If you ever find yourself needing to run rake tasks remotely, give cape a shot.

Image by Andrew Horner, 2013

Published by: Andrew Horner in Developers
Tags: ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.