From e04249116995119849aa949b2e75309fff50961b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 31 Oct 2020 13:16:21 +0100 Subject: [PATCH] Speed up deployment when Ruby is already installed We were installing RVM every time we were deploying, which meant deployments took a few extra seconds and generated a lot of unneeded output even when we didn't have to update Ruby. We need to update RVM when a new Ruby version needs to be installed (otherwise we could be asking RVM to install a Ruby version which the current RVM version cannot handle), but in every other case we're fine using the already installed RVM version. We're also considering the case where the RVM command is not available. Even though the CONSUL installer installs RVM, some people might prefer to install it through Capistrano. --- config/deploy.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 1236fc326..417cf3a99 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -39,8 +39,7 @@ namespace :deploy do Rake::Task["delayed_job:default"].clear_actions Rake::Task["puma:smart_restart"].clear_actions - after :updating, "rvm1:install:rvm" - after :updating, "rvm1:install:ruby" + after :updating, "install_ruby" after "deploy:migrate", "add_new_settings" @@ -60,6 +59,26 @@ namespace :deploy do end end +task :install_ruby do + on roles(:app) do + within release_path do + begin + current_ruby = capture(:rvm, "current") + rescue SSHKit::Command::Failed + after "install_ruby", "rvm1:install:rvm" + after "install_ruby", "rvm1:install:ruby" + else + if current_ruby.include?("not installed") + after "install_ruby", "rvm1:install:rvm" + after "install_ruby", "rvm1:install:ruby" + else + info "Ruby: Using #{current_ruby}" + end + end + end + end +end + task :refresh_sitemap do on roles(:app) do within release_path do