# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee module RightConf class BundlerConfigurator DEFAULT_GEM_PATH = 'vendor/system_gems/cache' include Configurator register :bundler description 'Installs bundler and runs "bundle install"' settings :version => 'Version of bundler gem, e.g. "1.0.10"', :exclusions => 'Comma separated list of gem groups to be excluded when installing bundle', :bundle_path => 'Path where bundle should be installed', :gem_path => 'Path to bundler gem, e.g. "vendor/system_gems/cache"' validate_has_settings :version # Check whether bundler is already installed # # === Return # true:: If bundler is already installed # false:: Otherwise def check_linux report_check("Checking for bundler #{version}") res = Command.execute_in_ruby('bundle', '--version') success = (res.output =~ /#{version}/) report_result(success) success end alias :check_darwin :check_linux # Not implemented on windows # # === Raise # (Exception):: Always raise def check_windows raise "Bundler is not supported on Windows!" end # Install bundler if needed and run bundle install # # === Return # true:: Always return true def run_linux install_bundler report_check('Installing gems') options = [ "_#{version}_", 'install' ] options << "--without=#{exclusions.delete(' ')}" unless exclusions.nil? options += [ '--path', bundle_path ] unless bundle_path.nil? options << { :abort_on_failure => 'Failed to install gems' } res = Command.execute_in_ruby('bundle', *options) report_success true end alias :run_darwin :run_linux # Not implemented on windows # # === Raise # (Exception):: Always raise def run_windows raise "Bundler is not supported on Windows!" end protected # Install bundler from gem in cache # # === Return # true:: Always return true # # === Raise # (Exception):: If bundler gem cannot be found or installed def install_bundler res = Command.execute_in_ruby('bundle', '--version') exists = res.success? && res.output !~ /exec: bundle: not found/ if exists && res.output !~ /#{version}/ report_check('Uninstalling existing versions of bundler') Command.execute_in_ruby('gem', 'uninstall', 'bundler', '-a', '-x') report_success end report_check("Installing bundler #{version}") if gem_path bundler_file = [ File.join(gem_path, "bundler-#{version}.gem") ] report_fatal("Missing bundler gem at #{bundler_file}") unless File.exist?(bundler_file) else bundler_file = [ 'bundler', '-v', version ] end options = [ 'gem','install' ] options += bundler_file options += [ '--no-ri', '--no-rdoc', { :abort_on_failure => 'Failed to install bundler' } ] res = Command.execute_in_ruby(*options) report_success true end end end