bundler错误地尝试安装“开发”和“测试”生产中的群体宝石 [英] bundler incorrectly trying to install "development" and "test" group gems in production

查看:139
本文介绍了bundler错误地尝试安装“开发”和“测试”生产中的群体宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  unicorn_rails -E生产-D -c config / unicorn.rb 

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

 刷新宝石列表
找不到宝石'spork(> = 0.9.0.rc2,运行时)'您的Gemfile中列出的宝石来源。
尝试运行`bundle install`。

我粘贴了下面的gemfile:

  source'http://rubygems.org'

gem'rails','3.0.1'
gem'独角兽'
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:开发do
gem'haml-rails'
gem'hpricot','0.8.2'
gem' ruby_parser','2.0.5'
gem'less'
gem'rspec-rails','> = 2.0.1'
结束

组合:开发,: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'
结束



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

解决方案

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



从文档


Bundler CLI允许您指定
a列表,其中gem bundle
install不应该使用
--without选项进行安装。要指定多个要忽略的组,请指定由空格分隔的
组列表。



捆绑安装 - 无测试捆绑
安装 - 无出局开发测试
在运行软件包安装 - 没有执行
测试之后,bundler会记住您在最后一次
安装中排除了测试组的
。下次运行
bundle install时,如果没有任何 - 没有
选项,bundler会记得它。

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



I have a small web app, which uses a bunch of gems. Some of them are only used for test and development environments. Now, when I try to start unicorn on the production server using the following command, it fails.

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

The error I see in the log files is:

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`.

I've pasted my gemfile below:

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 is supposed to detect the right environment and ignore the other gems, right? Right now, I am deleting all the lines which are not in the default group on the server to get this working, but that's an ugly hack.

解决方案

After a lot of digging I found the fix for this issue. All I had to do was run bundle install --without development test before starting the server. This adds a .bundle/config file in the rails root with the line BUNDLE_WITHOUT: test:development . Now whenever you run bundle install or start the server it'll ignore those groups.

From the documentation

The Bundler CLI allows you to specify a list of groups whose gems bundle install should not install with the --without option. To specify multiple groups to ignore, specify a list of groups separated by spaces.

bundle install --without test bundle install --without development test After running bundle install --without test, bundler will remember that you excluded the test group in the last installation. The next time you run bundle install, without any --without option, bundler will recall it.

Also, calling Bundler.setup with no parameters, or calling require "bundler/setup" will setup all groups except for the ones you excluded via --without (since they are obviously not available).

这篇关于bundler错误地尝试安装“开发”和“测试”生产中的群体宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆