Capistrano - How to deploy to multiple cloud servers

前端 未结 2 1347
北海茫月
北海茫月 2021-02-06 16:44

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 sa

相关标签:
2条回答
  • 2021-02-06 17:16

    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)

    0 讨论(0)
  • 2021-02-06 17:27

    I had to use a different syntax with Rails 4.

    role :app, %w{s01.app.com s02.app.com}
    role :web, %w{s01.web.com s02.web.com}
    
    0 讨论(0)
提交回复
热议问题