Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Capistrano tasks only for certain roles

My project has a multi-step pipeline that includes some steps like Crawling, NLP, etc, but I'll just refer to them as Step1, Step2, etc. Additionally I want to be able to deploy to different environments (dev, prod, etc).

I figure I'll use multistage component for Capistrano in order to deploy to the different environments (e.g. cap dev deploy vs cap prod deploy).

It also seems to make intuitive sense to use roles for each pipeline step. However, each step runs fairly independently of the rest of the pipeline, so each step can be restarted/deployed independently of the other steps. It doesn't seem like Capistrano explicitly supports running tasks only for a specific role. What's a good way to do this?

Is the best way of doing this defining tasks specifically for each role? What if there are some tasks common between roles? Maybe helper methods is the answer there?

like image 398
JZC Avatar asked Jun 29 '11 23:06

JZC


3 Answers

Not sure this is exactly what you are looking for, but when I want to do something just to a particular role, I use the capistrano shell. For example, let's say I want to deploy but only to my app servers, I might do the following:

cap production shell
cap>with app
cap>!deploy #or any other cap task you have

You can also scope by machine if you want. Again:

cap production shell
cap>on <machine name or ip>
cap>!deploy #or any other cap task you have

Hope it helps,

Scott

like image 183
Scott Tamosunas Avatar answered Oct 20 '22 00:10

Scott Tamosunas


If you want to run a capistrano task from the command line, but only for a subset of defined roles, you can use the ROLES parameter.

The command below executes the task category:task only for role was:

cap ROLES=was category:task

The ROLES parameter is multivalued, so you can add more roles separated by a comma:

cap ROLES=was,db category:task

For more details, you can refer to the invoke documentation

like image 20
Nicolas Colomer Avatar answered Oct 20 '22 00:10

Nicolas Colomer


Check this discussion Creating a Capistrano task that performs different tasks based on role

task :stop_memcached, :roles => :memcache do 
...
end
like image 36
irfn Avatar answered Oct 19 '22 23:10

irfn