我有一个小型的Web应用程序,它使用了一堆宝石。其中一些仅用于 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

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

有帮助吗?

解决方案

经过大量挖掘,我找到了这个问题的修复程序。我要做的就是跑步 bundle install --without development test 启动服务器之前。这添加了 .bundle/config 在铁路上归档与线条 BUNDLE_WITHOUT: test:development 。现在每当你跑步 bundle install 或启动服务器,它将忽略这些组。

从文档

Bundler CLI允许您指定一组GEMS Bundle安装的组列表,不应使用 - 无需选项安装。要指定多个要忽略的组,请指定由空格分开的组列表。

捆绑安装 - 无测试捆绑包安装 - 无需开发测试在运行捆绑包安装之后 - 没有测试,邦德勒会记住您在上次安装中排除了测试组。下次您运行捆绑包安装时,没有任何 - 没有选项,邦德勒会回忆起它。

另外,请致电Bundler.setup没有参数,或者呼叫要求“ Bundler/Setup”设置所有组,除了您通过 - 无需 - 无需 - 显然是不可用的组。

其他提示

就我而言,它是从詹金斯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]

您尚未定义生产组=)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top