Capistrano - How to deploy to multiple cloud servers

淺唱寂寞╮ 提交于 2019-12-20 16:49:14

问题


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.


回答1:


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)




回答2:


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}


来源:https://stackoverflow.com/questions/11587915/capistrano-how-to-deploy-to-multiple-cloud-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!