使用Capistrano将Rails应用程序部署到多台服务器

使用Capistrano将Rails应用程序部署到多台服务器

本文介绍了使用Capistrano将Rails应用程序部署到多台服务器-最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails应用程序,需要将其部署到3台服务器上:machine1.com,machine2.com和machine3.com。我希望能够一次将其部署到所有计算机,并分别部署到每台计算机。有人可以帮我解决骨架Capistrano配置文件/食谱吗?全部是在deploy.rb中还是应该在machine1.rb中进行扩展,等等?



我认为我在正确的方向上让Capistrano接受命令行参数,但是当我尝试在名称空间中设置角色时,它很ked。在拆分命令并进入每个主机后,我将'hosts = 1,2,3'作为参数传递,并将role:app / web / db设置为 machine#{host} .com | {} ...



无论如何,除了创建4个不同的deploy.rb文件并在每次运行cap:deploy之前重命名它之外,我都很困惑。我希望能够执行以下操作:

  cap deploy:machine1:latest_version_from_svn 
cap deploy:all_machines :latest:version_from_svn

只是不知道是否应该全部都在deploy.rb中

解决方案

它们都应该放在一个文件中。

解决方案

例如:

  set:应用程序, my-app 
set:存储库, git @ git。 my-git-host.com:my-app.git
设置:keep_releases,5
设置:deploy_via,:remote_cache
设置:git_enable_submodules,true
设置:scm, :git
设置:user,'您的用户在这里'

设置:deploy_to, /var/www/staging.mydomain.com
设置:branch,' staging'
set:rails_env,'staging'

作用:web, machine1.mydomain.com, machine2.mydomain.com, machine3.mydomain.com
角色:app, machine1.mydomain.com, machine2.mydomain.com, machine3.mydomain.com
角色:db, db.mydomain.com
#。 ..

您将看到仅指定了一个数据库服务器。这是运行迁移的机器。如果您只有一个数据库(该问题的答案为 99.9%的可能性为99.9%),请确保仅提供一个数据库。


I have a rails application that I need to deploy to 3 servers - machine1.com, machine2.com and machine3.com. I want to be able to deploy it to all machines at once and each machine individually. Can someone help me out with a skeleton Capistrano config file / recipe? Should it all be in deploy.rb or should I break it out in machine1.rb, etc?

I thought I was on the right track getting Capistrano to take in command line arguments, but it choked when I tried set the roles within the namespaces. I'd pass in 'hosts=1,2,3' as an argument and set the role:app/web/db to "machine#{host}.com" after splitting on the command and going into an each do |host| {}...

Anyway, other than creating 4 different deploy.rb files and renaming it before running cap:deploy each time, I'm stumped. I'd like to be able to do the following:

cap deploy:machine1:latest_version_from_svn
cap deploy:all_machines:latest:version_from_svn

Just don't know if it should all be in deploy.rb split up with namespaces or if it should be broken into multiple *deploy**.rb files.

解决方案

It should all go in one file. Here's an example:

set :application, "my-app"
set :repository,  "[email protected]:my-app.git"
set :keep_releases, 5
set :deploy_via, :remote_cache
set :git_enable_submodules, true
set :scm, :git
set :user, 'your-user-here'

set :deploy_to, "/var/www/staging.mydomain.com"
set :branch, 'staging'
set :rails_env, 'staging'

role :web, "machine1.mydomain.com", "machine2.mydomain.com", "machine3.mydomain.com"
role :app, "machine1.mydomain.com", "machine2.mydomain.com", "machine3.mydomain.com"
role :db, "db.mydomain.com"
# ...

You'll see that only one db server was specified. This is the machine the migrations will be run from. If you only have one database (99.9% chance of the answer to that question being YES), then make sure to only provide one.

这篇关于使用Capistrano将Rails应用程序部署到多台服务器-最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 05:42