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

Depend on a specific version of Node.js #5158

merged 3 commits into from
Oct 18, 2023

Commits on Oct 17, 2023

  1. Depend on a specific version of Node.js

    We're choosing version 18 because if offers support for SSL 3, just
    like Ruby 3.1 does.
    
    Note we're symlinking a .nvmrc file as well, in order to make it
    compatible with NVM. While the .nvmrc and .node-version files use
    different formats, they both support the syntax we're using to
    define the version.
    
    The code to install Node.js in the Dockerfile is a simplification of the
    code in the Rails Dockerfile template [1].
    
    [1] https://github.com/rails/rails/blob/04c97aec8a/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt#L25
    javierm committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    55ed40e View commit details
    Browse the repository at this point in the history
  2. Install Node.js on deploy

    We use FNM instead of NVM. Reason: the setup seems easier with just
    `eval "$(fnm env)"`.
    
    So now, we try to install Node.js; if the command fails, it could be
    because FNM isn't installed (and we need to install it) or because the
    version of Node.js cannot be installed with the current version of FNM
    (and we need to update FNM). After installing/updating FNM, we try to
    install Node.js again.
    
    Note we're using `fnm env` in the middle of the `fnm_setup_command`.
    That way, the command will raise a `SSHKit::Command::Failed` exception
    if `fnm` isn't installed, and it will give us an indicator that we need
    to actually install it.
    javierm committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    8ab66dd View commit details
    Browse the repository at this point in the history
  3. 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.
    javierm committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    f209325 View commit details
    Browse the repository at this point in the history