Can I define two separate services in my railway.json
coltonidle
FREEOP

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

coltonidle
FREEOP

2 years ago

N/A


brody
EMPLOYEE

2 years ago

this is not supported config, you would need to run two railway services, or do something manually with GNU's parallel -


coltonidle
FREEOP

2 years ago

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?


brody
EMPLOYEE

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?


coltonidle
FREEOP

2 years ago

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.


brody
EMPLOYEE

2 years ago

then I'm not understanding the blocker here?


coltonidle
FREEOP

2 years ago

so i can have two services in a single project, right?


coltonidle
FREEOP

2 years ago

if so. then my question is how do i take my single service railway.json and update it so that it supports two services.


brody
EMPLOYEE

2 years ago

of course, I'm confident you already knew this


brody
EMPLOYEE

2 years ago

why does this have anything to do with railway.json?


brody
EMPLOYEE

2 years ago

how is your project structured?


brody
EMPLOYEE

2 years ago

not your railway project


coltonidle
FREEOP

2 years ago

because in the railway UI, for my service1 (existing) I'm using railway.json so in the UI it says this:

1270194567345606700


coltonidle
FREEOP

2 years ago

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 railway
androidApp <--- my app, nothing to do with railway
server2 <---- my new ktor service i want to deploy to railway

1270195085027446800


brody
EMPLOYEE

2 years ago

does anything in server need access to anything outside of it's folder


coltonidle
FREEOP

2 years ago

nope. each service (server and server2) is self contained. but they both need to read from the same db.


brody
EMPLOYEE

2 years ago

why not set the root directory to /server in your service settings


brody
EMPLOYEE

2 years ago

then you can add a new railway.json to server2


coltonidle
FREEOP

2 years ago

oh. I thought I could only have ony railway.json


coltonidle
FREEOP

2 years ago

that makes sense. lol


coltonidle
FREEOP

2 years ago

each server directory just holds it's own railway.json


brody
EMPLOYEE

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


coltonidle
FREEOP

2 years ago

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

coltonidle
FREEOP

2 years ago

i think ill just put the railway.json in each service folder. lemme see if that does the trick…


coltonidle
FREEOP

2 years ago

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?


brody
EMPLOYEE

2 years ago

in the service settings


coltonidle
FREEOP

2 years ago

ah railway config file


coltonidle
FREEOP

2 years ago

I think maybe what confused me was that I didn't have that filled out at all in service1


coltonidle
FREEOP

2 years ago

and so i thought that maybe the config file was something different than the railway.json i had created


brody
EMPLOYEE

2 years ago

right because the default file name is picked up automatically


coltonidle
FREEOP

2 years ago

but it looks like railway will use railway.json even if i dont configure it


coltonidle
FREEOP

2 years ago

okay okay. yeah. thats sensible. just threw me off since i wasn't explicit about it.


coltonidle
FREEOP

2 years ago

hence why i thought i needed everything configured in this single magical railway.json


coltonidle
FREEOP

2 years ago

it works! woot woot!


coltonidle
FREEOP

2 years ago

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!


coltonidle
FREEOP

2 years ago

now i just gotta connect the db to it (hopefully thats not an issue) and I should be good to go. WOOT WOOT.


coltonidle
FREEOP

2 years ago

noice

1270200467606995000


coltonidle
FREEOP

2 years ago

looks like it auto created this service in us-west while all my other stuff lives in us-east


coltonidle
FREEOP

2 years ago

fool me once…


Loading...