From d6eb6ce6ad3353049d826600d8e60e6815c83f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 22 Jul 2023 06:42:28 +0200 Subject: [PATCH] Wrap node commands with Capistrano This code is based on what the rvm1-capistrano and capistrano-nvm gems do, but simplified a bit to take advantage of the `fnm exec` command. Since ExecJS will check for a JavaScript runtime every time the application is started, we need to include commands like `bundle` (used when running `bin/delayed_job`), `puma` and `rake`, so Node.js is found when running these commands. I'm not sure whether `pumactl` is also necessary, but I've added it for consistency. We're also including the default commands gems like capistrano-nvm use because we will add the `npm` command in the near future. --- config/deploy.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/deploy.rb b/config/deploy.rb index 60438ff2162..465c603037d 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -46,6 +46,7 @@ def main_deploy_server "cd #{release_path} && eval \"$(fnm env)\"" end set :fnm_install_node_command, -> { "#{fetch(:fnm_setup_command)} && fnm use --install-if-missing" } +set :fnm_map_bins, %w[bundle node npm puma pumactl rake yarn] set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb" @@ -59,6 +60,8 @@ def main_deploy_server Rake::Task["delayed_job:default"].clear_actions Rake::Task["puma:smart_restart"].clear_actions + after "rvm1:hook", "map_node_bins" + after :updating, "install_ruby" after "bundler:install", "install_node" @@ -120,6 +123,20 @@ def main_deploy_server end end +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" + + fetch(:fnm_map_bins).each do |command| + SSHKit.config.command_map.prefix[command.to_sym].unshift(prefix) + end + end + end + end +end + task :refresh_sitemap do on roles(:app) do within release_path do