Node version

Im updating my cms directus to the last version "10.2.1" that version only runs with node LTS 18.16.0 so in my package.json I added also
"engines": {
"node": "18.16.0"
}
"engines": {
"node": "18.16.0"
}
But when trying to build seems docker doesn't have that node version. How I can configure railways to use that node version? error:
#10 13.07 npm ERR! code EBADENGINE
#10 13.07 npm ERR! engine Unsupported engine
#10 13.07 npm ERR! engine Not compatible with your version of node/npm: [email protected]
#10 13.07 npm ERR! notsup Not compatible with your version of node/npm: [email protected]
#10 13.07 npm ERR! notsup Required: {"node":"18.16.0"}
#10 13.07 npm ERR! notsup Actual: {"npm":"8.19.2","node":"v18.12.1"}
#10 13.08
#10 13.08 npm ERR! A complete log of this run can be found in:
#10 13.08 npm ERR! /root/.npm/_logs/2023-06-07T16_11_26_937Z-debug-0.log
#10 ERROR: process "/bin/bash -ol pipefail -c npm i" did not complete successfully: exit code: 1
#10 13.07 npm ERR! code EBADENGINE
#10 13.07 npm ERR! engine Unsupported engine
#10 13.07 npm ERR! engine Not compatible with your version of node/npm: [email protected]
#10 13.07 npm ERR! notsup Not compatible with your version of node/npm: [email protected]
#10 13.07 npm ERR! notsup Required: {"node":"18.16.0"}
#10 13.07 npm ERR! notsup Actual: {"npm":"8.19.2","node":"v18.12.1"}
#10 13.08
#10 13.08 npm ERR! A complete log of this run can be found in:
#10 13.08 npm ERR! /root/.npm/_logs/2023-06-07T16_11_26_937Z-debug-0.log
#10 ERROR: process "/bin/bash -ol pipefail -c npm i" did not complete successfully: exit code: 1
Project id: 151b2302-1f55-438d-9d30-a2d6311ce39d Thanks
91 Replies
Percy
Percy2y ago
Project ID: 151b2302-1f55-438d-9d30-a2d6311ce39d
Brody
Brody2y ago
nixpacks only parses major versions from engines.node eg. 16 or 18 so 18.16.0 turns into 18 then nixpacks uses whatever node 18 version is available in the nix packages
Brody
Brody2y ago
this behavior is specfiied in the nixpacks docs here https://nixpacks.com/docs/providers/node#setup
Brody
Brody2y ago
to use a very specific node version, i recommend using a dockerfile, where you can specify the base image to use the exact node version of your choosing eg. FROM node:18.16.0-slim
octavioamu
octavioamuOP2y ago
I don't plan to use docker on this project is a monorepo where one of the apps is hosted on railways and the rest are vercel apps, I can even move it to a new repo but avoid these headeaches was the reason for the team using railway instead of aws. There is a simple docker file template where I can just specify the node version? is kind of crazy the lts version is not supported by default
Brody
Brody2y ago
you dont need to use docker, the dockerfile is only for railway, and there are plenty of great node dockerfiles floating around on the interwebs 🙂 you just place the dockerfile in the subfolder that is your railway app
octavioamu
octavioamuOP2y ago
sorry Im not very familiar with dockerfiles + the specifics of railway we are just starting using it. Can you provide me a template I can include on the root of the project? I clicked on "ask an eng" on the railway interface but probably that would take longer *talk to an engineer"
Brody
Brody2y ago
it would be quite hard to make you a dockerfile without seeing your repo, could you link your repo?
octavioamu
octavioamuOP2y ago
cannot share because is private and have others apps on the monorepo but the code for that one is actually just an npm install I will share here package.json
{
"name": "mantle-cms",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "npx directus start",
"dev:cms": "npx directus start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"directus": "^10.2.1",
"sqlite3": "^5.1.4"
},
"engines": {
"node": "18.16.0"
}
}
{
"name": "mantle-cms",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "npx directus start",
"dev:cms": "npx directus start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"directus": "^10.2.1",
"sqlite3": "^5.1.4"
},
"engines": {
"node": "18.16.0"
}
}
octavioamu
octavioamuOP2y ago
the rest I believe doesn't affect basically railways just runs npx directus start which is currently working fine, no specifics things are setup more than env keys on railway side
Brody
Brody2y ago
you will want to switch over to using a postgre database with railway, railway doesnt have persistent storage so every deploy will wipe your sqlite file
octavioamu
octavioamuOP2y ago
yes the project is already setup on production running on railway with postgress
Brody
Brody2y ago
where is your package-lock.json ?
octavioamu
octavioamuOP2y ago
octavioamu
octavioamuOP2y ago
well is probably on the root of monorepo as is using pnpm give me a second
Brody
Brody2y ago
im gonna write a dockerfile that needs a package-lock file in that directory
octavioamu
octavioamuOP2y ago
Ok sounds good I will figure out
Brody
Brody2y ago
since installs deps from lockfile is faster
octavioamu
octavioamuOP2y ago
Thanks Brody
octavioamu
octavioamuOP2y ago
the pnpm-lock.yaml is on the root of the project
octavioamu
octavioamuOP2y ago
Brody
Brody2y ago
that doesnt really apply when in a sub directory
octavioamu
octavioamuOP2y ago
will check if there is a pnpm config to generate the lock file on the app directory
Brody
Brody2y ago
just go run npm i --package-lock-only in that directory npm lock file please, i have never used pnpm
octavioamu
octavioamuOP2y ago
sadly monorepos are a pain in the ass
Brody
Brody2y ago
^
octavioamu
octavioamuOP2y ago
let me move this app outside of the mono repo, as is giving me more headeaches
Brody
Brody2y ago
whatever works for you i advise you change dev:cmd to start
octavioamu
octavioamuOP2y ago
I was complaining already about being on a monorepo so is a good move cool yes with the change start will be possible
Brody
Brody2y ago
untested of course, so let me know how that goes
octavioamu
octavioamuOP2y ago
GitHub
GitHub - windranger-io/mantle-cms: Mantle cms
Mantle cms. Contribute to windranger-io/mantle-cms development by creating an account on GitHub.
octavioamu
octavioamuOP2y ago
will add
Brody
Brody2y ago
remember to do this
octavioamu
octavioamuOP2y ago
im just building locally first to check if my config works
Brody
Brody2y ago
the cms service on railway, is it using variable references for the database variables? (do they have a little postgre icon besides the variable names)
octavioamu
octavioamuOP2y ago
yes is using railway postgress services with internal variables
Brody
Brody2y ago
the variables in your service have the little postgre icon?
octavioamu
octavioamuOP2y ago
yes
Brody
Brody2y ago
perfect!
octavioamu
octavioamuOP2y ago
octavioamu
octavioamuOP2y ago
and basically all pointing to the service ${{Postgres}}
Brody
Brody2y ago
looks good
octavioamu
octavioamuOP2y ago
ok pushed will do the changes on railway side to point to the new repo and see if trigger now with the dockerfile
Brody
Brody2y ago
and im sure you know this already but since it seems like you are deploying a commercial product on railway, your team will need to be on the team plan
octavioamu
octavioamuOP2y ago
yep we are we created an org and added credit card I believe we are on the team plan right?
octavioamu
octavioamuOP2y ago
octavioamu
octavioamuOP2y ago
yep
Brody
Brody2y ago
great also, your package.json still has sqlite3 but youd need pg instead afaik also, also, missing the start script too
octavioamu
octavioamuOP2y ago
I updated the develop branch but seems there is a problem with line 13 COPY --chown=node:node ./ ERROR: failed to solve: dockerfile parse error on line 13: COPY requires at least two arguments, but only one was provided. Destination could not be determined.
Brody
Brody2y ago
oh my bad
octavioamu
octavioamuOP2y ago
seems is missing destination right?
Brody
Brody2y ago
COPY --chown=node:node . ./ technically missing the source, that should work I did say untested lol 🙂
octavioamu
octavioamuOP2y ago
thanks is going
Brody
Brody2y ago
how's it going?
octavioamu
octavioamuOP2y ago
do I need to do something to the variables get on the container?
Brody
Brody2y ago
explain please all the service variables are injected into the container/deployment as regular environment variables along with all the railway variables listed in the docs
octavioamu
octavioamuOP2y ago
I have a file like this https://github.com/kadumedim/directus-starter/blob/master/directus.config.js but seems the container cannot read them
GitHub
directus-starter/directus.config.js at master · kadumedim/directus-...
Contribute to kadumedim/directus-starter development by creating an account on GitHub.
Brody
Brody2y ago
are the environment variables named the same way as they are in your railway service?
octavioamu
octavioamuOP2y ago
yes and was working without the dockerfile I don't need to define those variables inside the dockerfile?
Brody
Brody2y ago
you commented out that COPY line?? and added in your own chown command please revert back to the dockerfile I provided, with this corrected copy command
octavioamu
octavioamuOP2y ago
yes ok
Brody
Brody2y ago
you still have sqlite as a dependency, you'd need pg instead
octavioamu
octavioamuOP2y ago
ahh is for running locally wouldn't affect the config file is already setup to be pg
Brody
Brody2y ago
then move sqlite to the dev dependencies, since railway doesn't need to install it and regardless, you use postgres on railway, so wouldn't you need the pg dependency
octavioamu
octavioamuOP2y ago
[Error: EACCES: permission denied, mkdir '/app/.cache'] { errno: -13, code: 'EACCES', syscall: 'mkdir', path: '/app/.cache' } Node.js v18.16.0 node:internal/process/promises:288 ^ [Error: EACCES: permission denied, mkdir '/app/.cache'] { triggerUncaughtException(err, true /* fromPromise /); errno: -13, code: 'EACCES', syscall: 'mkdir', path: '/app/.cache' } Node.js v18.16.0 node:internal/process/promises:288 triggerUncaughtException(err, true / fromPromise */); ^ [Error: EACCES: permission denied, mkdir '/app/.cache'] { errno: -13, code: 'EACCES', syscall: 'mkdir', path: '/app/.cache' } Node.js v18.16.0
Brody
Brody2y ago
FROM node:18.16.0-slim

ENV NODE_ENV production

WORKDIR /app

COPY package*.json ./

RUN npm ci --only=production

COPY . ./

CMD ["npm", "run", "start"]
FROM node:18.16.0-slim

ENV NODE_ENV production

WORKDIR /app

COPY package*.json ./

RUN npm ci --only=production

COPY . ./

CMD ["npm", "run", "start"]
use that instead
octavioamu
octavioamuOP2y ago
do you have idea why twhen pushing it skipps the build?
Brody
Brody2y ago
do you have any watch paths set?
octavioamu
octavioamuOP2y ago
yes seem was that was /** should be just /* ?
Brody
Brody2y ago
you can just remove it
octavioamu
octavioamuOP2y ago
oh builded no log errors but is failing https://mantle-xyz-staging.up.railway.app/
Brody
Brody2y ago
can I see the deploy logs?
octavioamu
octavioamuOP2y ago
octavioamu
octavioamuOP2y ago
octavioamu
octavioamuOP2y ago
The push refers to repository [us-west1-docker.pkg.dev/railway-infra/railway-docker-users/project/151b2302-1f55-438d-9d30-a2d6311ce39d/service/4e0ba9f0-2626-4abc-8cdf-5f86fd998419]
Brody
Brody2y ago
you will want to remove any build or start commands you have in your service settings like that thingy says
octavioamu
octavioamuOP2y ago
ok
Brody
Brody2y ago
also, perhaps your app isn't listening on host 0.0.0.0?
octavioamu
octavioamuOP2y ago
but is that what is making the app fail?
Brody
Brody2y ago
no, it's just making the annoying warning appear so try this instead of what you have in your config
PUBLIC_URL: `http://0.0.0.0:${env.PORT}`,
PUBLIC_URL: `http://0.0.0.0:${env.PORT}`,
octavioamu
octavioamuOP2y ago
PUBLIC_URL: https://${env.RAILWAY_STATIC_URL}, ok
Brody
Brody2y ago
yeah, but try the line I sent instead of yours
octavioamu
octavioamuOP2y ago
will try but I believe is not that as the error page is from directus, so seems is reading the 404 from the app
Brody
Brody2y ago
Brody
Brody2y ago
there's no error page anymore
octavioamu
octavioamuOP2y ago
wait you are seing that? but didn't end up deploying crazy is running
Brody
Brody2y ago
that means railway made your app live before the app was ready to handle requests, you will want to setup a healthcheck so that railway makes the app live only when it's able to handle requests https://docs.railway.app/deploy/healthchecks this way any future deployment will only be made live when the new deployment is ready to handle requests, thus giving you a zero downtime switch over
octavioamu
octavioamuOP2y ago
great worked now I will do it on prod thanks
Brody
Brody2y ago
sweet if you have any more questions, feel free to ask, but I will be gone for an hour or so soon
octavioamu
octavioamuOP2y ago
thanks Brody worked on prod
Want results from more Discord servers?
Add your server