a year ago
The monorepo documention (https://docs.railway.com/guides/monorepo) describes two kinds of monorepos but there's a third kind, a monorepo that looks like this (a monorepo that uses yarn workspaces):
|--- package.json
|------ backend
|---------package.json
|------frontend
|---------package.json
Here, frontend has a dependency on backend through the root level package.json which looks like
{
"private": true,
"workspaces": [
"frontend",
"backend"
],
"packageManager": "yarn@4.5.3"
}I can't set the respective folders as root in either service because then Docker can't find yarn.lock (which only exists at the top level with yarn workspaces) and I can't get the shared approach to work either because each package has their own package.json with their own set of build commands.
18 Replies
a year ago
what do you mean 3rd kind?

I finally got it to work, or at least farther than where I was but I had to modify relative paths in my Dockerfile to do so which I'm not particularly pleased about
Similar to how you can set RAILWAY_DOCKERFILE_PATH to point to your dockerfile, is there a way to point to your nixpacks.toml?
a year ago
yep! - NIXPACKS_CONFIG_FILE
a year ago
let me know if theres any more questions!
and got the frontend app to work! Here was my resulting nixpacks.toml:
# https://nixpacks.com/docs/configuration/file
# set up some variables to minimize annoyance
[variables]
NPM_CONFIG_UPDATE_NOTIFIER = 'false' # the update notification is relatively useless in a production environment
NPM_CONFIG_FUND = 'false' # the fund notification is also pretty useless in a production environment
NODE_ENV = 'production'
[phases.setup]
nixPkgs = ['nodejs', 'yarn']
cmds = [
'corepack enable'
]
[phases.install]
cmds = [
'cp ./yarn.lock frontend',
'yarn install --immutable'
]
[phases.build]
cmds = [
'rm frontend/yarn.lock',
'yarn build:backend',
'yarn build:frontend'
]
# download caddy from nix
[phases.caddy]
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
nixpkgsArchive = 'ba913eda2df8eb72147259189d55932012df6301' # Caddy v2.8.4 - https://github.com/NixOS/nixpkgs/commit/ba913eda2df8eb72147259189d55932012df6301
nixPkgs = ['caddy'] # install caddy as a nix package
# format the Caddyfile with fmt
[phases.fmt]
dependsOn = ['caddy'] # make sure this phase runs after the 'caddy' phase so that we know we have caddy downloaded
cmds = ['caddy fmt --overwrite frontend/Caddyfile'] # format the Caddyfile to fix any formatting inconsistencies
# start the caddy web server
[start]
cmd = 'exec caddy run --config frontend/Caddyfile --adapter caddyfile 2>&1' # start caddy using the Caddyfile config and caddyfile adapterit was...a lot. Would be great if railway supported yarn workspaces out of the box better because that was pretty rough
a year ago
awsome, im glad you got it working!
a year ago
!a
a year ago
!s
Status changed to Solved brody • over 1 year ago