How to use railway with monorepo?
coltonidle
FREEOP

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

coltonidle
FREEOP

2 years ago

N/A


brody
EMPLOYEE

2 years ago


coltonidle
FREEOP

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!


coltonidle
FREEOP

2 years ago

I wonder if i have to move my custom nixpack.toml into the new root folder… hmmmm


brody
EMPLOYEE

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


coltonidle
FREEOP

2 years ago

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)


brody
EMPLOYEE

2 years ago

wdym version control? like github?


coltonidle
FREEOP

2 years ago

yeah


brody
EMPLOYEE

2 years ago

its a variable that controls the platform, so it needs to be set on the platform itself


brody
EMPLOYEE

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


coltonidle
FREEOP

2 years ago

oh hmmm. i wonder if i can do that on ktor. i guess the auto generated port variable is set as an env variable?


brody
EMPLOYEE

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


coltonidle
FREEOP

2 years ago

very cool. thanks for teaching.


coltonidle
FREEOP

2 years ago

cant seem to get railway to use my /server directory. lmao


coltonidle
FREEOP

2 years ago

1214732906015101000


brody
EMPLOYEE

2 years ago

what makes you think that?


coltonidle
FREEOP

2 years ago

1214733120499224600


brody
EMPLOYEE

2 years ago

haha okay well more specifically?


coltonidle
FREEOP

2 years ago

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)


brody
EMPLOYEE

2 years ago

what did you set that NIXPACKS_CONFIG_FILE to?


coltonidle
FREEOP

2 years ago

1214733416310767600


brody
EMPLOYEE

2 years ago

its blue


brody
EMPLOYEE

2 years ago

have you not deployed the changes?


coltonidle
FREEOP

2 years ago

I did, I was just changing things back and forth again


coltonidle
FREEOP

2 years ago

Tried
/server
/server/nixpacks.toml
/nixpacks.toml


brody
EMPLOYEE

2 years ago

second option seems like the best


brody
EMPLOYEE

2 years ago

but without seeing your project structure i dont know for sure


brody
EMPLOYEE

2 years ago

oh maybe you dont need to set that variable if the root directory is set, try omitting it


coltonidle
FREEOP

2 years ago

this is my /server

1214734210569474000


coltonidle
FREEOP

2 years ago

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)


brody
EMPLOYEE

2 years ago

you completely removed the NIXPACKS_CONFIG_FILE variable from your service?


brody
EMPLOYEE

2 years ago

but those logs would indicate that its still set


coltonidle
FREEOP

2 years ago

you know what. i bet you i know the issue


coltonidle
FREEOP

2 years ago

i dont think i have a "true" monorepo


coltonidle
FREEOP

2 years ago

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.


brody
EMPLOYEE

2 years ago

what two apps are in this repo?


coltonidle
FREEOP

2 years ago

i used kmp.jetbrains.com to generate the project


coltonidle
FREEOP

2 years ago

and so i have two mobile apps (ios and android) and a server directory (ktor)


brody
EMPLOYEE

2 years ago

interesting


coltonidle
FREEOP

2 years ago

but yeah. its not a completely isolated project


coltonidle
FREEOP

2 years ago

i.e. isolated monorepo vs shared monorepo




brody
EMPLOYEE

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


coltonidle
FREEOP

2 years ago

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?


coltonidle
FREEOP

2 years ago

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


brody
EMPLOYEE

2 years ago

very odd


coltonidle
FREEOP

2 years ago

ill figure it out. im gettin good at this stuff. 🙂


coltonidle
FREEOP

2 years ago

rubberducking…


coltonidle
FREEOP

2 years ago

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'

brody
EMPLOYEE

2 years ago

very wrong


brody
EMPLOYEE

2 years ago

did gpt write that for you


coltonidle
FREEOP

2 years ago

no. i used the docs



brody
EMPLOYEE

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']

brody
EMPLOYEE

2 years ago

thats for a railway.toml


coltonidle
FREEOP

2 years ago

bah. wheres the nixpacks docs. lmaooo


brody
EMPLOYEE

2 years ago

we can pivot to a railway.toml if thats what you'd like to do?


brody
EMPLOYEE

2 years ago


coltonidle
FREEOP

2 years ago

i guess i dont really care. i was just using what i learned in the last thread (from aleks)


brody
EMPLOYEE

2 years ago

maybe a railway.json would even be best? since it has schema validation


brody
EMPLOYEE

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"
    }
}

coltonidle
FREEOP

2 years ago

interesting. how does it do schema validation? on the railway side? or can i somehow validate locally?


coltonidle
FREEOP

2 years ago

but anyway. yeah. i did what you said and it worked


brody
EMPLOYEE

2 years ago

the $schema value links to the schema file and then vscode tells you if you did something very wrong


coltonidle
FREEOP

2 years ago

maybe railway.json will be a project for tomorrow.


coltonidle
FREEOP

2 years ago

dont use vscode (using jetbrains fleet) lol.


brody
EMPLOYEE

2 years ago

i cant see why it wouldnt do json validation as well


coltonidle
FREEOP

2 years ago

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


coltonidle
FREEOP

2 years ago

i am a big fan of config as code. so i want to do that where possible.


brody
EMPLOYEE

2 years ago

i like railway.json by far, since you can embed a nixpacks.toml file into it and have schema validation!


aleks
HOBBY

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.


coltonidle
FREEOP

2 years ago

Alright. Going to try to convert to railway.json


coltonidle
FREEOP

2 years ago

i guess if railway.json exists, it'll just use it?


brody
EMPLOYEE

2 years ago

correct


coltonidle
FREEOP

2 years ago

because i just converted the file and everything seems to be building fine


coltonidle
FREEOP

2 years ago

cool


brody
EMPLOYEE

2 years ago

lets see the file you came up with


coltonidle
FREEOP

2 years ago

should i also just add the rest of this stuff?

1214805889014567000


coltonidle
FREEOP

2 years ago

I just plugged in the file you passed over 🥰


coltonidle
FREEOP

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"
    }
}

brody
EMPLOYEE

2 years ago

its not needed, unless you want to set that stuff from your railway.json file


coltonidle
FREEOP

2 years ago

sent some trains over. 💸 cheers buddy


brody
EMPLOYEE

2 years ago

ah thanks ❤️


coltonidle
FREEOP

2 years ago

im curious now about this json validation thing. ive never heard of that in my life. lol


coltonidle
FREEOP

2 years ago

not sure if jetbrains fleet is doing any sort of validation for me lol


brody
EMPLOYEE

2 years ago

hey, my first introduction to it was when i edited my first railway.json too!


brody
EMPLOYEE

2 years ago

i can't imagine fleet not doing the schema validation


coltonidle
FREEOP

2 years ago

i guess thats validation in action?

1214807880050671600


brody
EMPLOYEE

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


coltonidle
FREEOP

2 years ago

awesome. gonna try the port number thing and get some sleep. hopefully its easy peasy


coltonidle
FREEOP

2 years ago


coltonidle
FREEOP

2 years ago

even though the docs for that seem wrong? i think its a copy pasta issue


brody
EMPLOYEE

2 years ago

nope, just PORT


coltonidle
FREEOP

2 years ago

hm. howd you find that out? lol. sorry i try to find docs, but did i miss something here?


brody
EMPLOYEE

2 years ago

mainly covered here
and here


coltonidle
FREEOP

2 years ago

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… 🤞


coltonidle
FREEOP

2 years ago

oooh. very interesting. PORT didn't work…


brody
EMPLOYEE

2 years ago

do you have a tcp proxy on your service? if you do, you shouldn't


coltonidle
FREEOP

2 years ago

i dont believe so


coltonidle
FREEOP

2 years ago

actually


coltonidle
FREEOP

2 years ago

wait. i think it did work


coltonidle
FREEOP

2 years ago

but i had downtime. which caused me to think it didn't work.


brody
EMPLOYEE

2 years ago


coltonidle
FREEOP

2 years ago

ill refer back to the convo we had about health check or w/e


brody
EMPLOYEE

2 years ago

i think this is close enough to what you're running?


brody
EMPLOYEE

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


coltonidle
FREEOP

2 years ago

okay. so RAILWAYTCPAPPLICATION_PORT doesn't actually work. it was because if i can't find the env variable defined, then it chooses 8080


coltonidle
FREEOP

2 years ago

and somehow using 8080 as a default works now.


coltonidle
FREEOP

2 years ago

or actually. nope.


brody
EMPLOYEE

2 years ago

so the goal here would be to not have a PORT variable defined on your service


coltonidle
FREEOP

2 years ago

looks like its just a nice long delay again that was misleading me.


coltonidle
FREEOP

2 years ago

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)
}

brody
EMPLOYEE

2 years ago

BLAH?


coltonidle
FREEOP

2 years ago

so basically. before I just had

val serverPort: String = "8080"

coltonidle
FREEOP

2 years ago

BLAH is just me trying to break stuff and seeing if it works


brody
EMPLOYEE

2 years ago

gotcha


coltonidle
FREEOP

2 years ago

which i thought it did. but it was the previoius instance still working


brody
EMPLOYEE

2 years ago

so just to check, does your railway service have a PORT service variable set?


coltonidle
FREEOP

2 years ago

nope


coltonidle
FREEOP

2 years ago

variables are empty at the moment


coltonidle
FREEOP

2 years ago

switching back over to

val serverPort: String =
    try {
        System.getenv("PORT")
    } catch (e: Exception) {
        "8080"
    }

brody
EMPLOYEE

2 years ago

good


coltonidle
FREEOP

2 years ago

and will see if that works


coltonidle
FREEOP

2 years ago

cool. yep that works.


coltonidle
FREEOP

2 years ago

no PORT variable declaration needed. noice. another thing that can be tucked away as code.


coltonidle
FREEOP

2 years ago

thanks!


coltonidle
FREEOP

2 years ago

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

1214814196911308800


brody
EMPLOYEE

2 years ago

yeah its super handy how railway does that


brody
EMPLOYEE

2 years ago

the switch over time


coltonidle
FREEOP

2 years ago

gotcha. so its not my server code initialization actually taking 30 seconds. lol


brody
EMPLOYEE

2 years ago

nope


brody
EMPLOYEE

2 years ago

im sure that time will go down when railway rolls out their new http server


coltonidle
FREEOP

2 years ago

cool cool. thats fine. nice to at least know that its out of my control.


coltonidle
FREEOP

2 years ago

running a few more sanity checks with healthcheck endpoint and stuff, but i think im all set 🤞


brody
EMPLOYEE

2 years ago

great!


coltonidle
FREEOP

2 years ago

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.


brody
EMPLOYEE

2 years ago

happy i could help


coltonidle
FREEOP

2 years ago

1/1 replicas never became healthy!

Healthcheck failed!
never been so happy to see a failure lol


brody
EMPLOYEE

2 years ago

lol i assume you planned that


coltonidle
FREEOP

2 years ago

yep


coltonidle
FREEOP

2 years ago

System.getenv("BLAH")


coltonidle
FREEOP

2 years ago

just making sure the healthcheck worked as expected when it defaulted to 8080 and couldn't actually startup


coltonidle
FREEOP

2 years ago

thanks again. night 💤


brody
EMPLOYEE

2 years ago

no problem!


coltonidle
FREEOP

2 years ago

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.


coltonidle
FREEOP

2 years ago

Attempt #1 failed with service unavailable. Continuing to retry for 4m59s

[1/1] Healthcheck succeeded!


coltonidle
FREEOP

2 years ago

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.


brody
EMPLOYEE

2 years ago

RAILWAY_DEPLOYMENT_OVERLAP_SECONDS set to 35 should do the trick


coltonidle
FREEOP

2 years ago

aha. so thats diff from "Healthcheck Timeout"


coltonidle
FREEOP

2 years ago

yep. that seemed to do the trick. couldn't repro the railway 404 page.


coltonidle
FREEOP

2 years ago

excellent. ill make sure to add that to my default template as well (see, thats something id love to add to railway.json)


coltonidle
FREEOP

2 years ago

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.


brody
EMPLOYEE

2 years ago

unfortunately that looks like the best we can do with the current http proxy


coltonidle
FREEOP

2 years ago

bumped to RAILWAYDEPLOYMENTOVERLAP_SECONDS to 60. and couldn't repro.


coltonidle
FREEOP

2 years ago

¯_(ツ)_/¯


coltonidle
FREEOP

2 years ago

might do a few more sanity checks tomorrow. sleep for real this time. lmao


brody
EMPLOYEE

2 years ago

sounds good!


Loading...