简体   繁体   English

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

[英]RVM problems `bundle install` in a Vagrant/Chef-solo vm

I'm having some trouble doing a bundle install of my rails app dependencies as part of the vagrant up configuring my VM. 作为vagrant up配置我的VM的一部分,我在执行rails应用程序依赖项的bundle install时遇到了一些麻烦。

The problem I'm having is getting the bundle install to run as the correct user (vagrant) with correct rvm. 我遇到的问题是使用正确的rvm将bundle安装作为正确的用户(vagrant)运行。

So my rvm is set up via Berkshelf with the following configuration: 所以我的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' }
  }

and I'm using the following RVM recipes: 我正在使用以下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]'
]

(note lasso-plan is my own local one) (注意套索计划是我自己的本地计划)

now if I try: 现在,如果我尝试:

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

or 要么

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

I get 我明白了

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)`

whereas without the user declaration it seems to install the gems fine but they are not accessible as the vagrant user. 如果没有用户声明,它似乎可以很好地安装宝石,但它们不能作为流浪者用户访问。

I'm assuming this is because of rvm and it treating users differently, if anyone could shed any light on how to move forward with this that would be great. 我假设这是因为rvm并且它以不同的方式对待用户,如果有人能够阐明如何向前推进这将是很好的。

Thanks 谢谢

Update 更新

So after some help (thank you) I've made some progress with this and I've found a similar issue reported before: http://lists.opscode.com/sympa/arc/chef/2012-05/msg00153.html 所以经过一些帮助(谢谢)我已经取得了一些进展,我发现之前报告过类似的问题: http//lists.opscode.com/sympa/arc/chef/2012-05/msg00153.html

At the moment I've got a bit of work around going by running: 目前我还有一些工作要做:

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

Which allows the bundles to be installed in the directory of my app, it has the downside that the bins aren't in a path but this can be resolved with bundle exec 这允许捆绑包安装在我的应用程序的目录中,它的缺点是容器不在路径中但是这可以用bundle exec解决

If I run: 如果我跑:

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

I get the following error: 我收到以下错误:

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" ----

Which I think might be to do with the sudo problems outlined here: https://github.com/bundler/bundler/blob/master/man/bundle-install.ronn as I'm assuming chef uses sudo to run as the vagrant user and it may be thinking the home directory is /root/ 我认为这可能与这里概述的sudo问题有关: https//github.com/bundler/bundler/blob/master/man/bundle-install.ronn因为我假设厨师使用sudo作为流浪者运行用户可能认为主目录是/root/

and then if I don't specify the user and run it as root: 然后,如果我没有指定用户并以root身份运行它:

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

It installs most of them but not ones where I'm referencing git repositories and errors about the missing ones not existing like so: 它安装了大部分但不是我引用git存储库的那些,以及关于缺少的那些不存在的错误:

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

I'm not sure if there would be other implications to having the bundle installed by root and not the vagrant user if I wanted to run bundle install again 我不确定如果我想再次运行bundle install ,是否会对root用户安装捆绑包而不是流浪者用户有其他影响

So ideally I want to install to the gem path rather than into .bundle in the app (or if I can't at least understand why) as the user. 理想情况下,我想安装到gem路径而不是应用程序中的.bundle(或者如果我不能理解为什么)作为用户。 Thanks for the help 谢谢您的帮助

It's been a while since I last tried to use this cookbook, but here's what I remember... 自从我上次尝试使用这本食谱以来已经有一段时间了,但这就是我记得的......

The global_gems array puts those gems in a gemset called global . global_gems数组将这些gem放在名为global的gemset中。 In your case, they would be placed in ruby 2.0.0@global . 在您的情况下,它们将被放置在ruby 2.0.0@global

If you set that as your default_ruby you might fix your problem with the least effort (disclaimer -- I haven't tested it, but it should work). 如果你将它设置为default_ruby你可以用最少的努力解决你的问题(免责声明 - 我没有测试它,但它应该工作)。

Another option would be to leverage the gems attribute, setting it to something like: 另一种选择是利用gems属性,将其设置为:

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

This latter option should install the gems without a gemset, thus letting them be found in your current default_ruby . 后一个选项应该安装没有gemset的gem,因此可以在当前的default_ruby找到它们。

Update: 更新:

Your problem must be that the bundle install commands are running outside of RVM, thus using Chef's embedded Ruby. 您的问题必须是bundle install命令在RVM之外运行,因此使用Chef的嵌入式Ruby。 Try "sourcing" the rvm profile script prior to running bundle: 在运行bundle之前尝试“获取”rvm配置文件脚本:

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

You might need to change /etc/profile.d/rvm.sh to wherever RVM has its profile script installed. 您可能需要将/etc/profile.d/rvm.sh更改为RVM安装其配置文件脚本的位置。

I had the exact same problem. 我有同样的问题。 When installing normally using the system install into /usr/local/rvm it would skip custom GitHub gems (for some reason??). 当使用系统安装正常安装到/ usr / local / rvm时,它会跳过自定义GitHub gems(出于某种原因??)。 But when trying to install as the vagrant user, I would get the Permission denied - /root/.bundler error. 但是当尝试作为vagrant用户安装时,我会得到Permission denied - /root/.bundler错误。 Here's what I came up with: 这是我想出的:

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

Using the --path directive installs gems into the current working directory. 使用--path指令将gems安装到当前工作目录中。 It seems to work. 它似乎工作。 Gems will have to be installed independently for each app using this method, and everything must be run with bundle exec all the time from that directory, but it seems to work. 必须使用此方法为每个应用程序独立安装Gems,并且所有内容必须始终使用bundle exec从该目录运行,但它似乎有效。

I used OpsWorks and had the same issue. 我使用OpsWorks并遇到了同样的问题。 I got it solved successfully following suggestion from cbl, but I used rvmsudo bundle install instead of only bundle install : 我根据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

The reason of using rvmsudo is that, I think, some gems try to create directories at places that do not allow normal users. 使用rvmsudo的原因是,我认为,一些宝石尝试在不允许普通用户的地方创建目录。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM