Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Capistrano set variables based on a role?

I am trying to use Capistrano to deploy to two different roles, using Bundler on both, however the Bundler command and flags will be different. Is it possible to set variables that are specific to a role? Either something like:

set :bundle_flags, "--deployment --quiet", :role => "web"

or:

role :web do
  set :bundler_cmd, "--deployment --quiet"
end

Neither of those two options work, of course. Is there a way to accomplish this, or something like it?

like image 284
silvamerica Avatar asked Nov 14 '22 04:11

silvamerica


1 Answers

There is no way to have custom variable values per role.

You can instead use the multistage extension from capistrano-ext to have different stages for your two different roles.

If different stages doesn't make sense for your deployment, you could write your own bundle:install task and run different commands based on roles

run "bundle --deployment --quiet", :roles => :web
run "bundle --deployment", :roles => :app

As noted in the comment below, this approach, however, will raise errors if the role does not have a server defined. It will also run each command serially. To work around both those issues, use the parallel helper.

parallel do |session|
   session.when 'in?(:web)', "bundle --deployment --quiet"
   session.when 'in?(:app)', "bundle --deployment"
end
like image 163
Doug Barth Avatar answered Dec 06 '22 23:12

Doug Barth