2 years 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
81 Replies
@Brody This is what I have:
root package.json
"kangiten:start": "pnpm --filter kangiten start"2 years ago
yes you do, like a start:backend and start:frontend etc
2 years ago
ERR_PNPM_NO_LOCKFILE Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absent2 years ago
beat you
2 years ago
is pnpm-lock.yaml absent?
2 years ago
does the go app need to access code from any other folder?
2 years ago
okay, do you have a kangiten:build script?
2 years ago
go apps need to be built
2 years ago
youd want app specfic build scripts
2 years ago
do you have this set too? -
2 years ago
you may have added the new build script but you didnt configure the railway service to use it
ahh this errorWARN Local package.json exists, but node_modules missing, did you mean to install?
ive had it before
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```
2 years ago
looks like it didnt take, try removing and readding node and go
2 years ago
your providers list is only go though
2 years ago
you want to set it to node and go
2 years ago
might be time to move to a nixpacks.toml, i dont think you can pass in providers when you use the v2 builder
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"]2 years ago
tbh i dont know the syntax for the railway.toml file off the top of my head.
so cant hurt to try
2 years ago
yeah its not being used anyway
2 years ago
under a key?
2 years ago
syntax might be wrong, or you placed the file in the wrong location (need to be on root)
2 years ago
i forgot, the v2 builder does not support nixpack configs in a railway.toml/json
2 years ago
use a nixpacks.toml file
2 years ago
alright, Dockerfile time
2 years ago
or disable the v2 builder
do yall have any docs or examples for monorepos? i dont have a lot experience with dockerfiles in monorepo. disabling v2 didnt work
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
2 years ago
you switched the runtime back to legacy, that should stay on v2.
you wanted to switch off the new builder
2 years 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
2 years ago
yeah
2 years ago
but that looks like its not going to work, so dockerfile for sure
@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"]2 years ago
unfortunately you need to hardcode the service id
2 years ago
awesome
2 years ago
no problem, dockerfiles imo are better for most things than doing a dance with nixpacks
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.
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
a year ago
Railpack is a great option for you then!
a year ago
!s
Status changed to Solved brody • 11 months ago










