2 years ago
I currently have
{
"$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"
}
}
but now I'd like my single github repo to host two java services. I named my new service directory "server2". My first service name exist in "server" directory (as you can see in the json)
What's the best way to go about this? Thanks
39 Replies
2 years ago
this is not supported config, you would need to run two railway services, or do something manually with GNU's parallel -
hm. not sure i understand exactly.
just to restate… I have one github repo with two distinct services that I want to run (if it matters, I also want the both of them to be able to connect to a postgres db). since they are both kotlin apps… i need to configure their build AND deploy steps.
what i understand from "this is not supported config" is that I can't do that with a railway.json file and I can just remove that file, and just use the railway UI directly to set each build and deploy script?
2 years ago
running two apps in a single service is not something thats natively supported like it is on heroku for example, on railway you would run those two apps as separate services typically.
do the two apps need access to the same fs?
so maybe im saying the worng thing here. but. i dont want two apps in a single service. I want two ktor instances in a single project. so. two services in a project.
those two services should have access to my postgres db.
to add some more color to this. I essentially have a github repo at the moment that works fine with railway and this service is a rest api that inserts stuff into my db. now I want to perform some work on the db at various times, so i created another service in my repo that will do that.
2 years ago
then I'm not understanding the blocker here?
if so. then my question is how do i take my single service railway.json and update it so that it supports two services.
2 years ago
of course, I'm confident you already knew this
2 years ago
why does this have anything to do with railway.json?
2 years ago
how is your project structured?
2 years ago
not your railway project
because in the railway UI, for my service1 (existing) I'm using railway.json so in the UI it says this:

so now I created another service. but its automatically taking the start command from railway.json
so it also says server/build/libs... when instead I want service2 to have a start command of server2/build/libs
my project is structured as such
server <--- current railwayandroidApp <--- my app, nothing to do with railwayserver2 <---- my new ktor service i want to deploy to railway

2 years ago
does anything in server need access to anything outside of it's folder
nope. each service (server and server2) is self contained. but they both need to read from the same db.
2 years ago
why not set the root directory to /server in your service settings
2 years ago
then you can add a new railway.json to server2
2 years ago
you could also have server.railway.json and server2.railway.json in the root and set that in the service settings too
I thought I needed to do something like this (made up the field names of course… but this is what i was looking for)
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"services" : [
{
"name": "server",
"build": {
"builder": "NIXPACKS",
"buildCommand": "./gradlew -p server clean build -x check -x test"
},
"deploy": {
"startCommand": "java $JAVA_OPTS -jar server/build/libs/*-all.jar"
}
},
{
"name": "service2",
"build": {
"builder": "NIXPACKS",
"buildCommand": "./gradlew -p server2 clean build -x check -x test"
},
"deploy": {
"startCommand": "java $JAVA_OPTS -jar server2/build/libs/*-all.jar"
}
}
]
}i think ill just put the railway.json in each service folder. lemme see if that does the trick…
actually. im going to go for
server.railway.json and server2.railway.json in the root and set that in the service settings too
where do i set that?
2 years ago
in the service settings
I think maybe what confused me was that I didn't have that filled out at all in service1
and so i thought that maybe the config file was something different than the railway.json i had created
2 years ago
right because the default file name is picked up automatically
but it looks like railway will use railway.json even if i dont configure it
okay okay. yeah. thats sensible. just threw me off since i wasn't explicit about it.
hence why i thought i needed everything configured in this single magical railway.json
ive got a REST api with a publicly accessibly URL and I've got a private kotlin service that is essentially a cronjob service thingy!
now i just gotta connect the db to it (hopefully thats not an issue) and I should be good to go. WOOT WOOT.
looks like it auto created this service in us-west while all my other stuff lives in us-east
