【问题标题】:How to install ruby and bundler via Chef?如何通过 Chef 安装 ruby​​ 和 bundler?
【发布时间】:2017-05-22 09:37:25
【问题描述】:

我是 Chef 的新手,我正在尝试几个小时,弄清楚如何安装 ruby​​ 并安装 gem bundler,我也是 ruby 的新手。

我想克隆我的存储库并像这样执行:

$ bundle install
$ bundle exec rackup

通过 Shell 脚本很简单,但目前看来,使用 Chef 非常困难。 虽然,我创建了这个食谱:

元数据.rb

depends 'apt'
depends 'git'
# depends 'rbenv' -> # very old version
depends 'ruby_rbenv' # -> new version
depends 'application'
depends 'application_ruby'
depends 'build-essential'

元数据.rb

include_recipe 'git'
include_recipe 'ruby_rbenv::system'
include_recipe 'build-essential'

rbenv_global 'system'

group 'sinatra_app'

user 'sinatra_app' do
  group 'sinatra_app'
  system true
  shell '/bin/bash'
end

# DON'T WORK    
# rbenv_gem "bundler" do
  # action :install
# end

# DON'T WORK
# rbenv_gem "bundler" do
  # ruby_version "2.4.0"
# end

directory '/srv/sinatra-app' do
  owner 'sinatra_app'
  group 'sinatra_app'
  mode '0755'
  recursive true
end

application '/srv/sinatra-app' do
  # Application resource properties.
  owner 'sinatra_app'
  group 'sinatra_app'

  # Subresources, like normal recipe code.
  package 'ruby'
  git "/srv/sinatra-app" do
    repository "git://github.com/tnh/sinatra-app.git"
    reference "master"
    action :sync
  end

  # DON'T WORK
  bundle_install do
    deployment true
  end

end

但我不确定是否正确安装了 ruby​​。还有bundle_install 似乎不起作用..

这是我的错误输出:

node1-ubuntu     ================================================================================
node1-ubuntu     Error executing action `install` on resource 'application_bundle_install[/srv/sinatra-app]'
node1-ubuntu     ================================================================================
node1-ubuntu     
node1-ubuntu     Mixlib::ShellOut::ShellCommandFailed
node1-ubuntu     ------------------------------------
node1-ubuntu     Expected process to exit with [0], but received '1'
node1-ubuntu     ---- Begin output of ["/usr/bin/ruby", "/usr/local/bin/bundle", "install", "--deployment"] ----
node1-ubuntu     STDOUT: 
node1-ubuntu     STDERR: /usr/bin/ruby: No such file or directory -- /usr/local/bin/bundle (LoadError)
node1-ubuntu     ---- End output of ["/usr/bin/ruby", "/usr/local/bin/bundle", "install", "--deployment"] ----
node1-ubuntu     Ran ["/usr/bin/ruby", "/usr/local/bin/bundle", "install", "--deployment"] returned 1
node1-ubuntu     
node1-ubuntu     Cookbook Trace:
node1-ubuntu     ---------------
node1-ubuntu     /var/chef/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/command/mixin.rb:207:in `tap'
node1-ubuntu     /var/chef/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/command/mixin.rb:207:in `language_command_shell_out!'
node1-ubuntu     /var/chef/cache/cookbooks/poise-languages/files/halite_gem/poise_languages/command/mixin.rb:222:in `block in language_command_mixin'
node1-ubuntu     /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:160:in `run_bundler'
node1-ubuntu     /var/chef/cache/cookbooks/poise-ruby/files/halite_gem/poise_ruby/resources/bundle_install.rb:119:in `action_install'
node1-ubuntu     
node1-ubuntu     Resource Declaration:
node1-ubuntu     ---------------------
node1-ubuntu     # In /var/chef/cache/cookbooks/sinatra-app/recipes/default.rb
node1-ubuntu     
node1-ubuntu      68:   bundle_install do
node1-ubuntu      69:     deployment true
node1-ubuntu      70:   end
node1-ubuntu      71:   
node1-ubuntu     
node1-ubuntu     Compiled Resource:
node1-ubuntu     ------------------
node1-ubuntu     # Declared in /var/chef/cache/cookbooks/sinatra-app/recipes/default.rb:68:in `block in from_file'
node1-ubuntu     
node1-ubuntu     application_bundle_install("/srv/sinatra-app") do
node1-ubuntu       action [:install]
node1-ubuntu       retries 0
node1-ubuntu       retry_delay 2
node1-ubuntu       default_guard_interpreter :default
node1-ubuntu       declared_type :application_bundle_install
node1-ubuntu       cookbook_name "sinatra-app"
node1-ubuntu       recipe_name "default"
node1-ubuntu       parent application[/srv/sinatra-app]
node1-ubuntu       deployment true
node1-ubuntu       parent_ruby nil
node1-ubuntu       gem_binary "/usr/bin/gem"
node1-ubuntu       timeout 900
node1-ubuntu       path "/srv/sinatra-app"
node1-ubuntu     end
node1-ubuntu     
node1-ubuntu     Platform:
node1-ubuntu     ---------
node1-ubuntu     x86_64-linux

任何帮助将不胜感激!

【问题讨论】:

  • 另一个需要考虑的选项是安装 ChefDK 包。它包括一个完整的 Ruby 环境

标签: ruby sinatra chef-infra bundler chef-recipe


【解决方案1】:

您已经在使用application_ruby,这取决于poise-ruby,所以使用它。查看https://github.com/poise/poise-ruby 的文档,但简短版本只需将ruby_runtime 'myapp' 添加到应用程序块。

您还可以查看application_examples 以获取更详细的示例。这是针对 Rails 的,但您可能会弄清楚如何将其适应 sinatra

【讨论】:

    猜你喜欢
    • 2013-08-17
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 2020-07-28
    相关资源
    最近更新 更多