lib/rconf/configurators/ruby_configurator.rb in rconf-1.0.8 vs lib/rconf/configurators/ruby_configurator.rb in rconf-1.0.9

- old
+ new

@@ -9,10 +9,22 @@ # License Agreement between RightScale.com, Inc. and # the licensee module RightConf + # Specify rbenv and ruby-build git revision for installation + RBENV_GIT_REPO = 'git://github.com/sstephenson/rbenv.git' + RBENV_GIT_REVISION = "9375e99f921f428849f19efe2a2e500b3295d1a7" + + RUBYBUILD_GIT_REPO = 'git://github.com/sstephenson/ruby-build.git' + RUBY_BUILD_GIT_REVISION = "28b9bcb6df1bc18fb2b06e25ee65f397ac3d4632" + + # Local installation target folders + RBENV_INSTALL_TARGET = "#{ENV['HOME']}/.rbenv" + RUBYBUILD_TARGET = "#{RBENV_INSTALL_TARGET}/plugins/ruby-build" + + class RubyConfigurator include Configurator register :ruby @@ -20,17 +32,19 @@ description "Installs ruby interpreter and rubygems.\n" + 'Installs and uses rbenv on supported (i.e. non-Windows) platforms' setting 'version', 'Ruby version using rbenv notation (see "rbenv versions")', :required => true + updater lambda { update_rbenv_installation } + + # Message to display to the user when rbenv isn't in the path. - PATH_ADVICE = "You should add 'eval \"$(rbenv init -)\"' to your .bash_profile / .bashrc etc. " + - "so rbenv is properly initialized in new shells.\n\n" + - "If you are a bash user (e.g. Mac OS X), you can add the following to ~/.bash_profile:\n\n" + - " echo 'eval \"$(rbenv init -)\"' >> ~/.bash_profile\n\n" + - "You should also update your PATH environment variable with:\n\n" + - " echo 'export PATH=\"$HOME/.rbenv/shims:$PATH\" >> ~/.bash_profile'\n" + PATH_ADVICE = "You should add rbenv to your path and 'eval \"$(rbenv init -)\"' to your .bash_profile / .bashrc etc. " + + "so rbenv is properly initialized in new shells.\n\n" + + "If you are a bash user (e.g. Mac OS X), you can add the following to ~/.bash_profile:\n\n" + + " echo 'export PATH=\"$HOME/.rbenv/bin:$PATH\"' >> ~/.bash_profile\n" + + " echo 'eval \"$(rbenv init -)\"' >> ~/.bash_profile\n\n" # Let configurator run, it is idempotent # # === Return # false:: Always return false @@ -88,29 +102,106 @@ if rbenv_present && !rbenv_in_path # Bail if rbenv isn't correctly initialized (we can't use it in this state) post_note "rconf detected rbenv is installed in #{rbenv_path} but it is not in the PATH.\n" + PATH_ADVICE aborting(true) - elsif rbenv_present && rbenv_in_path + elsif rbenv_in_path # rbenv is installed and initialized; make sure we have a suitable version res.output =~ /^rbenv ([0-9]+)\.([0-9]+)\.([0-9]+)$/ maj, min, build = [$1.to_i, $2.to_i, $3.to_i] if maj == 0 && min < 4 report_fatal("rconf requires rbenv version 0.4.0 or greater, you have #{maj}.#{min}.#{build} installed, "+ "please upgrade (e.g. via 'brew upgrade rbenv') and try again") end else # No sign of rbenv; try to install it - opts = { :report => true, :post_install => update_msg }.merge(abort_option('Failed to install rbenv')) - PackageInstaller.install('rbenv', opts) - opts = { :report => true }.merge(abort_option('Failed to install ruby-build')) - PackageInstaller.install('ruby-build', opts) + install_rbenv_from_git end true end + + # Overwrite ruby-build definition file to use our own, patched version of REE and to set certain compile options + # so that it REE works with newer versions of GCC as well. + # + # === Return + # true:: Always return true + def self.add_custom_ree_definition + curr_dir=File.dirname(__FILE__) + patched_ree = "#{curr_dir}/../../patches/ree-1.8.7-2012.02-rs-custom" + FileUtils.cp patched_ree, "#{RUBYBUILD_TARGET}/share/ruby-build/ree-1.8.7-2012.02" + + true + end + + + # Update rbenv and ruby-build to the version specified through the git commit version constant + # + # === Return + # true:: Always return true + def self.update_rbenv_installation + puts "Updating rbenv ..." + if File.directory?("#{RBENV_INSTALL_TARGET}/.git") + # Perform the pull only if rbenv has been installed by using a git pull (and not through a package manager) + system("cd #{RBENV_INSTALL_TARGET}; git fetch -q; git checkout -q #{RBENV_GIT_REVISION}") + end + + puts "Updating ruby-build ..." + if File.directory?("#{RUBYBUILD_TARGET}/.git") + # Perform the pull only if ruby-build has been installed by using a git pull (and not through a package manager) + # Before checking out the new branch, reset the repository to avoid conflicts + system("cd #{RUBYBUILD_TARGET}; git reset -q --hard; git fetch -q; git checkout -q #{RUBY_BUILD_GIT_REVISION}") + + # Add our ree definition again because the repository has been reset + RubyConfigurator.add_custom_ree_definition + end + + true + end + + + # Install rbenv + # 1. Fetch rbenv from repository and install it + # 2. Fetch ruby-build from repository and install it + # 3. Install custom ree installation definition into ruby-build so that our patched REE gets installed + # + # === Return + # true:: Always return true + def install_rbenv_from_git + + # Require: git + res = Command.execute('git', '--version').success? + if !res + # Install git + opts = { :report => true, :post_install => update_msg }.merge(abort_option('Failed to install git, required for rbenv')) + PackageInstaller.install('git', opts) + end + + + # Fetch and install rbenv + # *********************** + + # Fetch rbenv from git repo + Command.execute('git', 'clone', RBENV_GIT_REPO, RBENV_INSTALL_TARGET, {:abort_on_failure => 'Git clone of rbnev failed - server down?'}) + Kernel.system("cd #{RBENV_INSTALL_TARGET}; git checkout #{RBENV_GIT_REVISION}") + + # Fetch, install and patch ruby-build + # *********************************** + + # Create plugins directory (target for ruby-build) + ret = FileUtils.mkdir_p(RUBYBUILD_TARGET) + if !ret + report_fatal("Could not create directory: #{RUBYBUILD_TARGET}"); + end + + Command.execute('git', 'clone', RUBYBUILD_GIT_REPO, RUBYBUILD_TARGET, {:abort_on_failure => 'Git clone of ruby-build failed - server down?'}) + Kernel.system("cd #{RUBYBUILD_TARGET}; git checkout #{RUBY_BUILD_GIT_REVISION}") + + RubyConfigurator.add_custom_ree_definition + end + # Check .ruby-version and its content # # === Return # true:: Always return true def check_ruby @@ -188,12 +279,10 @@ # === Return # true:: Always return true def install_ruby_prerequisites_linux_ubuntu(ruby) report_check("Installing required packages, this could take a while") packages = [] - if ruby =~ /^ree-|^ruby-/ - packages = %w(build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev) - end # TBD Define packages needed for other rubies + packages = %w(build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev) Command.sudo('apt-get', 'install', '-y', *packages) report_success end alias install_ruby_prerequisites_linux_debian install_ruby_prerequisites_linux_ubuntu