bundler错误地尝试在生产中安装“开发”和“测试”组宝石

时间:2010-12-14 11:24:39

标签: ruby-on-rails gem bundle bundler unicorn

我有一个小型的网络应用程序,它使用了一堆宝石。其中一些仅用于testdevelopment环境。现在,当我尝试使用以下命令在生产服务器上启动独角兽时,它会失败。

unicorn_rails -E production -D -c config/unicorn.rb

我在日志文件中看到的错误是:

Refreshing Gem list
Could not find gem 'spork (>= 0.9.0.rc2, runtime)' in any of the gem sources listed in your Gemfile.
Try running `bundle install`.

我已经粘贴了我的gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.1'
gem 'unicorn'
gem 'mongoid', '>= 2.0.0.beta.19'
gem 'devise'
gem 'cancan'
gem 'haml', '>= 3.0.0'
gem 'bson'
gem 'bson_ext'
gem 'formtastic'
gem 'bluecloth'

group :production do
  gem 'capistrano'
end

group :development do
  gem 'haml-rails'
  gem 'hpricot', '0.8.2'
  gem 'ruby_parser', '2.0.5'
  gem 'less'
  gem 'rspec-rails', '>= 2.0.1'
end

group :development,:test do
  gem 'spork', '>=0.9.0.rc2'
  gem 'mongoid-rspec'
end

group :test do
  gem 'factory_girl_rails'
  gem 'autotest'
  gem 'cucumber-rails'
  gem 'cucumber'
  gem 'capybara'
  gem 'shoulda'
  gem 'database_cleaner'
  gem 'test_notifier'
  gem 'rspec', '2.0.1'
  gem 'launchy' 
end

Bundler应该检测正确的环境并忽略其他宝石,对吧?现在,我正在删除服务器上默认组中没有的所有行,以使其工作,但这是一个丑陋的黑客。

3 个答案:

答案 0 :(得分:53)

经过大量挖掘后,我找到了解决此问题的方法。我所要做的就是在启动服务器之前运行bundle install --without development test。这会在rails根目录中添加一个.bundle/config文件,其中包含行BUNDLE_WITHOUT: test:development。现在,无论何时运行bundle install或启动服务器,它都会忽略这些组。

From the documentation

  

Bundler CLI允许您指定   宝石捆绑的组列表   安装不应该与安装    - 没有选项。要指定要忽略的多个组,请指定一个列表   由空格分隔的组。

     

捆绑安装 - 没有测试捆绑   安装 - 没有开发测试   运行捆绑安装后--without   测试,捆绑者会记得你   最后排除了测试组   安装。下次你跑   捆绑安装,没有任何--without   选项,捆绑商会召回它。

     

另外,调用Bundler.setup时没有   参数或调用require   “bundler / setup”将设置所有组   除了你排除的那些    - 没有(因为它们显然不可用)。

答案 1 :(得分:4)

在我的情况下,它是从jenkins env安装宝石。所以我必须在capistrano中设置我自己的bundle_without变量。

的Gemfile

group :test, :development, :jenkins do  
  gem 'test-unit', '1.2.3'  
  gem 'rspec-rails'
end

deploy.rb

set :bundle_without, [:development, :test, :jenkins]

答案 2 :(得分:-2)

您尚未定义生产组=)

相关问题