The One Where You Run Rake Commands With Capistrano
Simple Enough, right? Run some rake tasks on your servers. You think it’d be built in, but nope. Drink some sake and let capistrano do the work!
First Off, Sake is not sake
Defunkt wrote sake in ought-eight (2008) for system wide rake tasks. This isn’t it; this is just a file, name it what you want.
Background
I’ll use rake tasks to do data-migrations that I don’t want to stick around in db/migrations. Or to do one-off things like re-process images.
But it’s not all that awesome to actually run those things in production when you need to. Here’s a way!
Then, make sure you require it
And that’s it! Now, when you want to run that code, say to migrate a database:
cap sake:invoke task="db:migrate"
This is not mind-blowing, but it’s not very obvious for new deployers, so I wanted to add it here for the googlers.
Naming Notes
Don’t name your task rake – newer versions of rake (0.9.2) are not pleased with that. That’s how I ended on sake. (rake => sake).
Credit
This answer on Stack Overflow had some good stuffs. I modified from there.