How to use railway with monorepo?
I created a new project and essentially my server code is not at the top level, and instead is one directory down. How do I configure this with railway?
104 Replies
Project ID:
N/A
N/A
should have known there was going to be a setting for this. but in my defense... i did try to search for it and i got no hits. but of course i try now and its there in settings. š¤¦āāļø
thanks Brody!
I wonder if i have to move my custom nixpack.toml into the new root folder... hmmmm
you would likely have the nixpacks.toml in the subfolder and then set the location to it with the
NIXPACKS_CONFIG_FILE
variablethanks. just moved it to the subfolder, so I will give that a shot. still find it weird that variables cant be in version control (like PORT 8080)
wdym version control? like github?
yeah
its a variable that controls the platform, so it needs to be set on the platform itself
but side node, there would be no need for you to set a PORT variable yourself as long as your app listens on the automatically generated PORT variable
oh hmmm. i wonder if i can do that on ktor. i guess the auto generated port variable is set as an env variable?
yep it would be an environment variable, and yes you can do it with ktor, remove the PORT variable you set, now railway will randomly assign one behind the scenes, now all your app has to do is read the PORT environment variable and listen on it
very cool. thanks for teaching.
cant seem to get railway to use my /server directory. lmao
what makes you think that?
haha okay well more specifically?
Error: Failed to read Nixpacks config file
nixpacks.toml
Caused by:
0: Error reading nixpacks.toml
1: No such file or directory (os error 2)what did you set that
NIXPACKS_CONFIG_FILE
to?its blue
have you not deployed the changes?
I did, I was just changing things back and forth again
Tried
/server
/server/nixpacks.toml
/nixpacks.toml
second option seems like the best
but without seeing your project structure i dont know for sure
oh maybe you dont need to set that variable if the root directory is set, try omitting it
this is my /server
Nope. same issue even if i remove the env variable. already tried that, and just tried again
Error: Failed to read Nixpacks config file
nixpacks.toml
Caused by:
0: Error reading nixpacks.toml
1: No such file or directory (os error 2)you completely removed the
NIXPACKS_CONFIG_FILE
variable from your service?
but those logs would indicate that its still setyou know what. i bet you i know the issue
i dont think i have a "true" monorepo
the root project is still a gradle project. so i probably actually dont want to change root, but I instead might want to move the nixpacks.toml.
what two apps are in this repo?
i used kmp.jetbrains.com to generate the project
and so i have two mobile apps (ios and android) and a server directory (ktor)
interesting
but yeah. its not a completely isolated project
i.e. isolated monorepo vs shared monorepo
yeah this is more like a shared monorepo, and in that case you liking don't want to set a root directory
doesn't seem like its picking up my nixpacks.toml even though its in the root of the project. do i need to set a variable even if its in the root?
yeah. if i just set the build command directly in the railway dashboard then things build properly. not sure why it doesn't like my nixpacks.toml
very odd
ill figure it out. im gettin good at this stuff. š
rubberducking...
i think my nixpacks.toml file is wrong
very wrong
did gpt write that for you
no. i used the docs
https://docs.railway.app/reference/config-as-code#nixpacks-config-path
thats for a railway.toml
bah. wheres the nixpacks docs. lmaooo
we can pivot to a railway.toml if thats what you'd like to do?
https://nixpacks.com/docs/configuration/file
i guess i dont really care. i was just using what i learned in the last thread (from aleks)
maybe a railway.json would even be best? since it has schema validation
interesting. how does it do schema validation? on the railway side? or can i somehow validate locally?
but anyway. yeah. i did what you said and it worked
the
$schema
value links to the schema file and then vscode tells you if you did something very wrongmaybe railway.json will be a project for tomorrow.
dont use vscode (using jetbrains fleet) lol.
i cant see why it wouldnt do json validation as well
gotta shut the laptop for a bit. but. let me know if you have any pref between doing a railway.json/toml vs a nixpacks.toml
i am a big fan of config as code. so i want to do that where possible.
i like railway.json by far, since you can embed a nixpacks.toml file into it and have schema validation!
New reply sent from Help Station thread:
At the same time, though, your nixpacks settings in railway.json
will only be respected by Railway's nixpacks, so local nixpacks builds won't respect those settings. If that's not a concern, though, JSON schema validation is always great.
You're seeing this because this thread has been automatically linked to the Help Station thread.Alright. Going to try to convert to railway.json
i guess if railway.json exists, it'll just use it?
correct
because i just converted the file and everything seems to be building fine
cool
lets see the file you came up with
should i also just add the rest of this stuff?
I just plugged in the file you passed over š„°
its not needed, unless you want to set that stuff from your railway.json file
sent some trains over. šø cheers buddy
ah thanks ā¤ļø
im curious now about this json validation thing. ive never heard of that in my life. lol
not sure if jetbrains fleet is doing any sort of validation for me lol
hey, my first introduction to it was when i edited my first railway.json too!
i can't imagine fleet not doing the schema validation
i guess thats validation in action?
yeah thats it, its not gonna help you make sure what you do is going to do what you want, but it will let you know if what youre doing is not valid
awesome. gonna try the port number thing and get some sleep. hopefully its easy peasy
https://docs.railway.app/reference/variables#railway-provided-variables
Assuming I'm after
RAILWAY_TCP_APPLICATION_PORT
even though the docs for that seem wrong? i think its a copy pasta issue
nope, just
PORT
hm. howd you find that out? lol. sorry i try to find docs, but did i miss something here?
mainly covered here https://docs.railway.app/guides/fixing-common-errors
and here https://docs.railway.app/guides/public-networking#port-variable
thanks. for whatever reason... it seems like RAILWAY_TCP_APPLICATION_PORT also worked? unless it actually just defaulted to 8080 and that worked. going to switch to plain ol "PORT" now... š¤
oooh. very interesting. PORT didn't work...
do you have a tcp proxy on your service? if you do, you shouldn't
i dont believe so
actually
wait. i think it did work
but i had downtime. which caused me to think it didn't work.
ill refer back to the convo we had about health check or w/e
i think this is close enough to what you're running?
a health check and
RAILWAY_DEPLOYMENT_OVERLAP_SECONDS
set to 35
is what the team (and me) are currently recommending until railway rolls out the new and faster http proxyokay. so RAILWAY_TCP_APPLICATION_PORT doesn't actually work. it was because if i can't find the env variable defined, then it chooses 8080
and somehow using 8080 as a default works now.
or actually. nope.
so the goal here would be to not have a PORT variable defined on your service
looks like its just a nice long delay again that was misleading me.
I'm just doing this
BLAH?
so basically. before I just had
val serverPort: String = "8080"
BLAH is just me trying to break stuff and seeing if it works
gotcha
which i thought it did. but it was the previoius instance still working
so just to check, does your railway service have a PORT service variable set?
nope
variables are empty at the moment
switching back over to
val serverPort: String =
try {
System.getenv("PORT")
} catch (e: Exception) {
"8080"
}
good
and will see if that works
cool. yep that works.
no PORT variable declaration needed. noice. another thing that can be tucked away as code.
thanks!
i do wonder why my ktor server somehow says it starts up at 55:44, but can't actually handle requests until about 30 seconds later. at 56:19
yeah its super handy how railway does that
the switch over time
gotcha. so its not my server code initialization actually taking 30 seconds. lol
nope
im sure that time will go down when railway rolls out their new http server
cool cool. thats fine. nice to at least know that its out of my control.
running a few more sanity checks with healthcheck endpoint and stuff, but i think im all set š¤
great!
oh yahhh. works great. awesome. so many great little tips learned today. appreciate it. im essentially getting to a point where i can have a small template for all future ktor projects. love to see it.
happy i could help
1/1 replicas never became healthy! Healthcheck failed!never been so happy to see a failure lol
lol i assume you planned that
yep
System.getenv("BLAH")
just making sure the healthcheck worked as expected when it defaulted to 8080 and couldn't actually startup
thanks again. night š¤
no problem!
heh. i was able to see the railway 404 page or w/e even with the healthcheck and timeout of 500. no storage or db attached to this server.
Attempt #1 failed with service unavailable. Continuing to retry for 4m59s [1/1] Healthcheck succeeded!so for a split second my server went down. you think im missing anything else here? (i know the last time this happened we narrowed it down to the fact that i had some storage attached). but none of that this time.
RAILWAY_DEPLOYMENT_OVERLAP_SECONDS
set to 35
should do the trickaha. so thats diff from "Healthcheck Timeout"
yep. that seemed to do the trick. couldn't repro the railway 404 page.
excellent. ill make sure to add that to my default template as well (see, thats something id love to add to railway.json)
lol. sat there again and just tried cmd + r to refresh over and over and over and i was able to see the downtime page for a split second.
unfortunately that looks like the best we can do with the current http proxy
bumped to RAILWAY_DEPLOYMENT_OVERLAPSECONDS to 60. and couldn't repro.
ĀÆ_(ć)/ĀÆ
might do a few more sanity checks tomorrow. sleep for real this time. lmao
sounds good!