Skip to content

Commit

Permalink
Install Node.js on deploy
Browse files Browse the repository at this point in the history
We use FNM instead of NVM. Reason: the setup seems easier with just
`eval "$(fnm env)"`.
  • Loading branch information
javierm committed Aug 7, 2023
1 parent 7c3ea35 commit bf4f20d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def main_deploy_server
Rake::Task["puma:smart_restart"].clear_actions

after :updating, "install_ruby"
after "bundler:install", "install_node"

after "deploy:migrate", "add_new_settings"

Expand Down Expand Up @@ -88,6 +89,16 @@ def main_deploy_server
end
end

task :install_node do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "node_manager:install:node"
end
end
end
end

task :refresh_sitemap do
on roles(:app) do
within release_path do
Expand Down
35 changes: 35 additions & 0 deletions lib/tasks/node_manager.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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

0 comments on commit bf4f20d

Please sign in to comment.