From c082d64e988f5238c579d57dadb75110e4466426 Mon Sep 17 00:00:00 2001 From: Paul Carey Date: Sun, 21 Jun 2015 22:11:42 +0100 Subject: [PATCH] Allow rvm to mount a Ruby --- .gitignore | 3 ++ .../rvm_system_ruby/rvm_system_ruby.rb | 38 +++++++++++++------ lib/puppet/type/rvm_system_ruby.rb | 4 ++ manifests/init.pp | 2 + manifests/system.pp | 36 +++++++++++++++--- 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 7eb39d3d..5d046865 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,9 @@ vendor/ .rvmrc* .ruby-* +# IntelliJ/RubyMine +.idea/* + ## rspec spec/fixtures/manifests/ spec/fixtures/modules/ diff --git a/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb b/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb index 8846ac55..c4ed75f3 100644 --- a/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb +++ b/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb @@ -6,19 +6,10 @@ end def create - unless resource[:proxy_url].nil? - ENV['http_proxy'] = resource[:proxy_url] - ENV['https_proxy'] = resource[:proxy_url] - unless resource[:no_proxy].nil? - ENV['no_proxy'] = resource[:no_proxy] - end - end - set_autolib_mode if resource.value(:autolib_mode) - options = Array(resource[:build_opts]) - if resource[:proxy_url] and !resource[:proxy_url].empty? - rvmcmd "install", resource[:name], "--proxy", resource[:proxy_url], *options + if resource[:mount_from] + mount else - rvmcmd "install", resource[:name], *options + install end set_default if resource.value(:default_use) end @@ -63,4 +54,27 @@ def set_autolib_mode raise Puppet::Error, "Could not set autolib mode: #{detail}" end end + + private + + def install + unless resource[:proxy_url].nil? + ENV['http_proxy'] = resource[:proxy_url] + ENV['https_proxy'] = resource[:proxy_url] + unless resource[:no_proxy].nil? + ENV['no_proxy'] = resource[:no_proxy] + end + end + set_autolib_mode if resource.value(:autolib_mode) + options = Array(resource[:build_opts]) + if resource[:proxy_url] and !resource[:proxy_url].empty? + rvmcmd "install", resource[:name], "--proxy", resource[:proxy_url], *options + else + rvmcmd "install", resource[:name], *options + end + end + + def mount + rvmcmd "mount", resource[:mount_from] + end end diff --git a/lib/puppet/type/rvm_system_ruby.rb b/lib/puppet/type/rvm_system_ruby.rb index 2464dbe5..4c1910e0 100644 --- a/lib/puppet/type/rvm_system_ruby.rb +++ b/lib/puppet/type/rvm_system_ruby.rb @@ -32,4 +32,8 @@ desc "Set RVM autolib mode" end + newparam(:mount_from) do + desc 'If you wish to specify a Ruby archive to mount' + end + end diff --git a/manifests/init.pp b/manifests/init.pp index 61f4a257..a5544f66 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,6 +1,7 @@ # Install RVM, create system user a install system level rubies class rvm( $version=undef, + $install_from=undef, $install_rvm=true, $install_dependencies=false, $manage_rvmrc=$rvm::params::manage_rvmrc, @@ -31,6 +32,7 @@ no_proxy => $no_proxy, key_server => $key_server, gnupg_key_id => $gnupg_key_id, + install_from => $install_from, } } diff --git a/manifests/system.pp b/manifests/system.pp index 968edcbf..232c3308 100644 --- a/manifests/system.pp +++ b/manifests/system.pp @@ -1,6 +1,7 @@ # Install the RVM system class rvm::system( $version=undef, + $install_from=undef, $proxy_url=undef, $no_proxy=undef, $key_server=undef, @@ -20,7 +21,7 @@ ensure_packages(['curl']) Package['curl'] -> Exec['system-rvm'] } - default: {} + default: { } } } @@ -44,11 +45,34 @@ } } - exec { 'system-rvm': - path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', - command => "curl -fsSL https://get.rvm.io | bash -s -- --version ${actual_version}", - creates => '/usr/local/rvm/bin/rvm', - environment => $environment, + if $install_from { + + file { '/tmp/rvm': + ensure => directory, + } + + exec { 'unpack-rvm': + path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', + command => "tar --strip-components=1 -xzf ${install_from}", + cwd => '/tmp/rvm', + } + + exec { 'system-rvm': + path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', + command => './install --auto-dotfiles', + cwd => '/tmp/rvm', + creates => '/usr/local/rvm/bin/rvm', + environment => $environment, + } + + } + else { + exec { 'system-rvm': + path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', + command => "curl -fsSL https://get.rvm.io | bash -s -- --version ${actual_version}", + creates => '/usr/local/rvm/bin/rvm', + environment => $environment, + } } # the fact won't work until rvm is installed before puppet starts