Search code examples
deploymentamazon-web-servicescapistranocloud-hostingrackspace-cloud

Capistrano - How to deploy to multiple cloud servers


I've heard that Capistrano supports deployment to multiple servers, but I haven't found a practical way to set it up. When I say multiple servers I mean servers running the same application in a production environment. At any time I would like to deploy to 5 or 10 servers if that is what I'm currently using.

Thank you.


Solution

  • Using multiple servers is one of the main reasons to use capistrano versus just doing things by hand.

    Your deploy.rb just needs to define what actions should be performed on what servers, which is done by setting which servers belong to which roles. You can create your own roles, but the built-in capistrano recipes expect you to define 3 roles:

    • app: where your application code runs
    • web: web front ends
    • db: where migrations are run

    It's not uncommon for these 3 to be synonymous: if you have a bunch of identical servers all running apache + passenger then they are all app and web servers. One of them needs to be given the db role.

    You define roles in your deploy.rb file. At its simplest this is just a list of ip addresses or host names:

    role :app, [192.168.1.1,192.168.1.2]
    

    It can also be a block. For example when deploying to ec2 you might insert an api call that retrieves the list of servers to deploy to. I usually do this by assigning tags to servers, in which case you might have

    role :app do
      ec2.instances.tagged('app').map(&:ip_address)
    end
    

    to have that role map to the ec2 instances with the app tag (capistrano caches this information and will only execute your block once)