Point to a railway.json in a subfolder
I have a NX monorepo with multiple projects. Should I have one railway.app json in each project? How can I tell the service in railway.app which config file to use?
51 Replies
Project ID:
N/A
N/A
what kind of configurations are you needing to do in the railway.json files?
I think I will need to tell railway to deploy our app using nodejs instead of Docker which its currently configured as because it autodetected a Dockerfile in the repo and I couldnt find anywhere to change that in the UI
if there is a dockerfile, the only way to change that would be to remove or rename it
Hmm ok so railway.json isnt able to override it?
a
Dockerfile
will always be used, theres no way to change that besides removing or renamingThanks, now it shows more things like start command and such π
One last thing, is there a similar setting to fly.io's
release_command
which is suited to run for example database migrations? https://fly.io/docs/reference/configuration/#run-one-off-commands-before-releasing-a-deploymentat what point during the build or deployment would you want to run your desired command?
Hmm I guess just before the app will be deployed. In our case it's a prisma migrations so we currently run prisma migrate deploy and if it's successful(exit code 0) only then the start cmd is ran (node build/index.js)
would running the migration during build work for you?
like as the last step of the build before the image is published and then deployed
Hmm yea I guess that could work. I will try! π
haha did you want me to show you how to set that up?
well, for that a railway.json is needed right?
yeah it can be done in a railway.json
or a nixpacks.toml
Which is preferred?
well you mentioned having to point to a specific config file in a subfolder, and i dont think you can do that with a railway.json, but you can with a nixpacks.toml
can you send me the build table at the top of the build logs and the command you want to run
The migrate command I wish to run is
npx prisma migrate deploy
with CWD in ./packages/backend
.
I would also like to run this with node 18.The migrate command I wish to run is npx prisma migrate deploy with CWD in ./packages/backend.okay so what command will execute
npx prisma migrate deploy
in ./packages/backend
without using cd
I would also like to run this with node 18.set
engines.node
to 18
in your package.jsonNot sure I understand, but I guess we would have to put
cd ./packages/backend && npx prisma migrate deploy
somewhere, maybe in the railway.json file?i think i said without using
cd
do you have a migrate script in your package.jsonno, but i could just add it like so
"migrate-backend1": "cd ./packages/backend && npx prisma migrate deploy"
right.without using
cd
because we have a nx monorepo it's contained within that package
i know
so it needs to be like executed from that context
i know
how many apps do you have in the monorepo
right now only a backend and frontend be we do got other services in other repos
how many railway services do you have
just a postgres and a compute service
im trying out railway
so I set it up today
ignoring databases, if this repo contains two apps, you need two railway services, one service for the frontend, and one service for the backend
the frontend is running at Vercel so currently it's only the one backend app I want to launch on railway
okay thanks for the clarification
add a
migrate:backend
script to your package.json prisma migrate deploy
then add this nixpacks.toml file to your project
That's the
./package.json
and not the ./packages/backend/package.json
?why not just tell railway to start from within
/packages/backend
??because we also have some common packages that's shared between frontend and backend so we need to build the backend from the root.
it's how nx wants us to do it π
pain
then yes, package.json at the root
wait a minute.. now I remember. The
npm i
has to be performed from the root because nx hoists shared packages from all packages in the monorepo but the build can be started from packages/backend without any problem even though it references packages outside.well that doesnt really help, you cant tell railway what directory to use for each step, its a one time setting
can you send your package.json
the one from the root
i see a lot of
cd
π¬all of the scripts in there are basically only used during dev
that's problematic?
its not ideal / a proper solution
are you aware of the prefix flag for npm?
yes
remove all the
cd
stuff and move over to using --prefix
let me know when thats done!hmm, it doesn't look like it's the one I linked to. --prefix seems to be a hidden and obscure flag according to this https://github.com/npm/cli/issues/1368 and should be avoided, some people say in the comments.
looks like everyone in that thread is just using it for the wrong reasons, but okay, does nx have any way to run commands in subdirectorys
turbo does, surely nx must
not sure tbh, im not fond of nx π¦
move to turbo!
in the long run ya maybe π for now im using nx, but I "gave up" and just started my app like this now and it almost seems to work:
npm run prisma:deploy && node ./packages/backend/build/index.js
that works too