R
Railway6mo ago
Yashu

How to split the build process from 1 repo and deploying 2 different services?

I am trying to deploy (1 node, and 1 go) service. And I have a Dockerfile for deploying the Node service. But, now the go service is also using the same Dockerfile. I prefer to use the Config As Code option, instead of using UI settings.
22 Replies
Percy
Percy6mo ago
Project ID: N/A
Yashu
YashuOP6mo ago
I saw the railway.json option, my question is that can I have two of them. One for node and other for go service? Project ID: 8fc2ad89-714b-4cb3-9778-cb64d1373409
Brody
Brody6mo ago
you can have two yes, but first can you tell me about your file structure?
Yashu
YashuOP6mo ago
It's kind of messy structure, as of now.
/app
// all go code
/src
// all node code
/package.json
/pnpm-lock.yaml
/Dockerfile
/app
// all go code
/src
// all node code
/package.json
/pnpm-lock.yaml
/Dockerfile
Did I missed any file, which needs to be mentioned?
Brody
Brody6mo ago
looks easy enough to deploy, do you already have two blank railway services
Yashu
YashuOP6mo ago
I have a node service already running on prod. Now, I am trying to add a go service.
Brody
Brody6mo ago
and that Dockerfile, that's for the go app right? it has nothing to do with node?
Yashu
YashuOP6mo ago
That Dockerfile is for the node
Brody
Brody6mo ago
do you have a dockerfile for the go app, or are you going to let nixpacks try and build it?
Yashu
YashuOP6mo ago
It would be nice to use Docker. What I can try is to have two railway.json file. For example - railway.node.json in (src directory) - railway.go.json in (app directory) Will something like this work? Just a rough idea 🤷‍♂️
Brody
Brody6mo ago
yes it can work, but I don't currently see a need for the difference of names, but one thing at a time here. do you have a Dockerfile for the go app? or have you yet to write one?
Yashu
YashuOP6mo ago
I have yet to write one
Brody
Brody6mo ago
in the mean time, do you think nixpacks would be able to build your go app?
Yashu
YashuOP6mo ago
I was able to run 2 different services from single repo, using railway.json file. Thanks for the help. 🙂
Brody
Brody6mo ago
no problem!
Yashu
YashuOP6mo ago
Continuing on the same ticket. Now, I ran into similar issue. Where I have set the app sleep to disable for production, but how can I enable it for non-production environment. Since I ham using railway.json file, I am not able to modify the settings manually for non-prod env. I tried looking into the docs, for PR Environment Overrides
{
"environments": {
"pr": {
"deploy": {
"startCommand": "echo 'start command for all pull requests!'"
}
}
}
}
{
"environments": {
"pr": {
"deploy": {
"startCommand": "echo 'start command for all pull requests!'"
}
}
}
}
But railway.json schema is not showing any linting for this object.
Brody
Brody6mo ago
yeah it doesn't have schema validation for this, but it should still work.. does it not work?
Yashu
YashuOP6mo ago
I am getting this error in the railway dashboard.
Failed to parse JSON file railway.node.json: invalid character '}' looking for beginning of object key string
Failed to parse JSON file railway.node.json: invalid character '}' looking for beginning of object key string
The actual config, I used.
"environments": {
"testing": {
"deploy": {
"sleepApplication": true
}
}
}
"environments": {
"testing": {
"deploy": {
"sleepApplication": true
}
}
}
Here testing is an environment in railway not a PR branch name from git.
Brody
Brody6mo ago
that's your full railway.json?
Yashu
YashuOP6mo ago
Here's the full json file.
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "node.Dockerfile",
"buildEnvironment": "V2"
},
"deploy": {
"runtime": "V2",
"numReplicas": 1,
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
},
"environments": {
"testing": {
"deploy": {
"sleepApplication": true
}
}
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "node.Dockerfile",
"buildEnvironment": "V2"
},
"deploy": {
"runtime": "V2",
"numReplicas": 1,
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
},
"environments": {
"testing": {
"deploy": {
"sleepApplication": true
}
}
}
}
Brody
Brody6mo ago
I'll have to do some testing and get back to you
Want results from more Discord servers?
Add your server