Created
March 11, 2013 15:58
-
-
Save mulderp/5135267 to your computer and use it in GitHub Desktop.
cookbook rvm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chef::Resource::Script | |
def log_code command | |
if Chef::Config[:log_level] == :debug | |
code "{ #{command}; _ret=$?; echo \"Exit status was $_ret.\"; exit $_ret; } 2>&1 | | |
tee /var/log/#{@command.to_s.gsub(/ /,"_")}.log; exit ${PIPESTATUS[0]}" | |
else | |
code command | |
end | |
end | |
end | |
reqs = [ | |
node[:rvm][:requirements][ node["platform"] ] || | |
node[:rvm][:requirements][ node["platform_family"] ] || | |
node[:rvm][:requirements][ node["os"] ] | |
].flatten * " && " | |
unless reqs.empty? | |
bash "install #{node["platform"]} requirements" do | |
if Chef::Config[:log_level] == :debug | |
puts "--- type: #{ node["platform"] } / #{ node["platform_family"] } / #{ node["os"] }" | |
puts "--- requirements: '#{reqs}'" | |
end | |
log_code reqs | |
end | |
end | |
installer_options="--auto-dotfiles" | |
rvm_command="/usr/local/rvm/bin/rvmsudo /usr/local/rvm/bin/rvm" | |
bash "install rvm" do | |
if File.directory? "/vagrant/rvm-src" | |
cwd "/vagrant/rvm-src" | |
log_code "./install #{installer_options}" | |
else | |
$stderr.puts "rvm-src not found falling back to download" | |
log_code "curl -L https://get.rvm.io | bash -s -- #{installer_options}" | |
end | |
end | |
%w( archives repos ).each do |type| | |
if File.directory? "/vagrant/rvm-#{type}" | |
bash "link rvm #{type}" do | |
log_code "rm -rf /usr/local/rvm/#{type} && ln -s /vagrant/rvm-#{type}/ /usr/local/rvm/#{type} " | |
end | |
else | |
$stderr.puts "rvm-#{type} missing, shared #{type} disabled" | |
end | |
end | |
bash "install rvm requirements" do | |
log_code "#{rvm_command} requirements run force" | |
end | |
node[:rvm][:binary][:versions].each do |version| | |
bash "uninstall #{version}" do | |
log_code "#{rvm_command} uninstall #{version}" | |
only_if "#{rvm_command} use #{version}" | |
end | |
bash "install #{version}" do | |
log_code "#{rvm_command} install #{version} --movable" | |
end | |
bash "package #{version}" do | |
cwd "/vagrant" | |
log_code "#{rvm_command} prepare #{version} --path" | |
end | |
end | |
deploy_user = 'vagrant' #node[:deploy][:user] | |
deploy_user_home = File.join('/', 'home', deploy_user) | |
rvm_version = "head" | |
execute "install_rvm_for_deploy_user" do | |
user deploy_user | |
command "curl -L https://get.rvm.io | bash -s #{rvm_version}" | |
environment "HOME" => deploy_user_home | |
creates "#{deploy_user_home}/.rvm" | |
end | |
#node['buildpack']['ruby_versions'].each do |ruby_version| | |
ruby_version = 'ruby-2.0.0-rc1' | |
execute "install_rvm_ruby_#{ruby_version}" do | |
user deploy_user | |
environment "HOME" => deploy_user_home | |
command "#{deploy_user_home}/.rvm/bin/rvm install #{ruby_version} --autolibs=3" | |
end | |
file "#{deploy_user_home}/.rvmrc" do | |
content 'export rvm_trust_rvmrcs_flag=1' | |
owner deploy_user | |
mode 0644 | |
end |
Author
mulderp
commented
Mar 11, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment