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

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

问题描述

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天全站免登陆