From ddc8cfdfb016d737580ecaed9cf9c238f41a8705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= <15726+Senen@users.noreply.github.com> Date: Tue, 24 Oct 2023 12:55:06 +0200 Subject: [PATCH] Map node binaries whenever `rvm1:hook` is called and evaluate the `fnm_setup_command` dynamically The previous version worked fine when using Capistrano to deploy a new release, but it did not work for other commands, like `cap npm install` or `cap puma:start`, as they do not create a release. Therefore, the `git:create_release` was never called, and the `map_node_bins` was not invoked. Since we need node binaries available to the deploy user when executing any process that runs the application, like puma, delayed_job, and rake tasks, among others, it makes sense to load FNM to use the correct Node version in the same places where Capistrano loads RVM to load the correct Ruby version. With dynamic loading of the `fnm_setup_command`, we get the correct path when deploying a new release and also when running any other capistrano command that does not deploy a new release. --- config/deploy.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 657b14f80..35a6b1a5b 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -60,7 +60,7 @@ namespace :deploy do Rake::Task["delayed_job:default"].clear_actions Rake::Task["puma:smart_restart"].clear_actions - after "git:create_release", "map_node_bins" + after "rvm1:hook", "map_node_bins" after :updating, "install_node" after :updating, "install_ruby" @@ -127,7 +127,7 @@ task :map_node_bins do on roles(:app) do within release_path do with rails_env: fetch(:rails_env) do - prefix = "#{fetch(:fnm_setup_command)} && fnm exec" + prefix = -> { "#{fetch(:fnm_setup_command)} && fnm exec" } fetch(:fnm_map_bins).each do |command| SSHKit.config.command_map.prefix[command.to_sym].unshift(prefix)