-
Notifications
You must be signed in to change notification settings - Fork 82
Added "ruby" cookbook for maintaining binary ruby distribution #172
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ gem "kitchen-vagrant" | |
gem "kitchen-digitalocean" | ||
gem "serverspec" | ||
gem "rspec" | ||
gem "chefspec" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
applications_root = node[:rails][:applications_root] | ||
available_binaries = node[:rbenv][:available_binaries] | ||
kernel_architecture = node[:kernel][:machine] | ||
if node[:active_applications] | ||
node[:active_applications].each do |app, app_info| | ||
if app_info[:ruby_version] | ||
if available_binaries.include? app_info[:ruby_version] | ||
ruby_version = app_info[:ruby_version] | ||
ruby_binary = "ruby-#{ruby_version}.tar.bz2" | ||
execute "Install ruby #{app_info[:ruby_version]} binaries" do | ||
ruby = app_info[:ruby_version] | ||
user node[:rbenv][:user] | ||
group node[:rbenv][:group] | ||
cwd "#{node[:rbenv][:root_path]}/versions" | ||
command <<-EOM | ||
wget #{node[:rbenv][:binaries_url]}/#{node["platform_version"]}/#{kernel_architecture}/#{ruby_binary}; | ||
tar jxf #{ruby_binary} | ||
rm #{ruby_binary} | ||
EOM | ||
not_if { File.directory?(File.join('opt', 'rbenv', 'versions', ruby_version)) } | ||
version, rbenv_versions_path = app_info[:ruby_version], "/opt/rbenv/versions" | ||
|
||
ruby_binary version do | ||
path rbenv_versions_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||
not_if { File.directory? "#{rbenv_versions_path}/#{version}" } | ||
end | ||
|
||
ruby_build_ruby version do | ||
prefix_path "#{rbenv_versions_path}/#{version}" | ||
subscribes :install, "ruby_binary[#{version}]", :immediately | ||
not_if { node[:ruby][version][:installed] } | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
case node["platform_family"] | ||
when 'debian' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
default["ruby"]["download_url"] = "http://binaries.intercityup.com/ruby/ubuntu" | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 trailing blank lines detected. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name "rails" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put one space between the method name and the first argument. |
||
maintainer "Michiel Sikkes" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put one space between the method name and the first argument. |
||
maintainer_email "[email protected]" | ||
license "MIT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put one space between the method name and the first argument. |
||
description "Installs/Configures ruby" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put one space between the method name and the first argument. |
||
long_description "Installs/Configures ruby" | ||
version "0.1.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put one space between the method name and the first argument. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
def whyrun_supported? | ||
true | ||
end | ||
|
||
use_inline_resources | ||
|
||
# | ||
# Name parameter: ruby version, for ex. "2.2.0" | ||
# Path parameter: where new ruby should be installed | ||
# | ||
action :install do | ||
version = @new_resource.version | ||
path = @new_resource.path | ||
download_url = "#{node[:ruby][:download_url]}/#{node[:platform_version]}/#{node[:kernel][:machine]}/ruby-#{version}.tar.bz2" | ||
downloaded_ruby = "#{Chef::Config[:file_cache_path]}/#{::File.basename download_url}" | ||
|
||
Chef::Log.info "Installing ruby binaries..." | ||
Chef::Log.debug "version: #{version}" | ||
Chef::Log.debug "installation path: #{path}" | ||
Chef::Log.debug "download from: #{download_url}" | ||
Chef::Log.debug "save ruby to file: #{downloaded_ruby}" | ||
|
||
begin | ||
remote_file downloaded_ruby do | ||
source download_url + "abc" | ||
action :nothing | ||
end.run_action :create | ||
|
||
bash "extract ruby binary" do | ||
cwd path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||
code <<-EOH | ||
mkdir -p #{path} | ||
tar jxf #{downloaded_ruby} -C #{path} | ||
EOH | ||
only_if { ::File.exists? downloaded_ruby } | ||
end | ||
|
||
Chef::Log.debug "extracted to #{path}" | ||
node.default[:ruby][version][:installed] = true | ||
rescue Exception => e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid rescuing the |
||
Chef::Log.warn "Ruby installation failed, cause: #{e}" | ||
node.default[:ruby][version][:installed] = false | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
actions :install | ||
default_action :install | ||
|
||
attribute :version, kind_of: String, name_attribute: true | ||
attribute :path, kind_of: String |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "spec_helper" | ||
|
||
describe "ruby::default" do | ||
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) } | ||
|
||
it "installs ruby" do | ||
expect(chef_run).to install_package("foo") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to actually test something here, right? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we do. I'm adding some meaningful tests right now |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "chefspec" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.