Browse files

Major refactoring of recipes which will result in a minor version bump.

There are now 2 main modes in which to use RVM: isolated as a user or
system-wide.

* recipe[rvm] - pulls in the RVM gem and initializes Chef to use the
  LWRPs which is a breaking change to previous behavior. Use this recipe
  if you only want access to the LWRPs provided.
* recipe[rvm::system_install] - only installs RVM framework system-wide.
  Use this recipe by itself if you want RVM installed but will handle
  rubies yourself (by hand, with the LWRPs, etc.)
* recipe[rvm::system] - installs RVM system-wide and installs
  rubies, gems, etc. Use this recipe to get the same functionality
  previously availble by including recipe[rvm].
* recipe[rvm:user_install] - installs the RVM framwork for one or more
  isolated users. Use this recipe if you want to handle rubies yourself.
* recipe[rvm::user] - installs RVM for one or more isolated users and
  installs rubies, gems, etc. This is equivalent to recipe[rvm::system],
  but for user installs.
  • Loading branch information...
1 parent 133d340 commit 69027cafbe8e25251a797f1dcf11e5bc4c96275b @fnichol fnichol committed Aug 10, 2011
Showing with 236 additions and 56 deletions.
  1. +41 −0 libraries/chef_rvm_helpers.rb
  2. +26 −5 libraries/rvm_rubygems_package.rb
  3. +0 −44 recipes/default.rb
  4. +65 −0 recipes/system.rb
  5. +52 −0 recipes/system_install.rb
  6. +43 −0 recipes/user.rb
  7. +9 −7 recipes/user_install.rb
View
41 libraries/chef_rvm_helpers.rb
@@ -331,6 +331,47 @@ def rvmrc_template(opts = {})
end
t.run_action(:create) if install_now
end
+
+ def install_rubies(opts = {})
+ # install additional rubies
+ opts[:rubies].each do |rubie|
+ rvm_ruby rubie do
+ user opts[:user]
+ end
+ end
+
+ # set a default ruby
+ rvm_default_ruby opts[:default_ruby] do
+ user opts[:user]
+ end
+
+ # install global gems
+ opts[:global_gems].each do |gem|
+ rvm_global_gem gem[:name] do
+ user opts[:user]
+ [:version, :action, :options, :source].each do |attr|
+ send(attr, gem[attr]) if gem[attr]
+ end
+ end
+ end
+
+ # install additional gems
+ opts[:gems].each_pair do |rstring, gems|
+ rvm_environment rstring do
+ user opts[:user]
+ end
+
+ gems.each do |gem|
+ rvm_gem gem[:name] do
+ ruby_string rstring
+ user opts[:user]
+ [:version, :action, :options, :source].each do |attr|
+ send(attr, gem[attr]) if gem[attr]
+ end
+ end
+ end
+ end
+ end
end
end
end
View
31 libraries/rvm_rubygems_package.rb
@@ -61,19 +61,29 @@ class RVMRubygems < Chef::Provider::Package::Rubygems
class RVMGemEnvironment < AlternateGemEnvironment
include Chef::RVM::ShellHelpers
- attr_reader :ruby_strings
+ attr_reader :ruby_strings, :user
- def initialize(gem_binary_location, ruby_strings)
+ def initialize(gem_binary_location, ruby_strings, user = nil)
super(gem_binary_location)
@ruby_strings = ruby_strings
+ @user = user
end
def gem_paths
cmd = "rvm #{ruby_strings.join(',')} "
cmd << "exec #{@gem_binary_location} env gempath"
+ if user
+ user_dir = Etc.getpwnam(user).dir
+ environment = { 'USER' => user, 'HOME' => user_dir }
+ else
+ user_dir = nil
+ environment = nil
+ end
+
# shellout! is a fork/exec which won't work on windows
- shell_style_paths = shell_out!(rvm_wrap_cmd(cmd)).stdout
+ shell_style_paths = shell_out!(
+ rvm_wrap_cmd(cmd, user_dir), :env => environment).stdout
# on windows, the path separator is semicolon
paths = shell_style_paths.split(
::File::PATH_SEPARATOR).map { |path| path.strip }
@@ -83,7 +93,16 @@ def gem_platforms
cmd = "rvm #{ruby_strings.join(',')} "
cmd << "exec #{@gem_binary_location} env"
- gem_environment = shell_out!(rvm_wrap_cmd(cmd)).stdout
+ if user
+ user_dir = Etc.getpwnam(user).dir
+ environment = { 'USER' => user, 'HOME' => user_dir }
+ else
+ user_dir = nil
+ environment = nil
+ end
+
+ gem_environment = shell_out!(
+ rvm_wrap_cmd(cmd, user_dir), :env => environment).stdout
if jruby = gem_environment[JRUBY_PLATFORM]
['ruby', Gem::Platform.new(jruby)]
else
@@ -94,7 +113,8 @@ def gem_platforms
def initialize(new_resource, run_context=nil)
super
- @gem_env = RVMGemEnvironment.new(gem_binary_path, ruby_strings)
+ user = new_resource.respond_to?("user") ? new_resource.user : nil
+ @gem_env = RVMGemEnvironment.new(gem_binary_path, ruby_strings, user)
end
##
@@ -127,6 +147,7 @@ def install_package(name, version)
ruby_strings.each do |rubie|
next if rubie = 'system'
e = rvm_environment rubie do
+ user new_resource.user if new_user.respond_to?("user")
action :nothing
end
e.run_action(:create)
View
44 recipes/default.rb
@@ -37,47 +37,3 @@ class Chef::Recipe
# mix in recipe helpers
include Chef::RVM::RecipeHelpers
end
-
-include_recipe "rvm::system"
-
-if node['rvm']['install_rubies'] == true || node['rvm']['install_rubies'] == "true"
- # install additional rubies
- node['rvm']['rubies'].each do |rubie|
- rvm_ruby rubie
- end
-
- # set a default ruby
- rvm_default_ruby node['rvm']['default_ruby']
-
- # install global gems
- node['rvm']['global_gems'].each do |gem|
- rvm_global_gem gem[:name] do
- version gem[:version] if gem[:version]
- action gem[:action] if gem[:action]
- options gem[:options] if gem[:options]
- source gem[:source] if gem[:source]
- end
- end
-
- # install additional gems
- node['rvm']['gems'].each_pair do |rstring, gems|
- rvm_environment rstring
-
- gems.each do |gem|
- rvm_gem gem[:name] do
- ruby_string rstring
- version gem[:version] if gem[:version]
- action gem[:action] if gem[:action]
- options gem[:options] if gem[:options]
- source gem[:source] if gem[:source]
- end
- end
- end
-end
-
-# add users to rvm group
-if node['rvm']['group_users'].any?
- group 'rvm' do
- members node['rvm']['group_users']
- end
-end
View
65 recipes/system.rb
@@ -0,0 +1,65 @@
+#
+# Cookbook Name:: rvm
+# Recipe:: system
+#
+# Copyright 2010, 2011 Fletcher Nichol
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include_recipe "rvm::system_install"
+
+install_rubies = node['rvm']['install_rubies'] == true ||
+ node['rvm']['install_rubies'] == "true"
+
+if install_rubies
+ # install additional rubies
+ node['rvm']['rubies'].each do |rubie|
+ rvm_ruby rubie
+ end
+
+ # set a default ruby
+ rvm_default_ruby node['rvm']['default_ruby']
+
+ # install global gems
+ node['rvm']['global_gems'].each do |gem|
+ rvm_global_gem gem[:name] do
+ version gem[:version] if gem[:version]
+ action gem[:action] if gem[:action]
+ options gem[:options] if gem[:options]
+ source gem[:source] if gem[:source]
+ end
+ end
+
+ # install additional gems
+ node['rvm']['gems'].each_pair do |rstring, gems|
+ rvm_environment rstring
+
+ gems.each do |gem|
+ rvm_gem gem[:name] do
+ ruby_string rstring
+ version gem[:version] if gem[:version]
+ action gem[:action] if gem[:action]
+ options gem[:options] if gem[:options]
+ source gem[:source] if gem[:source]
+ end
+ end
+ end
+end
+
+# add users to rvm group
+if node['rvm']['group_users'].any?
+ group 'rvm' do
+ members node['rvm']['group_users']
+ end
+end
View
52 recipes/system_install.rb
@@ -0,0 +1,52 @@
+#
+# Cookbook Name:: rvm
+# Recipe:: system_install
+#
+# Copyright 2010, 2011 Fletcher Nichol
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include_recipe 'rvm'
+
+script_flags = build_script_flags(node['rvm']['version'], node['rvm']['branch'])
+upgrade_strategy = build_upgrade_strategy(node['rvm']['upgrade'])
+installer_url = node['rvm']['installer_url']
+rvm_prefix = ::File.dirname(node['rvm']['root_path'])
+rvm_gem_options = node['rvm']['rvm_gem_options']
+rvmrc = node['rvm']['rvmrc']
+
+install_pkg_prereqs
+
+# Build the rvm group ahead of time, if it is set. This allows avoiding
+# collision with later processes which may set a guid explicitly
+if node['rvm']['group_id'] != 'default'
+ g = group 'rvm' do
+ group_name 'rvm'
+ gid node['rvm']['group_id']
+ action :nothing
+ end
+ g.run_action(:create)
+end
+
+rvmrc_template :rvm_prefix => rvm_prefix,
+ :rvm_gem_options => rvm_gem_options,
+ :rvmrc => rvmrc,
+ :rvmrc_file => "/etc/rvmrc"
+
+install_rvm :rvm_prefix => rvm_prefix,
+ :installer_url => installer_url,
+ :script_flags => script_flags
+
+upgrade_rvm :rvm_prefix => rvm_prefix,
+ :upgrade_strategy => upgrade_strategy
View
43 recipes/user.rb
@@ -0,0 +1,43 @@
+#
+# Cookbook Name:: rvm
+# Recipe:: user
+#
+# Copyright 2011 Fletcher Nichol
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include_recipe 'rvm::user_install'
+
+node['rvm']['user_installs'].each do |rvm_user|
+ perform_install_rubies = rvm_user['install_rubies'] == true ||
+ rvm_user['install_rubies'] == "true" ||
+ node['rvm']['user_install_rubies'] == true ||
+ node['rvm']['user_install_rubies'] == "true"
+ rubies = rvm_user['rubies'] ||
+ node['rvm']['user_rubies']
+ default_ruby = rvm_user['default_ruby'] ||
+ node['rvm']['user_default_ruby']
+ global_gems = rvm_user['global_gems'] ||
+ node['rvm']['user_global_gems']
+ gems = rvm_user['gems'] ||
+ node['rvm']['user_gems']
+
+ if perform_install_rubies
+ install_rubies :rubies => rubies,
+ :default_ruby => default_ruby,
+ :global_gems => global_gems,
+ :gems => gems,
+ :user => rvm_user['user']
+ end
+end
View
16 recipes/user_install.rb
@@ -17,28 +17,30 @@
# limitations under the License.
#
+include_recipe 'rvm'
+
install_pkg_prereqs
node['rvm']['user_installs'].each do |rvm_user|
- user_home = rvm_user['home'] ||
- "#{node['rvm']['user_home_root']}/#{rvm_user['user']}"
-
script_flags = build_script_flags(rvm_user['version'], rvm_user['branch'])
upgrade_strategy = build_upgrade_strategy(rvm_user['upgrade'])
installer_url = rvm_user['installer_url'] || node['rvm']['installer_url']
- rvm_path = "#{user_home}/.rvm"
+ rvm_prefix = rvm_user['home'] ||
+ "#{node['rvm']['user_home_root']}/#{rvm_user['user']}"
rvm_gem_options = rvm_user['rvm_gem_options'] || node['rvm']['rvm_gem_options']
rvmrc = rvm_user['rvmrc'] || Hash.new
- rvmrc_template :rvm_path => rvm_path,
+ rvmrc_template :rvm_prefix => rvm_prefix,
:rvm_gem_options => rvm_gem_options,
:rvmrc => rvmrc,
:user => rvm_user['user']
- install_rvm :installer_url => installer_url,
+ install_rvm :rvm_prefix => rvm_prefix,
+ :installer_url => installer_url,
:script_flags => script_flags,
:user => rvm_user['user']
- upgrade_rvm :upgrade_strategy => upgrade_strategy,
+ upgrade_rvm :rvm_prefix => rvm_prefix,
+ :upgrade_strategy => upgrade_strategy,
:user => rvm_user['user']
end

0 comments on commit 69027ca

Please sign in to comment.