RVM问题`捆绑安装`在Vagrant / Chef-solo vm中

时间:2013-07-11 01:02:58

标签: ruby-on-rails ruby rvm chef vagrant

作为bundle install配置我的虚拟机的一部分,我在执行vagrant up我的rails应用依赖项时遇到了一些麻烦。

我遇到的问题是使用正确的rvm将bundle安装作为正确的用户(vagrant)运行。

所以我的rvm是通过Berkshelf设置的,具有以下配置:

  rvm: {
    rubies: ['2.0.0'],
    default_ruby: '2.0.0',
    global_gems: [{ name: 'bundler' },
                    { name: 'rake' }],
    vagrant: { system_chef_solo: '/usr/bin/chef-solo' }
  }

我正在使用以下RVM配方:

chef.run_list = [
  'recipe[apt]',
  'recipe[rvm]',
  'recipe[rvm::vagrant]',
  'recipe[rvm::system]',
  'recipe[rvm::gem_package]',
  'recipe[mongodb::10gen_repo]',
  'recipe[mongodb]',
  'recipe[nodejs]',
  'recipe[phantomjs]',
  'recipe[lasso-plan]'
]

(注意lasso-plan是我自己的当地人)

现在如果我尝试:

execute 'bundle install' do
  cwd node['lasso_plan']['path']
  user 'vagrant'
end

rvm_shell "bundle the gems" do 
  cwd node['lasso_plan']['path']
  code 'bundle install'
  user 'vagrant'
end

我得到了

STDERR: /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'bundler' (>= 0) among 74 total gem(s) (Gem::LoadError)`

虽然没有用户声明,但似乎安装了宝石,但它们不能作为流浪者用户访问。

我认为这是因为rvm并且它以不同的方式对待用户,如果有人能够阐明如何向前推进这将是非常好的。

由于

更新

所以在得到一些帮助后(谢谢)我已经取得了一些进展,我发现之前报告过类似的问题:http://lists.opscode.com/sympa/arc/chef/2012-05/msg00153.html

目前,我已经有了一些关于跑步的工作:

rvm_shell 'bundle the gems' do 
  ruby_string ruby_version
  cwd node['lasso_plan']['path']
  code 'bundle install --path .bundle'
  user 'vagrant'
end 

这允许捆绑包安装在我的应用程序的目录中,它的缺点是这些容器不在路径中,但可以使用bundle exec来解决这个问题

如果我跑:

rvm_shell 'bundle the gems' do 
  ruby_string ruby_version
  cwd node['lasso_plan']['path']
  code 'bundle install'
  user 'vagrant'
end

我收到以下错误:

STDERR: /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/fileutils.rb:245:in `mkdir': Permission denied - /root/.bundler (Errno::EACCES)
  from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/fileutils.rb:245:in `fu_mkdir'
  from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/fileutils.rb:219:in `block (2 levels) in mkdir_p'
  from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/fileutils.rb:217:in `reverse_each'
  from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/fileutils.rb:217:in `block in mkdir_p'
  from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/fileutils.rb:203:in `each'
  from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/fileutils.rb:203:in `mkdir_p'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/source/git/git_proxy.rb:46:in `checkout'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/source/git.rb:144:in `specs'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/lazy_specification.rb:52:in `__materialize__'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/spec_set.rb:88:in `block in materialize'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/spec_set.rb:85:in `map!'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/spec_set.rb:85:in `materialize'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:114:in `specs'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:109:in `resolve_remotely!'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/installer.rb:83:in `run'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/installer.rb:14:in `install'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/cli.rb:247:in `install'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `run'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in `dispatch'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in `start'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/bin/bundle:20:in `block in <top (required)>'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in `with_friendly_errors'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/bin/bundle:20:in `<top (required)>'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/bin/bundle:23:in `load'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/bin/bundle:23:in `<main>'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/bin/ruby_noexec_wrapper:14:in `eval'
  from /usr/local/rvm/gems/ruby-2.0.0-p247@global/bin/ruby_noexec_wrapper:14:in `<main>'
---- End output of "bash"  "/tmp/chef-script20130711-23336-uqohfl" ----

我认为可能与此处列出的sudo问题有关:https://github.com/bundler/bundler/blob/master/man/bundle-install.ronn因为我假设厨师使用sudo作为流浪者用户运行,并且它可能认为主目录是/root/

然后如果我没有指定用户并以root身份运行它:

rvm_shell 'bundle the gems' do 
  ruby_string ruby_version
  cwd node['lasso_plan']['path']
  code 'bundle install'
end

它安装了大部分内容,但没有安装我引用git存储库的内容以及有关缺少的内存错误的错误:

Gems included by the bundle:
git://github.com/bkeepers/dotenv.git (at master) is not checked out. Please run
`bundle install`

我不确定如果我想再次运行bundle install,是否会让root用户安装捆绑包而不是流浪者用户

理想情况下,我想安装到gem路径而不是应用程序中的.bundle(或者如果我不能理解为什么)作为用户。谢谢你的帮助

4 个答案:

答案 0 :(得分:1)

自从我上次尝试使用这本食谱以来已经有一段时间了,但这就是我记得的......

global_gems数组将这些宝石放在名为global的宝石集中。在您的情况下,他们将被置于红宝石2.0.0@global

如果您将其设置为default_ruby,则可以用最少的努力解决问题(免责声明 - 我没有对其进行测试,但它应该可以正常工作)。

另一种选择是利用gems属性,将其设置为:

node['rvm']['gems'] = {
  '2.0.0' => [
    { name: 'bundler' },
    { name: 'rake' }
  ]
}

后一个选项应安装没有gemset的gem,因此可以在当前的default_ruby中找到它们。

<强>更新

您的问题必须是bundle install命令在RVM之外运行,因此使用Chef的嵌入式Ruby。 在运行bundle之前尝试“获取”rvm配置文件脚本:

execute 'bundle install' do
  cwd node['lasso_plan']['path']
  command <-EOC
    . /etc/profile.d/rvm.sh;
    bundle install
  EOC
  user 'vagrant'
end

您可能需要将/etc/profile.d/rvm.sh更改为RVM安装其配置文件脚本的位置。

答案 1 :(得分:1)

我遇到了完全相同的问题。当使用系统安装正常安装到/ usr / local / rvm时,它会跳过自定义GitHub gems(出于某种原因??)。但是当尝试作为vagrant用户安装时,我会得到Permission denied - /root/.bundler错误。这就是我想出的:

rvm_shell "bundle" do
  ruby_string node[:rvm][:default_ruby]
  user        "vagrant"
  group       "vagrant"
  cwd         "/home/vagrant/my_app"
  code        <<-EOF
    bundle install --path .bundle
  EOF
end

使用--path指令将gems安装到当前工作目录中。它似乎工作。必须使用此方法为每个应用程序独立安装Gems,并且必须始终使用bundle exec从该目录运行所有内容,但它似乎有效。

答案 2 :(得分:0)

我使用OpsWorks并遇到了同样的问题。我根据cbl的建议成功解决了问题,但我使用的是rvmsudo bundle install而不是bundle install

execute 'bundle install' do
  cwd node['lasso_plan']['path']
  command <<-EOF
    source /etc/profile.d/rvm.sh
    rvmsudo bundle install
  EOF
  user 'vagrant'
end

使用rvmsudo的原因是,我认为,有些宝石尝试在不允许普通用户的地方创建目录。

答案 3 :(得分:0)

execute "bundle install" do                                                                                                                                                                      
  cwd "/vagrant"                                                                                                                                                                                 
  command "/usr/local/rvm/bin/rvm ruby-2.1.2 do /usr/bin/env bundle install"                                                                                                                     
  action :nothing                                                                                                                                                                                
end