From dda07fa2dd2099435b3405133c1c797ffca016b2 Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Mon, 24 Nov 2014 12:38:16 +0100 Subject: [PATCH 1/7] Fix empty output of rvm:check when log_level is not set to debug --- lib/capistrano/tasks/rvm.rake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index b2845db..79cc45b 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -5,11 +5,9 @@ namespace :rvm do desc "Prints the RVM and Ruby version on the target host" task :check do on roles(fetch(:rvm_roles, :all)) do - if fetch(:log_level) == :debug - puts capture(:rvm, "version") - puts capture(:rvm, "current") - puts capture(:ruby, "--version") - end + puts capture(:rvm, "version") + puts capture(:rvm, "current") + puts capture(:ruby, "--version") end end @@ -45,7 +43,9 @@ end Capistrano::DSL.stages.each do |stage| after stage, 'rvm:hook' - after stage, 'rvm:check' + if fetch(:log_level) == :debug + after stage, 'rvm:check' + end end namespace :load do From f36c297fc295fb4ea9d63618e3f0d257f525d19c Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Mon, 24 Nov 2014 12:39:15 +0100 Subject: [PATCH 2/7] Make rvm:check respect an exisiting .ruby-version file --- lib/capistrano/tasks/rvm.rake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index 79cc45b..4e0f599 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -5,9 +5,11 @@ namespace :rvm do desc "Prints the RVM and Ruby version on the target host" task :check do on roles(fetch(:rvm_roles, :all)) do - puts capture(:rvm, "version") - puts capture(:rvm, "current") - puts capture(:ruby, "--version") + within release_path do + puts capture(:rvm, "version") + puts capture(:rvm, "current") + puts capture(:ruby, "--version") + end end end From 8c0058075dd25512484c421108cea2dc2b41da47 Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Mon, 24 Nov 2014 12:39:46 +0100 Subject: [PATCH 3/7] Make rvm_ruby_version default to ruby version reported by rvm:check --- lib/capistrano/tasks/rvm.rake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index 4e0f599..14f3c1d 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -54,6 +54,10 @@ namespace :load do task :defaults do set :rvm_map_bins, %w{gem rake ruby bundle} set :rvm_type, :auto - set :rvm_ruby_version, "default" + set :rvm_ruby_version, proc{ + within release_path do + capture(:rvm, "current") + end + } end end From 4563fec103419efe561f3cc90e4a25662536365f Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Mon, 24 Nov 2014 13:23:41 +0100 Subject: [PATCH 4/7] Run ruby version detection on primary app server only --- lib/capistrano/tasks/rvm.rake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index 14f3c1d..3272959 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -55,8 +55,12 @@ namespace :load do set :rvm_map_bins, %w{gem rake ruby bundle} set :rvm_type, :auto set :rvm_ruby_version, proc{ - within release_path do - capture(:rvm, "current") + "".tap do |ruby_version| + on primary(:app) do + within release_path do + ruby_version << capture(:rvm, "current") + end + end end } end From 55a9f901d8eeef81348becb855e31401b9a8cb25 Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Tue, 2 Dec 2014 13:21:25 +0100 Subject: [PATCH 5/7] Redetect ruby version after the new code has been checked out --- lib/capistrano/tasks/rvm.rake | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index 3272959..f933334 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -36,8 +36,11 @@ namespace :rvm do SSHKit.config.command_map[:rvm] = "#{fetch(:rvm_path)}/bin/rvm" + # Use proc for rvm_prefix once capistrano supports it rvm_prefix = "#{fetch(:rvm_path)}/bin/rvm #{fetch(:rvm_ruby_version)} do" fetch(:rvm_map_bins).each do |command| + # We could remove that hack once capistrano supports procs for SSHKit.config.command_map.prefix + SSHKit.config.command_map.prefix[command.to_sym].reject!{ |cmd| cmd =~ /bin\/rvm / } SSHKit.config.command_map.prefix[command.to_sym].unshift(rvm_prefix) end end @@ -52,16 +55,28 @@ end namespace :load do task :defaults do + Rake::Task["load:set_rvm_defaults"].execute("default") + end + + task :set_rvm_defaults do |task, ruby_version| set :rvm_map_bins, %w{gem rake ruby bundle} set :rvm_type, :auto - set :rvm_ruby_version, proc{ - "".tap do |ruby_version| - on primary(:app) do - within release_path do - ruby_version << capture(:rvm, "current") - end - end + set :rvm_ruby_version, ruby_version + + # We could remove that hack once capistrano supports procs for SSHKit.config.command_map.prefix + Rake::Task["rvm:hook"].execute + end +end + +namespace :deploy do + task :set_current_revision do + on primary(:app) do + within release_path do + ruby_version = capture(:rvm, "current") + # FIX ME: when calling `set :rvm_ruby_version, ruby_version` here directly + # fetch(:rvm_ruby_version) in other tasks still returns the old value...?! + Rake::Task["load:set_rvm_defaults"].execute(ruby_version) end - } + end end end From e423b501c5e9b45c6ef63419f26d37995f931fee Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Tue, 2 Dec 2014 13:32:43 +0100 Subject: [PATCH 6/7] I added PR to sshkit to support procs for command prefixes, take already advantage of it --- lib/capistrano/tasks/rvm.rake | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index f933334..f127382 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -36,11 +36,8 @@ namespace :rvm do SSHKit.config.command_map[:rvm] = "#{fetch(:rvm_path)}/bin/rvm" - # Use proc for rvm_prefix once capistrano supports it - rvm_prefix = "#{fetch(:rvm_path)}/bin/rvm #{fetch(:rvm_ruby_version)} do" + rvm_prefix = proc{ "#{fetch(:rvm_path)}/bin/rvm #{fetch(:rvm_ruby_version)} do" } fetch(:rvm_map_bins).each do |command| - # We could remove that hack once capistrano supports procs for SSHKit.config.command_map.prefix - SSHKit.config.command_map.prefix[command.to_sym].reject!{ |cmd| cmd =~ /bin\/rvm / } SSHKit.config.command_map.prefix[command.to_sym].unshift(rvm_prefix) end end @@ -62,9 +59,6 @@ namespace :load do set :rvm_map_bins, %w{gem rake ruby bundle} set :rvm_type, :auto set :rvm_ruby_version, ruby_version - - # We could remove that hack once capistrano supports procs for SSHKit.config.command_map.prefix - Rake::Task["rvm:hook"].execute end end From 219a63265e828d7ddb0ff5d02d81b594439aca10 Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Tue, 16 Dec 2014 21:24:06 +0100 Subject: [PATCH 7/7] Use current ruby instead of default by default --- lib/capistrano/tasks/rvm.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index f127382..cc81f5c 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -52,7 +52,7 @@ end namespace :load do task :defaults do - Rake::Task["load:set_rvm_defaults"].execute("default") + Rake::Task["load:set_rvm_defaults"].execute("current") end task :set_rvm_defaults do |task, ruby_version|