diff --git a/config/deploy.rb b/config/deploy.rb index f92ddeef063..ec0c17bbd7e 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -36,6 +36,16 @@ def main_deploy_server set :local_user, ENV["USER"] +set :fnm_path, "$HOME/.fnm" +set :fnm_install_command, "curl -fsSL https://fnm.vercel.app/install | " \ + "bash -s -- --install-dir \"#{fetch(:fnm_path)}\"" +set :fnm_setup_command, -> do + "export PATH=\"#{fetch(:fnm_path)}:$PATH\" && " \ + "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[node npm rake yarn] + set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb" set :delayed_job_workers, 2 @@ -50,6 +60,7 @@ def main_deploy_server after :updating, "install_ruby" after "bundler:install", "install_node" + after "bundler:install", "map_node_bins" after "deploy:migrate", "add_new_settings" @@ -90,10 +101,34 @@ def main_deploy_server end task :install_node do + on roles(:app) do + with rails_env: fetch(:rails_env) do + begin + execute fetch(:fnm_install_node_command) + rescue SSHKit::Command::Failed + begin + execute fetch(:fnm_setup_command) + rescue SSHKit::Command::Failed + execute fetch(:fnm_install_command) + else + execute "#{fetch(:fnm_install_command)} --skip-shell" + end + + execute fetch(:fnm_install_node_command) + end + end + end +end + +task :map_node_bins do on roles(:app) do within release_path do with rails_env: fetch(:rails_env) do - execute :rake, "node_manager:install:node" + 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 diff --git a/lib/tasks/node_manager.rake b/lib/tasks/node_manager.rake deleted file mode 100644 index dcc41b73bc0..00000000000 --- a/lib/tasks/node_manager.rake +++ /dev/null @@ -1,35 +0,0 @@ -namespace :node_manager do - module NodeManager - def self.manager_path - "#{File.expand_path("~")}/.fnm" - end - - def self.setup_command - "export PATH=\"#{manager_path}:$PATH\" && eval \"$(fnm env)\"" - end - end - - namespace :install do - desc "Installs or updates a Node Manager" - task :manager do - path = NodeManager.manager_path - - begin - sh NodeManager.setup_command - rescue RuntimeError - sh "curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-dir \"#{path}\"" - else - sh "curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-dir \"#{path}\" --skip-shell" - end - end - - task :node do - begin - sh "#{NodeManager.setup_command} && fnm use --install-if-missing" - rescue StandardError - Rake::Task["node_manager:install:manager"].invoke - sh "#{NodeManager.setup_command} && fnm use --install-if-missing" - end - end - end -end