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

9

根据Bundler文档,在使用Capistrano部署时,只需插入以下命令即可安装所有必要的bundle:

require 'bundler/capistrano' # siehe http://gembundler.com/deploying.html

在他的deploy.rb文件中。然后,在部署时,Capistrano会调用它。

  * executing "bundle install --gemfile .../releases/20110403085518/Gemfile \
    --path .../shared/bundle --deployment --quiet --without development test"

这个很好。

然而,在我们的生产服务器上,我们有一个分离于真实网站的暂存设置,我们在那里使用(克隆和防火墙)真实生产数据测试新的应用程序发布。在那里,我们需要安装测试和开发gem。

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

谢谢!

3个回答

19

编写不同的任务肯定会使它简单:

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

然而,如果你想使用命令行选项,你可以根据提供的值进行切换:

cap deploy target=staging

并且在你的deploy.rb文件中,你可以使用该选项值:

if target == "staging"
  set :bundle_without, [:test]
  # do other stuff here
end

还有一种更为“正式”的配置对象可以使用。我在这里找到了一个参考链接:http://ryandaigle.com/articles/2007/6/22/using-command-line-parameters-w-rake-and-capistrano


3
我使用一个称为'multistage'的Capistrano扩展,它允许指定不同的目标环境(在我的情况下是staging和production)。设置 :bundle_without 暂时解决了我的问题。谢谢! - Jens
自从一年前回答这个问题以来,我现在也使用了capistrano-multistage扩展宝石。 - Scott

3

0

我没有独立确认的设置,但是RAILS_ENV='development'可以吗?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接