How do I separate roles in Capistrano?
I am trying to deploy my RoR application with Capistrano. Everything was fine until I introduced another role in my Capistrano config, the :web role, which supposedly would be my HTTP/reverse proxy server.
My understanding is that the :app role should refer to the application server (thin, mongrel, whatever) and the :web role should refer to the frontend server (nginx, apache), so I'm rather confused by the choice of running all tasks on all roles, even though开发者_如何学C capistrano separates them by default.
Right now my problem is that I'm not able to make the deploy:update_code run only on the servers that have an :app role, for example, and capistrano errors out because it tries to run update_code on my web server, where I didn't even install git (I don't need it ...). Has anyone suceeded in doing that? Can someone share the code?
TIA, ngw
This problem arises because the built-in tasks don't respect the role limitations on your custom tasks that invoke them, i.e.,
task my_task, :roles => :web do
run "some command" # will only be executed on servers with the :web role
update # will be executed for all roles
end
You will, as you intuited, have to override all the built-in tasks. Or you can try Rodney Koch's patch to Capistrano.
Are you explicitly specifying the role in the task name?
task :task_A, :roles => :web do
#do stuff here
end
task :task_B, :roles => :app do
#do stuff here
end
精彩评论