Using pyproject.toml or multistage Dockerfile

niccolomineo
HOBBY

9 days ago

I have been unsuccessful in using the pyproject.toml to install remote deps (thus replacing the root requirements.txt file) via the uv package. But I'd be ok with using just the Dockerfile if possible. Can you give guidance please?

Solved

0 Replies

niccolomineo
HOBBY

9 days ago

9a8cdddf-87aa-4caf-848a-69fb07710946


9 days ago

Hey @Niccolò, have you tried switching the builder to Railpack in your service's settings?


niccolomineo
HOBBY

9 days ago

Hi, thanks for the prompt response on a Sunday!


niccolomineo
HOBBY

9 days ago

1404189516440277000


niccolomineo
HOBBY

9 days ago

I do have a multistage Dockerfile with a remote stage which is not being picked up


niccolomineo
HOBBY

9 days ago

I reckon this file should be called something else than Dockerfile


niccolomineo
HOBBY

9 days ago

if I want to make use of the Railpack builder?


niccolomineo
HOBBY

9 days ago

Anyways, I'd actually be ok with using the Dockerfile since it's got a local stage anyways


niccolomineo
HOBBY

9 days ago

Using pyproject.toml or multistage Dockerfile


niccolomineo
HOBBY

9 days ago

but I don't know how to reference the remote stage for Railway to pick that one up instead of the local one


9 days ago

This is correct if you want to use Railpack. Alternatively, without renaming your Dockerfile, you can also add a railway.json at the root of your project with the following content to tell Railway to use Railpack as opposed to the detected Dockerfile.

{
  "$schema": "https://railway.com/railway.schema.json",
  "build": {
    "builder": "RAILPACK"
  }
}

niccolomineo
HOBBY

9 days ago

Ok, thanks. What about the Dockerfile issue? Any chance of having Railway pick up the "remote" stage specifically?


9 days ago

Can you show the Dockerfile?


niccolomineo
HOBBY

9 days ago


9 days ago

If I am not mistaken, there is currently no way to specify a specific target in a multi stage Dockerfile, it is best to create a Dockerfile for this stage alone and overwrite the Dockerfile path to your new Dockerfile using a service variable.

For example if you create a new Dockerfile called Dockerfile.remote:

RAILWAY_DOCKERFILE_PATH=Dockerfile.remote

niccolomineo
HOBBY

9 days ago

Ok, as I think maintaining 2 Dockerfiles would be too error prone, I think I'll go with the other solution. I have a couple of questions about this.

  • How can I port my current Nixpacks config (which is installing gcc, postgresql and python 3.13) to the Railpack system?

  • How is Railway supposed to pick the "local" and "remote" dependency groups in the pyproject.toml?


niccolomineo
HOBBY

9 days ago

Thank you


niccolomineo
HOBBY

9 days ago


niccolomineo
HOBBY

9 days ago

Giving you more context. This is how the deployment is failing on me right now:

``v sync --locked --no-dev --no-install-project
process "uv sync --locked --no-dev --no-install-project" did not complete successfully: exit code: 2

error: No interpreter found for Python >=3.13 in managed installations or search path
hint: A managed Python download is available for Python >=3.13, but Python downloads are set to 'never'``


9 days ago

Is this using Nixpacks or Railpack?


niccolomineo
HOBBY

9 days ago

Railpack


niccolomineo
HOBBY

9 days ago

1404204848546582800


9 days ago

Do you have a .python-version file? This technically isn't needed since Railpack should use 3.13.2 by default, but just in case you overwrote the version.


9 days ago

Railpack also checks for the Python version at other places, which may or may not have a version specified that isn't >= 3.13. https://railpack.com/languages/python/#versions


niccolomineo
HOBBY

9 days ago

Ok, thank you, it went through the process of deploying, but now the app is crashing, I presume because it is not finding the postgresql package (which I used to be able to install with the Nixpackages approach). How do I do that with Railpacks?

` File "/app/.venv/lib/python3.13/site-packages/django/db/backends/postgresql/base.py", line 29, in

raise ImproperlyConfigured("Error loading psycopg2 or psycopg module")

django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 or psycopg module
`


9 days ago

What was your Nixpacks approach? Also, can you try Nixpacks again, or is there a problem with Nixpacks (such as with uv)?


niccolomineo
HOBBY

9 days ago

With the Nixpacks approach I was selecting the Nixpacks as the builder


niccolomineo
HOBBY

9 days ago

but I had the requirements.txt, whereas now I have the pyproject.toml


niccolomineo
HOBBY

9 days ago

If I should stay with Nixpacks, how is it supposed to pick the packages from the pyproject.toml?


niccolomineo
HOBBY

9 days ago

I just tried with Nixpacks btw, but it is failing

[stage-0 3/10] COPY .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix failed to calculate checksum of ref ojxpv0ui1grqct03z03c8vd4l::j23jir1qces40cyctdg24dnn9: "/.nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix": not found


9 days ago

Nixpacks should also support pyproject.toml, at least per the docs. Now I am interested in why this is failing, do you mind trying out a different Postgres driver and Railpack? Not sure if anything has to do with this, but your pyproject.toml has pyscopg 3 specified https://pypi.org/project/psycopg2/.


niccolomineo
HOBBY

9 days ago

I don't think that is the problem, that dependency used to be there before.


niccolomineo
HOBBY

9 days ago

`✕ [stage-0 3/10] COPY .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix
failed to calculate checksum of ref wopnawjcyyxgr34vssu7xmlrp::tli9ohmvj7e9q5ua0s38sbtwr: "/.nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix": not found

Dockerfile:7

5 |

6 |

7 | >>> COPY .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix

8 | RUN nix-env -if .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix && nix-collect-garbage -d

9 |

ERROR: failed to build: failed to solve: failed to compute cache key: failed to calculate checksum of ref wopnawjcyyxgr34vssu7xmlrp::tli9ohmvj7e9q5ua0s38sbtwr: "/.nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix": not found

Error: Docker build failed`


9 days ago

I am kinda out of ideas at this point, I would try using the Dockerfile approach, while maintaining two separate can be error prone, it does at the end of the day give you total control over how your application is built.
-# I am going to sleep now, so expect answers to be delayed.


niccolomineo
HOBBY

9 days ago

Done that, app is giving 502 now


niccolomineo
HOBBY

9 days ago

how do I debug that?


9 days ago


niccolomineo
HOBBY

9 days ago

The implementation was getting a bit too vendor specific. I figured out what went wrong with the Railpack and fixed it (I just had to use the binary version of psycopg 3). Then, replacing the Railpack install command to target the remote dependenceis and changing all other commands to use uv rundid it.


8 days ago

At some point, especially with complex setups, it may just be easier to just write a Dockerfile. But in this case, I am glad that you have solved the issue with Railpack by modifying the commands to run. I'll mark this thread as solved if you don't have any further questions.


7 days ago

!s


Status changed to Solved uxuz 7 days ago