1

I'm attempting to use the application_ruby cookbook to deploy my Rails app on a server Chef is setting up. When the chef-client reaches the point of running bundle install, it crashes, saying that it can't find bundler. I suspect this may have to do with the fact that I'm using RVM on this server, but I'm not sure what to do about that.

Here's my application recipe:

database_name = "app_#{node.chef_environment}"
api_deploy_key = Chef::EncryptedDataBagItem.load('keys', 'app_repository')["deploy_key"]

application "my_app" do
  path "/var/www"
  owner 'ubuntu'
  repository "git@github.com:my_account/app.git"
  revision node.chef_environment == "production" ? "master" : "develop"
  deploy_key api_deploy_key

  rails do
    gems [['Bundler', '1.3.4']]
    database_master_role 'db_master'
    database do
      database database_name
      username "ubuntu"
      password Chef::EncryptedDataBagItem.load('passwords', 'db')["password"]
    end

    bundler true
    precompile_assets true
  end
end

And this is the error that it produces:

================================================================================
Error executing action `run` on resource 'execute[bundle install --path=vendor/bundle --deployment --without development test cucumber production]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of bundle install --path=vendor/bundle --deployment --without development test cucumber production ----
STDOUT: 
STDERR: /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:296:in `to_specs': Could not find 'bundler' (>= 0) among 175 total gem(s) (Gem::LoadError)
    from /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:307:in `to_spec'
    from /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /usr/local/rvm/gems/ruby-1.9.3-p125@global/bin/bundle:22:in `<main>'
    from /usr/local/rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `eval'
    from /usr/local/rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `<main>'
---- End output of bundle install --path=vendor/bundle --deployment --without development test cucumber production ----
Ran bundle install --path=vendor/bundle --deployment --without development test cucumber production returned 1

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/application_ruby/providers/rails.rb

 86:     execute "#{bundle_command} install --path=vendor/bundle #{bundler_deployment ? "--deployment " : ""}--without #{common_groups}" do
 87:       cwd new_resource.release_path
 88:       user new_resource.owner
 89:       environment new_resource.environment
 90:     end
 91:   else



Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/application_ruby/providers/rails.rb:86:in `block in class_from_file'

execute("bundle install --path=vendor/bundle --deployment --without development test cucumber production") do
  action "run"
  retries 0
  retry_delay 2
  command "bundle install --path=vendor/bundle --deployment --without development test cucumber production"
  backup 5
  cwd "/var/www/releases/30858f319060ca556b5109aa6d0ac64afa3f8e38"
  environment {"RAILS_ENV"=>"staging", "PATH"=>"/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"}
  returns 0
  user "ubuntu"
  cookbook_name "my_app"
end

If I set rollback_on_error to false, I can manually go into the checked-out code directory, and run bundle install without problems.

What's going wrong here, and how can I fix it?

4

1 回答 1

3

您设置错误的环境,它应该是:

environment {
  "RAILS_ENV"=>"staging", 
  "PATH"=>"/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games", 
  "GEM_PATH"=>"/usr/local/rvm/gems/ruby-1.9.3-p125:/usr/local/rvm/gems/ruby-1.9.3-p125@global", 
  "GEM_HOME"=>"/usr/local/rvm/gems/ruby-1.9.3-p125"
}
于 2013-08-30T15:37:06.290 回答