【问题标题】:Bundler error when executing berks command from a rake task on windows从 Windows 上的 rake 任务执行 berks 命令时出现 Bundler 错误
【发布时间】:2015-02-26 23:22:36
【问题描述】:

我写了一个 rake 任务来对子目录中的 Berksfile 执行berks package 命令:

task :cook do
  `berks package ./cookbooks.tar.gz -b ./cookbook/Berksfile`
end

我也尝试过这些变体:

task :cook do
  `.\\scripts\\berks_package.bat` # containing stuff
end

task :cook do
  `C:\\opscode\\chefdk\\embedded\\bin\\ruby.exe "C:\\opscode\\chefdk\\bin\\berks" package ..\\cookbooks.tar.gz -b ..\\cookbook\\Berksfile`
end

无论我以何种方式执行berks,任务都会失败并出现以下错误:

C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:434:in `version_conflict': Bundler could not find compatible versions for gem "nokogiri": (Bundler::VersionConflict)
  In snapshot (Gemfile.lock):
    nokogiri (1.6.5)

  In Gemfile:
    albacore (~> 2.0.0) x86-mingw32 depends on
      nokogiri (~> 1.5) x86-mingw32

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:232:in `resolve_for_conflict'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:250:in `resolve_conflict'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:373:in `resolve'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:166:in `start'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:129:in `resolve'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/definition.rb:193:in `resolve'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/definition.rb:132:in `specs'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/definition.rb:177:in `specs_for'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/definition.rb:166:in `requested_specs'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/environment.rb:18:in `requested_specs'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/runtime.rb:13:in `setup'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler.rb:122:in `setup'
        from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/setup.rb:17:in `<top (required)>'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
rake aborted!
Albacore::CommandFailedError: Command failed with status (1):
  .\scripts\berks_package.bat

从命令提示符执行berks package ./cookbooks.tar.gz -b ./cookbook/Berksfile 与在任务中执行其他正常系统命令一样。

宝石文件:

source 'https://rubygems.org'
gem 'albacore', '~> 2.0.0'
gem 'semver2', '~> 3.4.0'

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    albacore (2.0.16)
      map (~> 6.5)
      nokogiri (~> 1.5)
      rake (~> 10)
      semver2 (~> 3.4)
    map (6.5.5)
    mini_portile (0.6.1)
    nokogiri (1.6.5-x64-mingw32)
      mini_portile (~> 0.6.0)
    rake (10.4.2)
    semver2 (3.4.0)

PLATFORMS
  x64-mingw32

DEPENDENCIES
  albacore (~> 2.0.0)
  semver2 (~> 3.4.0)

【问题讨论】:

    标签: windows rake bundler berkshelf albacore


    【解决方案1】:

    我在写问题时发现了问题并偶然发现了新想法。

    根本问题是使用 ChefDK 安装的 Ruby 二进制文件和 gem 与 Ruby 的系统安装冲突。具体来说,rake 任务是在系统 Ruby 安装下执行的,但是当执行 berks 时,它是在嵌入式 ChefDK Ruby 下运行的。我不清楚下一部分,但似乎 ChefDK Ruby 知道 Gemfile 并试图解决依赖关系本身,但因为 nokogiri 无法通过 Windows 上的捆绑程序毫无痛苦地解决(即构建),所以它失败了。

    这是我为解决问题所做的:

    1. 卸载系统Ruby
    2. 在系统 PATH 变量中添加了 C:\opscode\chefdk\bin,以便我可以运行 ruby​​、rake、gem、bundle 等。
    3. Ran gem install nokogiri(现在在 ChefDK 的 Ruby 下执行)
    4. 通过运行bundle install 重新创建了 Gemfile.lock 文件
    5. Bundler.with_clean_env 块包围berks 系统调用(这是!)

    任务现在看起来像:

    task :cook do
      Bundler.with_clean_env do
        `berks package cookbooks.tar.gz -b .\\cookbook\\Berksfile`
      end
    end
    

    【讨论】:

    • 这很麻烦,感谢您弄清楚并发布此答案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    相关资源
    最近更新 更多