Problems during baremetal deploy

Hey guys. First of all, I must say that I am loving the framework.

I was following the tutorial in the docs, then, I wanted to test if I could deploy the project to a vps on digital ocean, so, I started to follow the baremetal deploy guide in the docs, but I got some problems in the process.

First, when I tried to run “yarn rw deploy baremetal --first-run”, It got stuck in the “Building web” step. In the VPS, it got jammed there. Then, in the next attempts, it just quits the script execution without any feedback:

Running locally it failed, but did not returned any error:

Then, I tried to execute manually the command “yarn rw build web” (running locally):

When I try to run in the vps:

Going forward, then when I try to execute “yarn pm2 start [service]” (running locally):

I am doing something wrong? I believe I’ve followed all steps listed in the documentation, but I don’t know if I am missing something.

By the way, the code I am trying to deploy, if someone wanna give a look (this is just the guide code, with a docker-compose file for the postgresql database. About the database, It was running before I tried the deploy script):

Howdy! My guess is that the DO instance can’t handle building the web side, and it just be killing the execution of the script without any error message. How much RAM in on that instance? In my experience you need at least 1GB to get the web side to build. When you ran yarn rw build web on the server, it looks like it just gave up and dumped you back to the prompt with no error message? That’s why you’re seeing what you’re seeing in the baremetal error output (an empty box).

You’ll need to install pm2 before you can use it to monitor anything. yarn add -WD pm2

However, I’ve got a PR in the works that’s going to change how a chunk of the baremetal deploy works (including requiring a global install of pm2), you may want to wait for that to get released! Updates Baremetal deploy to use `git clone` and branch names by cannikin · Pull Request #5282 · redwoodjs/redwood · GitHub

1 Like

Hey @rob!

Thanks a lot for the reply and for the work on this awesome project. I believe you are correct, I got the smaller DO droplet instance possible to test It. I will try again on another one with more memory and I will post here the outcome.

About the part that the command “yarn rw deploy baremetal --first-run” failed (returning with a empty red box), I was running it locally on my development machine, and I believe it was not a RAM issue (but running the command “yarn rw build web” did the job), so I still don’t understand why it failed, but I will try again.

About the pm2 issue, thanks for the information. I believe I got confused with the fact that Redwood was taking care of everything and forgot that I had to install it globally first.

Yeah you’ll be able to run yarn rw build web on your development machine all day and it’ll be fine, you probably have 8 or 16GB of RAM I’m guessing?

For pm2 it’s confusing: using the current release of baremetal, you’ll need to install pm2 locally in your app (yarn add -WD pm2). And then pm2 runs on the server (the example code you had above made it look like you were trying to start it on your dev machine, but that’s incorrect!). You can test it on the server by running something like yarn pm2 status or yarn pm2 start ecosystem.config.js from within the app directory.

The next release of baremetal (which may not be the next release of Redwood, we haven’t decided yet), you’ll need to install it globally (yarn global add pm2).

1 Like

Thanks again for the help, Rob!

Yes, now that you explained the steps, is indeed kinda confusing heheh.

When I tried to install the pm2 locally with yarn add -WD pm2 I got the error below, saying that the options passed are not valid:

I am still getting a empty red box as feedback, but now I know the error is the pm2 thing.

I’ve tried to install pm2 globally with npm on the VPS and tried to run the yarn rw deploy baremetal --first-run command, but it did not worked too:

Then, I tried to install the pm2 using just yarn add pm2 (in the VPS that I am trying to deploy to) and then I tried to run yarn rw deploy baremetal --first-run and:

It seems it worked. No idea why, but I will take that win for now and proceed to the next steps to finish the deploy configs.

To give a little more of context, the machine I am trying to deploy to is a Ubuntu 20.

Going forward in the tutorial, I did the pm2 step, and then I tried to run again the yarn rw deploy baremetal:

Trying to run the commands individually:

When I check the logs to discover why they are crashing:

Error: Cannot find module '/var/www/app/redwoodblog/api'

Error: Cannot find module '/var/www/app/redwoodblog/web'

But I have both directories:

image

Maybe is my config files?

deploy.toml:

[[servers]]
host = "leieordem.net"
username = "jc"
agentForward = true
sides = ["api","web"]
path = "/var/www/app/redwoodblog"
processNames = ["serve"]

ecosystem.config.js:

module.exports = {
  apps: [
    {
      name: 'api',
      script: 'node_modules/.bin/rw',
      args: 'serve api',
      instances: 'max',
      exec_mode: 'cluster',
      wait_ready: true,
      listen_timeout: 10000,
    },
  ],
}

In the ecosystem.config.js I have only the api side because I was following the recommendation in the docs, to serve the web side from nginx (Introduction to Baremetal | RedwoodJS Docs).

Maybe I am doing something wrong?

By the way, if I can help with anything (I believe that I could help with the documentation or something), let me know, would be a pleasure to help!

The “process or namespace serve not found” sounds like you don’t have a process named “serve” in ecosystem.config.js any more. If you change the name there you need to change it in the processNames var of deploy.toml as well. I can see in your following screenshots that you have processes called api and web so I’m guessing that’s what’s going on.

Not sure what’s going on with that “module” error…where are you running the yarn pm2 commands from?

I’ve got a bunch of PRs coming for baremetal that will require a different file structure on the server, you might want to wait for those to be released (within the next couple of weeks) before spending too much more time on this current configuration!

Hello,

I’m experiencing exactly the same error as @jwandekoken

Have you found a solution to the problem?

You can see my conf here :

ecosystem.config.js :

module.exports = {
  apps: [
    {
      name: 'serve',
      cwd: 'current',
      script: 'node_modules/.bin/rw',
      args: 'serve api',
      instances: 'max',
      exec_mode: 'cluster',
      wait_ready: true,
      listen_timeout: 10000,
    },
  ],
}

deploy.toml :

[[production.servers]]
host = "xxx.xxxxxxx.com"
username = "nassim"
agentForward = true
sides = ["api"]
packageManagerCommand = "yarn"
monitorCommand = "pm2"
path = "/var/www/alpha.app"
processNames = ["api"]
repo = "ssh://git@git.xxxxxx.com:222/xxxxxxx-dev/xxxxxxx"
branch = "Dev"
keepReleases = 5



PM2 :

pm2 start api
[PM2] Starting /var/www/alpha.app/20230602124657/api in fork_mode (1 instance)
[PM2] Done.
┌────┬────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name   │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ api    │ default     │ 0.0.0   │ fork    │ 835328   │ 0s     │ 0    │ online    │ 0%       │ 25.2mb   │ nassim   │ disabled │
└────┴────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. App web differs. Type 'pm2 save' to synchronize.
nassim@dev:/var/www/alpha.app/current$ pm2 list
┌────┬────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name   │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ api    │ default     │ 0.0.0   │ fork    │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ nassim   │ disabled │
└────┴────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. App web differs. Type 'pm2 save' to synchronize.


PM2 logs : 
Error: Cannot find module '/var/www/alpha.app/20230602124657/api'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Object.<anonymous> (/home/nassim/.nvm/versions/node/v18.16.0/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
[...]

Thx for help :pray:

It looks like a similar issue: in your ecosystem.config.js file your app name is “serve”, but in deploy.toml your processNames has “api”. The list of things in processNames is what pm2 will try to start/restart, but when it goes to ecosystem.config.js to see how to start it, it can’t find any matching process named “api”.

So, change: name: 'serve' to name: 'api' and see if it works!

1 Like