#Nixpack build error with Django app
203 messages · Page 1 of 1 (latest)
My Dockerfile works fine locally. How should I install the packages that will help psycopg2 installation go through without errors?
#12 6.407 pg_config is required to build psycopg2 from source. Please add the directory
#12 6.407 containing pg_config to the $PATH or specify the full executable path with the
#12 6.407 option:
#12 6.407
#12 6.407 python setup.py build_ext --pg-config /path/to/pg_config build ...
#12 6.407
#12 6.407 or with the pg_config option in 'setup.cfg'.
#12 6.407
#12 6.407 If you prefer to avoid building psycopg2 from source, please install the PyPI
(Copying error from text file into chat here for search)
I don’t have great insight to help further here, but interesting there’d be a difference in build locally vs on railway platform. What’s your dockerfile look like?
My Dockerfile is tailored for the local environment. I think my project setup has to be overhauled in order to make it work with Nixpacks remotely. So I am starting from scratch. In order to have Python requirements install on Heroku, I used to have a requirements.txt in the project root with the dependencies needed for the remote Heroku environment only. Is this how it is supposed to be done with Nixpacks as well? Also, is there a Nixpack-compatible Python project example available anywhere?
This is section for docs for python: https://nixpacks.com/docs/providers/python
App source + Nix packages + Docker = Image
And the parent page: https://docs.railway.app/deploy/builds
This looks like template example for python discord bot: https://railway.app/new/template/PxM3nl
There may be more examples. Note I’m just a user, and haven’t worked much with python before. Hope above links help
Thanks. The root requirements.txt thing is bugging me though. I thought the Nixpack buildpack was looking into the Dockerfile only, but it is actually looking into the root requirements.txt first and tries to install those. I don't see this covered in the guide at all.
If you have a Dockerfile it should use that
If it's in not the root, you'll wanna set the root directory to where the Dockerfile is is
Or set Variable DOCKERFILE_PATH to the dockerfiles path
My Dockerfile is in the root indeed, but the requirements.txt also is, and Nixpack is somehow preferring the latter.
Dockerfile
Capitals matter
indeed
9a8cdddf-87aa-4caf-848a-69fb07710946
I am wondering, does Nixpack support multistaging? Or should I go for using separate Dockerfiles for the local vs remote envs?
Could you elaborate?
What would you need to change in your Dockerfile for local vs remote
Locally I am using dependencies (mainly for testing and debugging) that are of no use remotely.
Gotchya
We've just added multiple provider support to Nixpacks. So, in the future yes but for now no
I see
Will have a look I'm about 10m when I'm home
Ok, thank you.
uhh it appears to be using your dockerfile
Mmh, when I do sudo nixpack build . it seems to get the requirements.txt instead. Anyway, I am taking it out for good.
A skeleton Django project built with a view to using the Nixpack buildpack would be great to inspect, with an example pyproject.toml and an example artifact the sudo nixpack build . command produces at the end of the build.
You need to use psycopg2-binary package instead of psycopg2. That should solve this issue
Thanks, but I can't. I have an ARM64 CPU. I'll have to work on my Dockerfile.
Ok, back at it again. Nixpack building is soo slow. Any clue as to why it's behaving like this?
[+] Building 621.4s (4/14)
=> [internal] load build definition from Dockerfile 0.0s
[+] Building 621.5s (5/14)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 1.08kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for ghcr.io/railwayapp/nixpacks:debian-16654 0.4s
=> [internal] load build context 0.4s
=> => transferring context: 25.57MB 0.4s
=> CANCELED [stage-0 1/10] FROM ghcr.io/railwayapp/nixpacks:debian-16 621.0s
=> => resolve ghcr.io/railwayapp/nixpacks:debian-1665446966@sha256:48088 0.0s
=> => sha256:4ce525b9479139c4ce71ba043d4d15360ae04216 29.77MB / 29.77MB 21.2s
=> => sha256:48088795aef10698578d862349bf230f0ace63c978f 1.05kB / 1.05kB 0.0s
=> => sha256:ba70d21f951d0969e1375f9320cd8578b2eda8e9a04904f 953B / 953B 0.0s
=> => sha256:a2593eb06f40909eccfe277c5d466d69938da501a67 3.84kB / 3.84kB 0.0s
=> => sha256:a9fe95647e78b5516c7e2327355b6996e2ea295 22.02MB / 30.05MB 621.0s
=> => sha256:adbc07ad76c8682da11b96475f4ed9dcbab30d78 7.34MB / 43.03MB 621.0s
FYI, I am peaking at 20 mb/s downloading games off of Steam.
Likely steams APIs being slow. Network looks fine here
?
Oh are you running this locally?
Sorry I thought it was on the builder
Unsure then could be GCR
Uhm ok, it should take like a few seconds to download 40 megs
but I was over 10 mins
Unsure sadly we can't debug local stuff
I am wondering, what it supposed to happen at the end of the build? What should be produced?
An image
Is that it? A Docker image?
Yes
And that image is pushed remotely at the end of the build?
Sorry, I don't get how that's supposed to work.
No
It's on your local
So you can test it however you'd like
I am already producing an image with my own docker compose
That's not usable on Railway
I don't need to do nixpack build .
Ok
Do you believe it would be possible to only have those files in the repo without doing nixpack build .?
Which files
Because from here it looks like an unnecessary chore for those having a docker compose
producing a set of images
You can use a Dockerfile
It looks like an unnecessary chore to have another image
just for Railway
or am I missing something?
What's your issue?
You said it's not usable on Railway
it means there's something more in that image produced by nixpack build . that doing docker compose build doesn't do.
Here's a django example
I have a couple:
- nixpack is not working at the moment as you can see
- I feel like I will be polluting my local system with docker images that'll be used just by Railway
What are you trying to do here
Deploy a Django application correct?
Yes
Great
thanks for the link
That looks like a vanilla Django project with a Heroku Procfile
I am mentioning Heroku because it's where I was before
You can delete the Heroku procfile if you'd like
Ok
I don't see a Dockerfile in there
That's because there isn't one
The repo builds just fine and is Django
Isn't it supposed to be feeding from a local Dockerfile?
Uhm, ok
You can either write a Dockerfile, or have Nixpacks run detection on your code
So you don't need a local Dockerfile
You do not
Ok
UNLESS, you want to write one
Ok
In which case we also support that
I'd like to keep a Dockerfile.local but maybe I don't need a Dockerfile for Nixpack
(btw, thanks for taking the time to give support)
You are very welcome
In this case, I'd make sure it's named exactly like that
Otherwise, Railway will try and use it
Ok
And Railway will recognize a requirements.txt file placed in the root only, correct?
In your root directory. Which you can set, in settings
So if you have a monorepo and it's backend/requirements.txt, set root to backend/
When you say "set root in settings", which settings are you talking about?
Service -> Settings -> Root Directory
Uhm ok maybe I don't need one
Anyways, what you meant before is that nixpack build . is just for local development?
No?
Well
Sorta in a way I suppose
You can run it locally to test Nixpacks
It's what we run when you build stuff in production using nixpacks
Yeah
you advise to do nixpack build , locally to test out the project before deploying. But it's not mandatory to run that command in order to deploy.
Shouldn't need to
Just trigger the deploy and see the logs
Should be fast enough to do that
Thanks, I understand the philosophy behind nixpacks better now.
I managed to deploy the app, but for some reason statics are not being served
it's 404 all over the place
How come in the example Django repo you have psycopg2 (and not psycopg2-binary) as a requirement, but when I push it it fails with
#12 13.65 Error: pg_config executable not found.
#12 13.65
#12 13.65 pg_config is required to build psycopg2 from source. Please add the directory
#12 13.65 containing pg_config to the $PATH or specify the full executable path with the
#12 13.65 option:
#12 13.65
#12 13.65 python setup.py build_ext --pg-config /path/to/pg_config build ...
#12 13.65
#12 13.65 or with the pg_config option in 'setup.cfg'.
#12 13.65
#12 13.65 If you prefer to avoid building psycopg2 from source, please install the PyPI
#12 13.65 'psycopg2-binary' package instead.
do you have django in requirements.txt?
Please share your requirements.txt file.
Sure
My root requirements.txt is just saying:
-r requirements/remote.txt
I am sharing the actual remote.txt contents in a minute
We currently scan requirements.txt for psycopg2 and back-fill system level deps.
Thus it fails
Try setting NIXPACKS_PKGS=postgresql under variables.
Done. It's redeploying... let's see what happens.
cool
It's taking more than 10 mins now
but it is indeed doing stuff
Ok it appears to have gone past the postgres deps build
Don't worry, future builds won't take that long. Railway will cache all your deps.
@tiny inlet (psycopg2)
We scan for that tho :/
yeah but ^
O
Ok deploy successful
Thank you
Only problem now is
statics are not served, but nothing changed on my side
I see 404s for every static
Is your repository open source?
sure ty,
Done
/opt/venv/lib/python3.8/site-packages/whitenoise/base.py:115: UserWarning: No directory at: /app/static/
warnings.warn(f"No directory at: {root}")
/opt/venv/lib/python3.8/site-packages/whitenoise/base.py:115: UserWarning: No directory at: /app/static/
warnings.warn(f"No directory at: {root}")
/opt/venv/lib/python3.8/site-packages/whitenoise/base.py:115: UserWarning: No directory at: /app/static/
warnings.warn(f"No directory at: {root}")
mmh maybe I should be doing python manage.py collectstatic somewhere
not sure where though.
set this as your start command python manage.py collectstatic && gunicorn niccolomineo.asgi:application --log-level=warning -b 0.0.0.0:$PORT --max-requests 14000 -w 3 -k niccolomineo.workers.UvicornDjangoWorker
Thanks. I would like to do without the Procfile if possible
Service -> Settings -> Start Command
Do you think the "release" command could be specified somewhere but in the Procfile?
yeah
yes, after build command
Thanks. What should be as the build command?
nothing in your case because you are using python
just set your release command as build command
should I just put python manage.py migrate --no-input
Is a requirements.txt with generated hashes supported?
railway by default uses pip install -r requirements.txt as your install command. It should work if this command ^ supports hases.
If not, you can modify install command by setting it to NIXPACKS_INSTALL_CMD under variables.
I am redeploying now, will tell you shortly if it works out of the box.
#12 20.00 ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not:
#12 20.00 backports.zoneinfo from https://files.pythonhosted.org/packages/1a/ab/3e941e3fcf1b7d3ab3d0233194d99d6a0ed6b24f8f956fc81e47edc8c079/backports.zoneinfo-0.2.1-cp38-cp38-manylinux1_x86_64.whl#sha256=7b0a64cda4145548fed9efc10322770f929b944ce5cee6c0dfe0c87bf4c0c8c9 (from django==4.1.2->-r requirements/remote.txt (line 205))
I am sorry that I cannot provide definitive answers. I don't have a background in python. 😦 I am more of a c/typescript/golang/rust guy.
Don't worry, you've been extremely helpful
Cooper and you, that is
💯
So you were saying I might override NIXPACKS_INSTALL_CMD
yes
I tried both pip3 and pip, but it says command not found
Let me know what you find out. Thank you!
Sure, I'll take a look at this in couple of hours.
Thank you!