gpt4 book ai didi

windows - 从 Windows 上的 rake 任务执行 berks 命令时出现 Bundler 错误

转载 作者:可可西里 更新时间:2023-11-01 10:35:45 25 4
gpt4 key购买 nike

我编写了一个 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 与在任务中执行其他正常系统命令一样。

gem 文件:

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)

最佳答案

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

根本问题是与 ChefDK 一起安装的 Ruby 二进制文件和 gems 与 Ruby 的系统安装冲突。具体来说,rake任务是在系统Ruby安装下执行的,但是执行berks时,它是在嵌入式ChefDK Ruby下运行的。我不清楚下一部分,但 ChefDK Ruby 似乎知道 Gemfile 并尝试自行解决依赖关系,但由于 nokogiri 无法由 Windows 上的 bundler 轻松解决(即构建),因此失败了。

以下是我为解决问题所做的工作:

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

任务现在看起来像:

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

关于windows - 从 Windows 上的 rake 任务执行 berks 命令时出现 Bundler 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27711480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com