Using pyproject.toml or multistage Dockerfile
niccolomineo
HOBBYOP

4 months 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
HOBBYOP

4 months ago

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


uxuz
MODERATOR

4 months ago

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


niccolomineo
HOBBYOP

4 months ago

Hi, thanks for the prompt response on a Sunday!


niccolomineo
HOBBYOP

4 months ago

1404189516440277000


niccolomineo
HOBBYOP

4 months ago

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


niccolomineo
HOBBYOP

4 months ago

I reckon this file should be called something else than Dockerfile


niccolomineo
HOBBYOP

4 months ago

if I want to make use of the Railpack builder?


niccolomineo
HOBBYOP

4 months ago

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


niccolomineo
HOBBYOP

4 months ago

Using pyproject.toml or multistage Dockerfile


niccolomineo
HOBBYOP

4 months ago

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


uxuz
MODERATOR

4 months 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
HOBBYOP

4 months ago

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


uxuz
MODERATOR

4 months ago

Can you show the Dockerfile?


niccolomineo
HOBBYOP

4 months ago


uxuz
MODERATOR

4 months 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
HOBBYOP

4 months 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
HOBBYOP

4 months ago

Thank you


niccolomineo
HOBBYOP

4 months ago


niccolomineo
HOBBYOP

4 months 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'``


uxuz
MODERATOR

4 months ago

Is this using Nixpacks or Railpack?


niccolomineo
HOBBYOP

4 months ago

Railpack


niccolomineo
HOBBYOP

4 months ago

1404204848546582800


uxuz
MODERATOR

4 months 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.


uxuz
MODERATOR

4 months 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
HOBBYOP

4 months 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
`


uxuz
MODERATOR

4 months ago

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


niccolomineo
HOBBYOP

4 months ago

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


niccolomineo
HOBBYOP

4 months ago

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


niccolomineo
HOBBYOP

4 months ago

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


niccolomineo
HOBBYOP

4 months 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


uxuz
MODERATOR

4 months 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
HOBBYOP

4 months ago

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


niccolomineo
HOBBYOP

4 months 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`


uxuz
MODERATOR

4 months 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
HOBBYOP

4 months ago

Done that, app is giving 502 now


niccolomineo
HOBBYOP

4 months ago

how do I debug that?


brody
EMPLOYEE

4 months ago


niccolomineo
HOBBYOP

4 months 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.


uxuz
MODERATOR

4 months 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.


uxuz
MODERATOR

4 months ago

!s


Status changed to Solved uxuz 4 months ago


Loading...