我是Chef
的新用户,我现在尝试了几个小时,想出如何安装ruby并安装gem bundler
,我是新手ruby
也是。
我想克隆我的存储库并执行如下:
$ bundle install
$ bundle exec rackup
简单的通过Shell脚本,但现在看来,Chef很难。 虽然,我创建了这个食谱:
metadata.rb
depends 'apt'
depends 'git'
# depends 'rbenv' -> # very old version
depends 'ruby_rbenv' # -> new version
depends 'application'
depends 'application_ruby'
depends 'build-essential'
metadata.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
非常感谢任何帮助!
答案 0 :(得分:1)
您已使用的application_ruby
取决于poise-ruby
,请使用它。查看https://github.com/poise/poise-ruby处的文档,但简短版只需将ruby_runtime 'myapp'
添加到应用程序块。
您还可以查看application_examples以获取更详细的示例。这是针对rails的,但您可以找出如何使其适应sinatra。