Minimal Rake Deploy Task

A great professor that I had during my studies at JTH always said that while a Volvo kept on running smoothly, a Ferrari would need service every 500 kilometer just because of its refined design of the engine and other parts.

I think the same goes for code. Basically, whenever you bring in an extra third party library or a gem as we, ruby people, might call them, you tend to add complexity and dependencies.

Skipping Capistrano for small projects

Take Capistrano for instance. A great gem for deploying apps to remote servers. It has a ton of support for different scm's and stuff and does a great job doing what it is supposed to do. However, when analysing what I tend to use it for nowadays, I realized that I basically only push production code to a bunch of servers. I never rollback, as all the apps I'm dealing with has staging environments, where those issues will be noticed first.

So why not skip Capistrano and go with good old Rake instead? This even saves you time on each deploy:

desc "Deploy the application"
task :deploy do
  commands = [
    "cd /apps/my_app",
    "git fetch",
    "git reset --hard origin/production",
    "git submodule init",
    "git submodule update",
    "mkdir -p tmp",
    "touch tmp/restart.txt"
  exec "ssh deploy@server.remote '#{commands.join(" && ")}'"

Put that in your Rakefile and you're good to go. Simple, elegant, flexible - just the way you want it!