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 aDockerfile 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.

0 Replies

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
EMPLOYEE

a year ago

you can have two yes, but first can you tell me about your file structure?


It's kind of messy structure, as of now.

/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
EMPLOYEE

a year ago

looks easy enough to deploy, do you already have two blank railway services


I have a node service already running on prod.

Now, I am trying to add a go service.


brody
EMPLOYEE

a year ago

and that Dockerfile, that's for the go app right? it has nothing to do with node?


That Dockerfile is for the node


brody
EMPLOYEE

a year ago

do you have a dockerfile for the go app, or are you going to let nixpacks try and build it?


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
EMPLOYEE

a year 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?


I have yet to write one


brody
EMPLOYEE

a year ago

in the mean time, do you think nixpacks would be able to build your go app?


I was able to run 2 different services from single repo, using railway.json file.

Thanks for the help. 🙂


brody
EMPLOYEE

a year ago

no problem!


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

But railway.json schema is not showing any linting for this object.


brody
EMPLOYEE

a year ago

yeah it doesn't have schema validation for this, but it should still work.. does it not work?


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

The actual config, I used.

  "environments": {
    "testing": {
      "deploy": {
        "sleepApplication": true
      }
    }
  }

Here testing is an environment in railway not a PR branch name from git.


brody
EMPLOYEE

a year ago

that's your full railway.json?


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

brody
EMPLOYEE

a year ago

I'll have to do some testing and get back to you


brody
EMPLOYEE

a year ago

works as intended -

1253780567816798200
1253780568114466800


Loading...