lib/rvm/capistrano.rb in rvm-capistrano-1.2.7 vs lib/rvm/capistrano.rb in rvm-capistrano-1.3.0.rc1

- old
+ new

@@ -54,10 +54,13 @@ else rvm_type.to_s.empty? ? "#{rvm_path}/bin" : rvm_type.to_s end end + # Let users configure a path to export/import gemsets + _cset(:rvm_gemset_path, "#{rvm_path}/gemsets") + # Use the default ruby on the server, by default :) _cset(:rvm_ruby_string, "default") # Default sudo state _cset(:rvm_install_with_sudo, false) @@ -71,11 +74,26 @@ _cset(:rvm_install_ruby_threads, "$(cat /proc/cpuinfo | grep vendor_id | wc -l)") # Pass no special params to the ruby build by default _cset(:rvm_install_ruby_params, '') + # Additional rvm packages to install. + _cset(:rvm_install_pkgs, '') + namespace :rvm do + + command_curl_start = <<-EOF.gsub(/^\s*/, '') + export CURL_HOME=${TMPDIR:-${HOME}}/.rvm-curl-config.$$; + mkdir ${CURL_HOME}/; + { + [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc; + echo "silent"; + echo "show-error"; + } > $CURL_HOME/.curlrc + EOF + command_curl_end = "rm -rf $CURL_HOME" + desc <<-EOF Install RVM of the given choice to the server. By default RVM "stable" is installed, change with: set :rvm_install_type, :head @@ -83,20 +101,10 @@ By default BASH is used for installer, change with: set :rvm_install_shell, :zsh EOF task :install_rvm do - command_curl_start = <<-EOF.gsub(/^\s*/, '') - export CURL_HOME=${TMPDIR:-${HOME}}/.rvm-curl-config; - mkdir ${CURL_HOME}/; - { - [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc; - echo "silent"; - echo "show-error"; - } > $CURL_HOME/.curlrc - EOF - command_curl_end = "rm -rf $CURL_HOME" command_fetch = "curl -L get.rvm.io" command_install = case rvm_type when :root, :system if fetch(:use_sudo, true) == false && rvm_install_with_sudo == false raise ":use_sudo is set to 'false' but sudo is needed to install rvm_type: #{rvm_type}. You can enable use_sudo within rvm for use only by this install operation by adding to deploy.rb: set :rvm_install_with_sudo, true" @@ -132,24 +140,85 @@ task :install_ruby do ruby, gemset = rvm_ruby_string.to_s.strip.split /@/ if %w( release_path default ).include? "#{ruby}" raise "ruby can not be installed when using :rvm_ruby_string => :#{ruby}" else - run "#{File.join(rvm_bin_path, "rvm")} #{rvm_install_ruby} #{ruby} -j #{rvm_install_ruby_threads} #{rvm_install_ruby_params}", :shell => "#{rvm_install_shell}" + command_install = "#{File.join(rvm_bin_path, "rvm")} #{rvm_install_ruby} #{ruby} -j #{rvm_install_ruby_threads} #{rvm_install_ruby_params}" if gemset - run "#{File.join(rvm_bin_path, "rvm")} #{ruby} do rvm gemset create #{gemset}", :shell => "#{rvm_install_shell}" + command_install << "; #{File.join(rvm_bin_path, "rvm")} #{ruby} do rvm gemset create #{gemset}" end + _command = <<-EOF + #{command_curl_start}; + #{command_install}; + #{command_curl_end} + EOF + run "#{_command}".gsub(/[\s\n]+/, ' '), :shell => "#{rvm_install_shell}" end end + desc <<-EOF + Install RVM packages to the server. + + This must come before the 'rvm:install_ruby' task is called. + + The package list is empty by default. Specifiy the packages to install with: + + set :rvm_install_pkgs, %w[libyaml curl] + + Full list of packages available at https://rvm.io/packages/ or by running 'rvm pkg'. + EOF + task :install_pkgs do + rvm_install_pkgs.each do |pkg| + run "#{File.join(rvm_bin_path, "rvm")} pkg install #{pkg}", :shell => "#{rvm_install_shell}" + end + end + desc "Create gemset" task :create_gemset do ruby, gemset = rvm_ruby_string.to_s.strip.split /@/ if %w( release_path default ).include? "#{ruby}" raise "gemset can not be created when using :rvm_ruby_string => :#{ruby}" else if gemset run "#{File.join(rvm_bin_path, "rvm")} #{ruby} do rvm gemset create #{gemset}", :shell => "#{rvm_install_shell}" + end + end + end + + desc <<-EOF + Import file contents to the current RVM ruby gemset. + + The gemset filename must match :rvm_ruby_string.gems and be located in :rvm_gemset_path. + :rvm_gemset_path defaults to :rvm_path/gemsets + + The gemset can be created with 'cap rvm:gemset_export'. + EOF + task :import_gemset do + ruby, gemset = rvm_ruby_string.to_s.strip.split /@/ + if %w( release_path default ).include? "#{ruby}" + raise "gemset can not be imported when using :rvm_ruby_string => :#{ruby}" + else + if gemset + run "#{File.join(rvm_bin_path, "rvm-shell")} #{rvm_ruby_string} rvm gemset import #{File.join(rvm_gemset_path, "#{rvm_ruby_string}.gems")}", :shell => "#{rvm_install_shell}" + end + end + end + + desc <<-EOF + Export the current RVM ruby gemset contents to a file. + + The gemset filename will match :rvm_ruby_string.gems and be located in :rvm_gemset_path. + :rvm_gemset_path defaults to :rvm_path/gemsets + + The gemset can be imported with 'cap rvm:gemset_import'. + EOF + task :export_gemset do + ruby, gemset = rvm_ruby_string.to_s.strip.split /@/ + if %w( release_path default ).include? "#{ruby}" + raise "gemset can not be imported when using :rvm_ruby_string => :#{ruby}" + else + if gemset + run "#{File.join(rvm_bin_path, "rvm-shell")} #{rvm_ruby_string} rvm gemset export > #{File.join(rvm_gemset_path, "#{rvm_ruby_string}.gems")}", :shell => "#{rvm_install_shell}" end end end desc "Install a gem, 'cap rvm:install_gem GEM=my_gem'."