Ruby on Rails:Bundler和Capistrano:指定在部署时要排除哪些组(开发,测试)

Jen*_*ens 8 production capistrano ruby-on-rails staging bundler

Bundler文档说,为了在通过Capistrano部署时安装所有必需的bundle,只需插入即可

require 'bundler/capistrano' # siehe http://gembundler.com/deploying.html
Run Code Online (Sandbox Code Playgroud)

在他的deploy.rb中.然后,在部署时,Capistrano打电话

  * executing "bundle install --gemfile .../releases/20110403085518/Gemfile \
    --path .../shared/bundle --deployment --quiet --without development test"
Run Code Online (Sandbox Code Playgroud)

这很好用.

但是,我们的生产服务器上有一个分段设置,与真实的实时站点隔离,我们在那里测试带有(克隆和防火墙)实时生产数据的新应用程序版本.在那里,我们需要安装测试和开发宝石.

如何在此处指定capistrano命令行?是否有我可以使用的参数,或者我是否需要设置自己的capistrano任务来覆盖Bundler?

谢谢!

Sco*_*ott 18

编写不同的任务肯定会保持简单:

task :production do
  # These are default settings
  set :bundle_without, [:development, :test]
end

task :staging do
  set :bundle_without, [:test]
  # set :rails_env, 'staging'
end
Run Code Online (Sandbox Code Playgroud)

但是,如果要使用命令行选项,可以打开提供的值:

cap deploy target=staging
Run Code Online (Sandbox Code Playgroud)

在deploy.rb文件中,您可以使用选项值:

if target == "staging"
  set :bundle_without, [:test]
  # do other stuff here
end
Run Code Online (Sandbox Code Playgroud)

您还可以使用更"正确"的配置对象.我在这里找到了它的参考:http://ryandaigle.com/articles/2007/6/22/using-command-line-parameters-w-rake-and-capistrano

  • 我使用名为'multistage'的Capistrano扩展,它允许指定不同的目标环境(在我的例子中,分段和生产).设置:bundle_without现在解决了我的问题.谢谢! (2认同)