Bundler在排除的组中为gems引发GemNotFound错误(使用,即`--without test`)

时间:2016-05-09 15:50:44

标签: ruby-on-rails ruby rubygems bundler

使用bundle install --without test安装gem时,然后使用bundle exec unicorn -c ./config/unicorn.rb -E development启动我的服务器,对于只在test环境中依赖的gem,bundler会抛出gem not found错误。我已经尝试明确指示bundler仅在boot.rb中使用默认和环境特定的gems:

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

# Set up gems listed in the Gemfile.
if File.exists?(ENV['BUNDLE_GEMFILE'])
  require 'bundler'
  Bundler.setup(:default, ENV["RAILS_ENV"])
end

但错误仍然存​​在。我已经验证服务器是在预期的环境中运行的,但我仍然会收到类似于/var/lib/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/spec_set.rb:95:in 'block in materialize': Could not find io-like-0.3.0 in any of the sources (Bundler::GemNotFound)的错误,用于测试特定的gem。我还明确地将io-like gem添加到Gemfile中的默认gem中,以测试这是否是io-like特定的问题,但是对于不同的仅测试gem,我仍然会得到相同的错误。

有什么想法可以在这里发生什么?

我已将下面的Gemfile以及我的Gemfile.lock包含在上下文中。

的Gemfile

source 'https://rubygems.org'

ruby '2.3.0'

gem 'rails', '4.2.6'

gem 'therubyracer', platforms: :ruby
gem 'unicorn'

gem 'pg'

# API helpers
gem 'gon'
gem 'jbuilder', '~> 2.0'
gem 'responders'
gem 'kaminari'

# asset helpers
gem "sprockets-es6"
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'

# Model helpers
gem 'bcrypt', '~> 3.1.11'
gem 'redcarpet'
gem 'carrierwave'
gem 'carrierwave-dropbox'
gem "fog-aws"

gem 'sendgrid'

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'factory_girl_rails', require: false
  gem 'jasmine-rails'
end

group :test do
  gem 'rspec-rails'
  gem 'database_cleaner'
  gem 'capybara'
  gem 'selenium-webdriver'
  gem 'chromedriver-helper'
  gem 'timecop'
end

Gemfile.lock的

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.2.6)
      actionpack (= 4.2.6)
      actionview (= 4.2.6)
      activejob (= 4.2.6)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.6)
      actionview (= 4.2.6)
      activesupport (= 4.2.6)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (4.2.6)
      activesupport (= 4.2.6)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    activejob (4.2.6)
      activesupport (= 4.2.6)
      globalid (>= 0.3.0)
    activemodel (4.2.6)
      activesupport (= 4.2.6)
      builder (~> 3.1)
    activerecord (4.2.6)
      activemodel (= 4.2.6)
      activesupport (= 4.2.6)
      arel (~> 6.0)
    activesupport (4.2.6)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    archive-zip (0.7.0)
      io-like (~> 0.3.0)
    arel (6.0.3)
    babel-source (5.8.19)
    babel-transpiler (0.7.0)
      babel-source (>= 4.0, < 6)
      execjs (~> 2.0)
    bcrypt (3.1.11)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    builder (3.2.2)
    byebug (5.0.0)
      columnize (= 0.9.0)
    capybara (2.4.4)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    carrierwave (0.10.0)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
      json (>= 1.7)
      mime-types (>= 1.16)
    carrierwave-dropbox (1.2.1)
      carrierwave (~> 0.9)
      dropbox-sdk (~> 1.6)
    childprocess (0.5.6)
      ffi (~> 1.0, >= 1.0.11)
    chromedriver-helper (1.0.0)
      archive-zip (~> 0.7.0)
      nokogiri (~> 1.6)
    columnize (0.9.0)
    concurrent-ruby (1.0.2)
    database_cleaner (1.4.1)
    debug_inspector (0.0.2)
    diff-lcs (1.2.5)
    dropbox-sdk (1.6.5)
      json
    erubis (2.7.0)
    excon (0.49.0)
    execjs (2.5.2)
    factory_girl (4.5.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.5.0)
      factory_girl (~> 4.5.0)
      railties (>= 3.0.0)
    ffi (1.9.10)
    fog-aws (0.9.2)
      fog-core (~> 1.27)
      fog-json (~> 1.0)
      fog-xml (~> 0.1)
      ipaddress (~> 0.8)
    fog-core (1.37.0)
      builder
      excon (~> 0.45)
      formatador (~> 0.2)
    fog-json (1.0.2)
      fog-core (~> 1.0)
      multi_json (~> 1.10)
    fog-xml (0.1.2)
      fog-core
      nokogiri (~> 1.5, >= 1.5.11)
    formatador (0.2.5)
    globalid (0.3.6)
      activesupport (>= 4.1.0)
    gon (6.0.1)
      actionpack (>= 3.0)
      json
      multi_json
      request_store (>= 1.0)
    i18n (0.7.0)
    io-like (0.3.0)
    ipaddress (0.8.3)
    jasmine-core (2.3.4)
    jasmine-rails (0.10.8)
      jasmine-core (>= 1.3, < 3.0)
      phantomjs (>= 1.9)
      railties (>= 3.2.0)
      sprockets-rails
    jbuilder (2.3.1)
      activesupport (>= 3.0.0, < 5)
      multi_json (~> 1.2)
    json (1.8.3)
    kaminari (0.16.3)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
    kgio (2.9.3)
    libv8 (3.16.14.11)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.4)
      mime-types (>= 1.16, < 4)
    mime-types (3.0)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0221)
    mini_portile2 (2.0.0)
    minitest (5.8.4)
    multi_json (1.11.2)
    nokogiri (1.6.7.2)
      mini_portile2 (~> 2.0.0.rc2)
    pg (0.18.2)
    phantomjs (1.9.8.0)
    rack (1.6.4)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.6)
      actionmailer (= 4.2.6)
      actionpack (= 4.2.6)
      actionview (= 4.2.6)
      activejob (= 4.2.6)
      activemodel (= 4.2.6)
      activerecord (= 4.2.6)
      activesupport (= 4.2.6)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.6)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.7)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6.0)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.3)
      loofah (~> 2.0)
    railties (4.2.6)
      actionpack (= 4.2.6)
      activesupport (= 4.2.6)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    raindrops (0.13.0)
    rake (11.1.2)
    redcarpet (3.3.2)
    ref (2.0.0)
    request_store (1.2.0)
    responders (2.1.0)
      railties (>= 4.2.0, < 5)
    rspec-core (3.3.2)
      rspec-support (~> 3.3.0)
    rspec-expectations (3.3.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-mocks (3.3.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-rails (3.3.3)
      actionpack (>= 3.0, < 4.3)
      activesupport (>= 3.0, < 4.3)
      railties (>= 3.0, < 4.3)
      rspec-core (~> 3.3.0)
      rspec-expectations (~> 3.3.0)
      rspec-mocks (~> 3.3.0)
      rspec-support (~> 3.3.0)
    rspec-support (3.3.0)
    rubyzip (1.1.7)
    sass (3.4.16)
    sass-rails (5.0.3)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (~> 1.1)
    selenium-webdriver (2.47.1)
      childprocess (~> 0.5)
      multi_json (~> 1.0)
      rubyzip (~> 1.0)
      websocket (~> 1.0)
    sendgrid (1.2.0)
      json
    spring (1.3.6)
    sprockets (3.6.0)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-es6 (0.7.0)
      babel-transpiler
      sprockets (>= 3.0.0)
    sprockets-rails (3.0.4)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    therubyracer (0.12.2)
      libv8 (~> 3.16.14.0)
      ref
    thor (0.19.1)
    thread_safe (0.3.5)
    tilt (1.4.1)
    timecop (0.7.4)
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uglifier (2.7.1)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    unicorn (4.9.0)
      kgio (~> 2.6)
      rack
      raindrops (~> 0.7)
    web-console (2.2.1)
      activemodel (>= 4.0)
      binding_of_caller (>= 0.7.2)
      railties (>= 4.0)
      sprockets-rails (>= 2.0, < 4.0)
    websocket (1.2.2)
    xpath (2.0.0)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  bcrypt (~> 3.1.11)
  byebug
  capybara
  carrierwave
  carrierwave-dropbox
  chromedriver-helper
  database_cleaner
  factory_girl_rails
  fog-aws
  gon
  io-like
  jasmine-rails
  jbuilder (~> 2.0)
  kaminari
  pg
  rails (= 4.2.6)
  redcarpet
  responders
  rspec-rails
  sass-rails (~> 5.0)
  selenium-webdriver
  sendgrid
  spring
  sprockets-es6
  therubyracer
  timecop
  uglifier (>= 1.3.0)
  unicorn
  web-console (~> 2.0)

BUNDLED WITH
   1.11.2

修改

启动容器时的实际错误输出:

web      | docker run -i --name draper-web -e DATABASE_HOST=172.17.0.1 -e DATABASE_HOST=172.17.0.1 -e DATABASE_PASSWORD=<password> -e DATABASE_PASSWORD=<password> -e DATABASE_PATH=/dev_db -e DATABASE_PORT=5432 -e DATABASE_PORT=5432 -e DATABASE_SCHEME=postgres -e DATABASE_SCHEME=postgres -e DATABASE_URL=postgres://postgres:<password>@172.17.0.1:5432/dev_db -e DATABASE_USERNAME=postgres -e RACK_ENV=development -e RAILS_ENV=development -p 80:80 -p 443:80 app/web sh -c bin/web

/var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/spec_set.rb:95:in `block in materialize': Could not find io-like-0.3.0 in any of the sources (Bundler::GemNotFound)
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/spec_set.rb:88:in `map!'
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/spec_set.rb:88:in `materialize'
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/definition.rb:140:in `specs'
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/definition.rb:185:in `specs_for'
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/definition.rb:174:in `requested_specs'
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/environment.rb:19:in `requested_specs'
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/runtime.rb:14:in `setup'
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler.rb:95:in `setup'
    from /var/lib/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/setup.rb:19:in `<top (required)>'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
starting server in env: development
...

bin / web,用于输出最后一行的上下文

# start server...
echo "starting server in env: $RAILS_ENV"
bundle exec unicorn -c ./config/unicorn.rb -E $RAILS_ENV

1 个答案:

答案 0 :(得分:1)

我打赌您使用了Gemfile Docker优化技术,这就是您Dockerfile中的内容:

COPY Gemfile* /tmp/
WORKDIR /tmp
RUN bundle install --without development test

这条线的问题是

BUNDLE_WITHOUT: development:test

已写入/tmp/.bundle/config文件,执行BundlerBundler.setup无法访问该文件。

所以一个可能的解决方案是将此行添加到Dockerfile(在切换工作目录后添加到您的应用目录):

RUN mkdir -p .bundle && printf '%s\n%s\n' '---' 'BUNDLE_WITHOUT: development:test' > .bundle/config

另一种方法是

RUN bundler config without development:test

但看起来Bundler会解析Gemfile,这个命令在我的机器上需要5秒,所以我决定坚持printf