What's the best way to start services in a monorepo with a lot of services?
kevmok
PROOP

a year ago

Looking at the docs I see commands like npm run start:backend so how does railway now which service is which? https://docs.railway.app/guides/monorepo#deploying-a-shared-monorepo

I have a turborepo with golang services in the following directory structure
/root
--/services
-- (golang services 1 folder each)
--/packages
--/apps

So now I am not sure how to start each monorepo service in each railway service

Solved

81 Replies

kevmok
PROOP

a year ago

f78d75b5-8972-4d61-8517-22bbccefb41e


kevmok
PROOP

a year ago

Do i need to add each service start command to the root package.json?

1271590188409159700


kevmok
PROOP

a year ago

@Brody This is what I have:

root package.json

"kangiten:start": "pnpm --filter kangiten start"

brody
EMPLOYEE

a year ago

yes you do, like a start:backend and start:frontend etc


kevmok
PROOP

a year ago

but

1271627831109095700


kevmok
PROOP

a year ago

1271627853263409200


kevmok
PROOP

a year ago

it does fail build though


kevmok
PROOP

a year ago

let me run that script for logs


brody
EMPLOYEE

a year ago

ERR_PNPM_NO_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absent

kevmok
PROOP

a year ago


brody
EMPLOYEE

a year ago

beat you


kevmok
PROOP

a year ago

dang


brody
EMPLOYEE

a year ago

is pnpm-lock.yaml absent?


kevmok
PROOP

a year ago

does the service need to have that? it's a golang app


kevmok
PROOP

a year ago

it's in the root


kevmok
PROOP

a year ago

1271628306067755000


brody
EMPLOYEE

a year ago

does the go app need to access code from any other folder?


kevmok
PROOP

a year ago

yeah, I have a shared package for other golang services


brody
EMPLOYEE

a year ago

okay, do you have a kangiten:build script?


kevmok
PROOP

a year ago

oh i need to set a specific one too? whoops


kevmok
PROOP

a year ago

i just had the turbo build one lol


brody
EMPLOYEE

a year ago

go apps need to be built


kevmok
PROOP

a year ago

yeah i just assumed it ran turbo build thats mb


brody
EMPLOYEE

a year ago

youd want app specfic build scripts


kevmok
PROOP

a year ago

gotcha


kevmok
PROOP

a year ago

this package json gonna be long haha


brody
EMPLOYEE

a year ago

do you have this set too? -


kevmok
PROOP

a year ago

Yeah


kevmok
PROOP

a year ago

you taught me not too long ago


brody
EMPLOYEE

a year ago

you may have added the new build script but you didnt configure the railway service to use it


kevmok
PROOP

a year ago

1271630291601064200


kevmok
PROOP

a year ago

ahh this error
WARN  Local package.json exists, but node_modules missing, did you mean to install?

ive had it before


kevmok
PROOP

a year ago

actually its a go error
```sh: 1: go: not found

/app/services/kangiten:

 ERRPNPMRECURSIVERUNFIRST_FAIL  kangiten@0.0.0 build: go build -o bin/kangiten main.go

spawn ENOENT

 WARN  Local package.json exists, but node_modules missing, did you mean to install?

 ELIFECYCLE  Command failed with exit code 1.

error building image: error building stage: failed to execute command: waiting for process to exit: exit status 1

exit status 1```


kevmok
PROOP

a year ago

i set provider to Go though


brody
EMPLOYEE

a year ago

looks like it didnt take, try removing and readding node and go


kevmok
PROOP

a year ago

same error


kevmok
PROOP

a year ago

this must be the issue - i dont see Go in here

1271645472850972700


brody
EMPLOYEE

a year ago

your providers list is only go though


kevmok
PROOP

a year ago

Yeah ive been changing them


brody
EMPLOYEE

a year ago

you want to set it to node and go


kevmok
PROOP

a year ago

yep it still fails

1271648242798559200


brody
EMPLOYEE

a year ago

might be time to move to a nixpacks.toml, i dont think you can pass in providers when you use the v2 builder


kevmok
PROOP

a year ago

ok ill look into that, i ahvent used a nixpacks toml file before


kevmok
PROOP

a year ago

Is this the correct way to do it. I added a railway.toml to the root of my monorepo with the following:

[build]
builder = "NIXPACKS"

providers = ["node", "go"]

brody
EMPLOYEE

a year ago

tbh i dont know the syntax for the railway.toml file off the top of my head.

so cant hurt to try


kevmok
PROOP

a year ago

should this stay this way?

1271661761493209000


kevmok
PROOP

a year ago

gotcha


brody
EMPLOYEE

a year ago

yeah its not being used anyway


kevmok
PROOP

a year ago

yeah it might have to be under a key, but the docs dont specify


brody
EMPLOYEE

a year ago

under a key?


kevmok
PROOP

a year ago

like [build]


kevmok
PROOP

a year ago

sorry idk what its called in toml


kevmok
PROOP

a year ago

yeah based on on the jsonschema it does, let me revisit


kevmok
PROOP

a year ago

seems that even then it still doesnt work


brody
EMPLOYEE

a year ago

syntax might be wrong, or you placed the file in the wrong location (need to be on root)


kevmok
PROOP

a year ago

1271667584307302400
1271667584542179300


brody
EMPLOYEE

a year ago

i forgot, the v2 builder does not support nixpack configs in a railway.toml/json


brody
EMPLOYEE

a year ago

use a nixpacks.toml file


kevmok
PROOP

a year ago

ohhh


kevmok
PROOP

a year ago

same issue with nixpacks.toml

1271669394165993500


brody
EMPLOYEE

a year ago

alright, Dockerfile time


brody
EMPLOYEE

a year ago

or disable the v2 builder


kevmok
PROOP

a year ago

do yall have any docs or examples for monorepos? i dont have a lot experience with dockerfiles in monorepo. disabling v2 didnt work


kevmok
PROOP

a year ago

from what im seeing i guess i could make a dockerfile for each service with custom docker file path https://docs.railway.app/guides/dockerfiles


brody
EMPLOYEE

a year ago

you switched the runtime back to legacy, that should stay on v2.

you wanted to switch off the new builder


brody
EMPLOYEE

a year ago

but docs on how to write a Dockerfile would not be specific to railway so it would be out of the scope of our docs


kevmok
PROOP

a year ago

no worries


kevmok
PROOP

a year ago

you mean the new builder env?


brody
EMPLOYEE

a year ago

yeah


brody
EMPLOYEE

a year ago

but that looks like its not going to work, so dockerfile for sure


kevmok
PROOP

a year ago

@Brody I see some people having the Cache mount ID is not prefixed with cache key which I am myself having but don't see the issue <:Thonk:264701195573133315>

# Build stage
FROM golang:1.22.5 AS builder

# Set working directory
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Set the service name (change this for each service)
ARG SERVICE_NAME=kangiten
ARG SERVICE_ID=fc824b79-e4db-4095-9801-b99985b8f4c8

# Download dependencies
RUN --mount=type=cache,id=s/${SERVICE_ID}-/root/cache/go-build,target=/root/.cache/go-build \
    go mod download

# Copy source code
COPY . .

# Build the application
RUN --mount=type=cache,id=s/${SERVICE_ID}-/root/cache/go-build,target=/root/.cache/go-build \
    CGO_ENABLED=0 GOOS=linux go build -o /app/main ./services/${SERVICE_NAME}

# Final stage
FROM alpine:3.18

# Set working directory
WORKDIR /app

# Copy the binary from the builder stage
COPY --from=builder /app/main .

# Run the binary
CMD ["./main"]

kevmok
PROOP

a year ago

actually just hardcoding the id without $service_id worked


brody
EMPLOYEE

a year ago

unfortunately you need to hardcode the service id


brody
EMPLOYEE

a year ago

awesome


kevmok
PROOP

a year ago

holy shit it works


kevmok
PROOP

a year ago

thanks for all your help @Brody 🙏


brody
EMPLOYEE

a year ago

no problem, dockerfiles imo are better for most things than doing a dance with nixpacks


teocns
PRO

10 months ago

Can't this be fixed? it is very annoying that we have to create separate dockerfiles for each service; it's a huge time waste especially for those who don't know they have to hardcode it.


teocns
PRO

10 months ago

I just completely removed cache mounts (at the expense of +2min build times). I honestly think we (users) are not meant to go through such hacky processes. Perhaps many other power users (that like running things efficiently) will share the same


brody
EMPLOYEE

10 months ago

Railpack is a great option for you then!


brody
EMPLOYEE

10 months ago

!s


Status changed to Solved brody 10 months ago


Loading...