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 Oct 10, 2023
1 parent 8080f4c commit db7fd28
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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_update_command, "#{fetch(:fnm_install_command)} --skip-shell"
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 :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb"

set :delayed_job_workers, 2
Expand All @@ -50,6 +60,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 @@ -89,6 +100,26 @@ def main_deploy_server
end
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_update_command)
end

execute fetch(:fnm_install_node_command)
end
end
end
end

task :refresh_sitemap do
on roles(:app) do
within release_path do
Expand Down

0 comments on commit db7fd28

Please sign in to comment.