Sambhav Sharma
Sambhav Sharma

Reputation: 5860

Capistrano deploy one server at a time

I am using capistrano for our RAILS deployment. We want to deploy to one server first, and after deployment is finished on the first server, then we want to start deployment on second server. We do not want restarting in sequence with delay. We want to have complete deployment one at a time. So far I have this:

namespace :deploy do
  task :sequence do
    on roles(:app), in: :sequence do |host|
      invoke 'deploy'
    end
  end
end

The problem is with invoke 'deploy' It calls deploy for all the app servers which in turns deploy in parallel.

Finally How Do I invoke deploy task for a specific host?

Upvotes: 1

Views: 1267

Answers (2)

will_in_wi
will_in_wi

Reputation: 2653

If I had that requirement, I'd probably script it. You can run Capistrano with the --hosts parameter to define which of the servers you described in your stage file (config/deploy/dev|stage|prod|somethingelse.rb) you actually want to run the command against. This can take two forms. Let's say I have three servers, test1, test2, and prod1. I can run it with a list, like cap prod --hosts=test1,test2 deploy and only test1 and test2 will receive the deployment. You can also use a regular expression to achieve the same thing, like cap prod --hosts=^test deploy.

This is documented here: http://capistranorb.com/documentation/advanced-features/host-filtering/

With this in mind, I'd probably write a script (or Makefile) which runs capistrano N time, for a different server each time.

Upvotes: 1

RAJ
RAJ

Reputation: 9747

Following should help you to run the deploy task in sequential mode:

task :my_task, roles: :web do
  find_servers_for_task(current_task).each do |server|
    run "YOUR_COMMAND", hosts: server.host
  end
end

Upvotes: 1

Related Questions