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

问题描述 投票:23回答:3

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

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

ruby-on-rails gem bundle bundler unicorn
3个回答
53
投票

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

From the documentation

Bundler CLI允许您指定其gems包安装不应使用--without选项安装的组列表。要指定要忽略的多个组,请指定由空格分隔的组列表。

bundle install --without test bundle install - withoutout development test运行bundle install --without test后,bundler会记住你在上次安装中排除了测试组。下次运行bundle install时,没有任何--without选项,bundler会调用它。

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


4
投票

在我的情况下,它是从jenkins环境安装宝石。所以我必须在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
投票

您尚未定义生产组=)

© www.soinside.com 2019 - 2024. All rights reserved.