I already have a deploy.rb that can deploy my app on my production server.
My app contains a custom rake task (a .rake file in the lib/tasks directory).
I'd like to create a cap task that will remotely run that rake task.
I already have a deploy.rb that can deploy my app on my production server.
My app contains a custom rake task (a .rake file in the lib/tasks directory).
I'd like to create a cap task that will remotely run that rake task.
If you want to be able to pass multiple arguments try this (based on marinosbern's answer):
Then you can run a task like so:
cap production invoke["task","arg1","arg2"]
A little bit more explicit, in your
\config\deploy.rb
, add outside any task or namespace:Then, from
/rails_root/
, you can run:Most of it is from above answer with a minor enhancement to run any rake task from capistrano
Run any rake task from capistrano
There's an interesting gem cape that makes your rake tasks available as Capistrano tasks, so you can run them remotely.
cape
is well documented, but here's a short overview on how to set i up.After installing the gem, just add this to your
config/deploy.rb
file.Now, you can run all you
rake
tasks locally or remotely throughcap
.As an added bonus,
cape
lets you set how you want to run your rake task locally and remotely (no morebundle exec rake
), just add this to yourconfig/deploy.rb
file:This also works:
More info: Capistrano Run
So I have been working on this. it seams to work well. However you need a formater to really take advantage of the code.
If you don't want to use a formatter just set the log level to to debug mode. These semas to h
Cap Stuff
This is the formatter I built to work with the code above. It is based off the :textsimple built into the sshkit but it is not a bad way to invoke custom tasks. Oh this many not works with the newest version of sshkit gem. I know it works with 1.7.1. I say this because the master branch has changed the SSHKit::Command methods that are available.