R
Railwayβ€’6mo ago
The Aleks

Can't build Poetry project in a shared monorepo

I've been trying to setup Railway with a NX based Monorepo for most of the day and I'm about to give up. So I was hoping there was a kind soul in here who could help me out πŸ‘ - Automatic detection seems to be very poorly supported in Monorepos. I'm using NX but it does not seem to pick that up on its own - It probably wouldn't work anyways, because it's assumed that NX is Node only. I have a python project in my NX monorepo in this instance. - No problem! I'll just setup my own railway.toml and nixpacks.toml and solve it that way - The "python" provider will only install poetry if there's a pyproject.toml in your app folder. Which isn't the case when you're in a monorepo - No issue! I'll just install poetry myself... only, it doesn't catch the poetry install between phases So... my question is: How can I build a poetry project that resides in a shared monorepo?
#Nixpacks
providers = ["...", "python"]

[phases.validate]
cmds = ["tools/scripts/nx-ignore.sh backends-python-api"]

[phases."python:install"]
dependsOn = ["validate"]
cmds = ["python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install poetry==$NIXPACKS_POETRY_VERSION && cd apps/backends/python/api && poetry install --no-dev --no-interaction --no-ansi"]

[phases.build]
dependsOn = ["python:install", "install"]
cmds = ["npx nx build backends-python-api"]

[deploy]
healthcheckPath = "/healthcheck"

[start]
runImage = 'python:3.11-slim-bullseye'
onlyIncludeFiles = ['./apps/backends/python/api/dist']
cmd = "npx nx start backends-python-api"
#Nixpacks
providers = ["...", "python"]

[phases.validate]
cmds = ["tools/scripts/nx-ignore.sh backends-python-api"]

[phases."python:install"]
dependsOn = ["validate"]
cmds = ["python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install poetry==$NIXPACKS_POETRY_VERSION && cd apps/backends/python/api && poetry install --no-dev --no-interaction --no-ansi"]

[phases.build]
dependsOn = ["python:install", "install"]
cmds = ["npx nx build backends-python-api"]

[deploy]
healthcheckPath = "/healthcheck"

[start]
runImage = 'python:3.11-slim-bullseye'
onlyIncludeFiles = ['./apps/backends/python/api/dist']
cmd = "npx nx start backends-python-api"
#railway.toml
[build]
builder = "nixpacks"
nixpacksConfigPath = "apps/backends/python/api/nixpacks.toml"
#railway.toml
[build]
builder = "nixpacks"
nixpacksConfigPath = "apps/backends/python/api/nixpacks.toml"
No description
Solution:
.venv/Scripts/activate; npx …
Jump to solution
12 Replies
Percy
Percyβ€’6mo ago
Project ID: bbb255bd-ad51-4f8e-801d-ad19617fceb5
The Aleks
The Aleksβ€’6mo ago
bbb255bd-ad51-4f8e-801d-ad19617fceb5
Brody
Brodyβ€’6mo ago
why not set the root directory to /apps/backends/python/api ?
The Aleks
The Aleksβ€’6mo ago
If I do that it doesn't have access to the dependencies outside of that. Eg: the API depends on a few shared dependencies in libs
Brody
Brodyβ€’6mo ago
is the python:install phase even running?
The Aleks
The Aleksβ€’6mo ago
It is - and it finishes installing all the dependencies. My suspicion is that everything it does isn't transfered over to the next step because there's no logic that caches it (and reloads it from the cache) I notice that the python provider in nixpacks sets a cache, but it only does that if it finds the respective python files in the root folder.
Brody
Brodyβ€’6mo ago
it's likely that the venv is no longer active in the next stage somehow, nothing to do with cache. maybe a dockerfile would serve you better in this instance?
The Aleks
The Aleksβ€’6mo ago
Yeah, probably. Wonder why that is though - I'm guessing it works just fine in autodected python builds. I can write a multistage docker build for it. Or use GitHub actions... But it slowly starts to remove the key USP of railway vs some of the other providers where I'd have to do the same.
Adam
Adamβ€’6mo ago
have you tried modifying your start command to fire up the venv before running your npx start command?
Solution
Adam
Adamβ€’6mo ago
.venv/Scripts/activate; npx …
The Aleks
The Aleksβ€’6mo ago
no... but let me try that right away re-replicating this step:
python -m venv --copies /opt/venv && . /opt/venv/bin/activate .... my other commands
python -m venv --copies /opt/venv && . /opt/venv/bin/activate .... my other commands
did the trick. now I just need to get the start command working. Thank you @Adam and @Brody!
Adam
Adamβ€’6mo ago
No prob! Let me know if you run into any other issues