Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depend on a specific version of Node.js #5158

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
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.

Note that, in order to setup FNM, we need to enter the actual release
folder (using `within release_path` isn't enough). So we have to run
this task after the actual release is created; otherwise many commands
would run in the previous release's folder.
  • Loading branch information
javierm committed Oct 17, 2023
commit f209325b902659bddf39e84e032c565513a9070b
17 changes: 17 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def main_deploy_server
"cd #{release_path} && fnm env > /dev/null && 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"

Expand All @@ -59,6 +60,8 @@ def main_deploy_server
Rake::Task["delayed_job:default"].clear_actions
Rake::Task["puma:smart_restart"].clear_actions

after "git:create_release", "map_node_bins"

after :updating, "install_node"
after :updating, "install_ruby"

Expand Down Expand Up @@ -120,6 +123,20 @@ def main_deploy_server
end
end

task :map_node_bins do
javierm marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down