2 years ago
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?
158 Replies
2 years ago
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
2 years ago
you would likely have the nixpacks.toml in the subfolder and then set the location to it with the NIXPACKS_CONFIG_FILE variable
thanks. 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)
2 years ago
wdym version control? like github?
2 years ago
its a variable that controls the platform, so it needs to be set on the platform itself
2 years ago
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?
2 years ago
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
2 years ago
what makes you think that?
2 years ago
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)
2 years ago
what did you set that NIXPACKS_CONFIG_FILE to?
2 years ago
its blue
2 years ago
have you not deployed the changes?
2 years ago
second option seems like the best
2 years ago
but without seeing your project structure i dont know for sure
2 years ago
oh maybe you dont need to set that variable if the root directory is set, try omitting it
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)
2 years ago
you completely removed the NIXPACKS_CONFIG_FILE variable from your service?
2 years ago
but those logs would indicate that its still set
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.
2 years ago
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)
2 years ago
interesting
2 years ago
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
2 years ago
very odd
i think my nixpacks.toml file is wrong
[build]
buildCommand = './gradlew -p server clean build -x check -x test'
[deploy]
startCommand = 'java $JAVA_OPTS -jar server/build/libs/*-all.jar'2 years ago
very wrong
2 years ago
did gpt write that for you
2 years ago
[phases.build]
cmds = ['./gradlew -p server clean build -x check -x test']
[start]
cmd = ['java $JAVA_OPTS -jar server/build/libs/*-all.jar']2 years ago
thats for a railway.toml
2 years ago
we can pivot to a railway.toml if thats what you'd like to do?
2 years ago
i guess i dont really care. i was just using what i learned in the last thread (from aleks)
2 years ago
maybe a railway.json would even be best? since it has schema validation
2 years ago
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"buildCommand": "./gradlew -p server clean build -x check -x test"
},
"deploy": {
"startCommand": "java $JAVA_OPTS -jar server/build/libs/*-all.jar"
}
}interesting. how does it do schema validation? on the railway side? or can i somehow validate locally?
2 years ago
the $schema value links to the schema file and then vscode tells you if you did something very wrong
2 years ago
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
2 years ago
i like railway.json by far, since you can embed a nixpacks.toml file into it and have schema validation!
2 years ago
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.
2 years ago
correct
because i just converted the file and everything seems to be building fine
2 years ago
lets see the file you came up with
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"buildCommand": "./gradlew -p server clean build -x check -x test"
},
"deploy": {
"startCommand": "java $JAVA_OPTS -jar server/build/libs/*-all.jar"
}
}2 years ago
its not needed, unless you want to set that stuff from your railway.json file
2 years ago
ah thanks ❤️
im curious now about this json validation thing. ive never heard of that in my life. lol
2 years ago
hey, my first introduction to it was when i edited my first railway.json too!
2 years ago
i can't imagine fleet not doing the schema validation
2 years ago
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
2 years ago
nope, just PORT
hm. howd you find that out? lol. sorry i try to find docs, but did i miss something here?
2 years ago
mainly covered here
and here
thanks. for whatever reason… it seems like RAILWAYTCPAPPLICATION_PORT also worked? unless it actually just defaulted to 8080 and that worked. going to switch to plain ol "PORT" now… 🤞
2 years ago
do you have a tcp proxy on your service? if you do, you shouldn't
2 years ago
2 years ago
i think this is close enough to what you're running?
2 years ago
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 proxy
okay. so RAILWAYTCPAPPLICATION_PORT doesn't actually work. it was because if i can't find the env variable defined, then it chooses 8080
2 years ago
so the goal here would be to not have a PORT variable defined on your service
I'm just doing this
fun main() {
val serverPort: String =
try {
System.getenv("BLAH")
} catch (e: Exception) {
"8080"
}
embeddedServer(Netty, port = serverPort.toInt(), host = "0.0.0.0", module = Application::module)
.start(wait = true)
}2 years ago
BLAH?
2 years ago
gotcha
2 years ago
so just to check, does your railway service have a PORT service variable set?
switching back over to
val serverPort: String =
try {
System.getenv("PORT")
} catch (e: Exception) {
"8080"
}2 years ago
good
no PORT variable declaration needed. noice. another thing that can be tucked away as code.
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

2 years ago
yeah its super handy how railway does that
2 years ago
the switch over time
gotcha. so its not my server code initialization actually taking 30 seconds. lol
2 years ago
nope
2 years ago
im sure that time will go down when railway rolls out their new http server
running a few more sanity checks with healthcheck endpoint and stuff, but i think im all set 🤞
2 years ago
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.
2 years ago
happy i could help
1/1 replicas never became healthy!
Healthcheck failed!
never been so happy to see a failure lol
2 years ago
lol i assume you planned that
just making sure the healthcheck worked as expected when it defaulted to 8080 and couldn't actually startup
2 years ago
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.
2 years ago
RAILWAY_DEPLOYMENT_OVERLAP_SECONDS set to 35 should do the trick
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.
2 years ago
unfortunately that looks like the best we can do with the current http proxy
might do a few more sanity checks tomorrow. sleep for real this time. lmao
2 years ago
sounds good!





