R
Railway2y ago
dev00

Railway deploying django help wanted!

when deploying my project, i get this error: ERROR: failed to solve: process "/bin/bash -ol pipefail -c python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt" did not complete successfully: exit code: 1 how do i fix it?
83 Replies
Percy
Percy2y ago
Project ID: 86e751b8-5900-4d54-b224-51a403c96f46
dev00
dev00OP2y ago
86e751b8-5900-4d54-b224-51a403c96f46
Brody
Brody2y ago
well first, don't listen to Alex, delete your dockerfile, redoploy, then give me your full build log please
dev00
dev00OP2y ago
@Brody Hello Brody, here is the full log:
Brody
Brody2y ago
looks like you are trying to use a windows specific package, services on railway generally use ubuntu
dev00
dev00OP2y ago
actually, i just noticed pywin32 i deleted this from requirements.txt
Brody
Brody2y ago
yep that would be the package in question
dev00
dev00OP2y ago
let me see if that work now
Brody
Brody2y ago
you may have pip freezed every package on your system into the requirements.txt file, please go through that file and delete all packages you don't use in your project
dev00
dev00OP2y ago
no i only freezed the one inside the virtual environment of my project
Brody
Brody2y ago
ah cool
dev00
dev00OP2y ago
i guess that indicate the deployment suceeded?
Brody
Brody2y ago
more or less yeah
dev00
dev00OP2y ago
ok, so how do i figure out the CNAME on railway? cause i am gonna point the domain from cloudflare to railway deployment
Brody
Brody2y ago
do you own a domain?
dev00
dev00OP2y ago
yes.
Brody
Brody2y ago
who's your domain provider
dev00
dev00OP2y ago
cloudflare
Brody
Brody2y ago
perfect then go to the service settings, add your custom domain, then railway will give you the cname address, use that in the cloudflare DNS settings make sure you have set SSL/TLS mode to full in cloudflare too
dev00
dev00OP2y ago
i can't see any cname address in the settings, the domain is already set
Brody
Brody2y ago
you would have been given the cname when you added the domain send me your custom domain please, along with a screenshot of the domains in the railway service, and your DNS settings in cloudflare
dev00
dev00OP2y ago
nvm, got it when i re-added the domain
Brody
Brody2y ago
all works?
dev00
dev00OP2y ago
let me see one last thing
dev00
dev00OP2y ago
I guess that part of "DNS takes 72 hours to propgate"?
Brody
Brody2y ago
do you see that from your custom domain?
dev00
dev00OP2y ago
yes.
Brody
Brody2y ago
then DNS has already propagated, that's an issue with your app
dev00
dev00OP2y ago
alright, let me see then
Brody
Brody2y ago
any errors in the deploy logs
dev00
dev00OP2y ago
deployment logs
Brody
Brody2y ago
oh you definitely don't want to be running a development server on railway
dev00
dev00OP2y ago
oh snap
Brody
Brody2y ago
do you have a Procfile?
dev00
dev00OP2y ago
how did i not notice this, ok so, what the procedure here? in the old times, i used to keep the server running using gunicorn+ niginx for load balancing but I guess railway does handle the server running for me
Brody
Brody2y ago
you still need gunicorn that hasn't changed and probably never will
dev00
dev00OP2y ago
ok, let's speak in term of gunicorn, why do i need it? i thought gunicorn whole idea is to keep a server running, no?
Brody
Brody2y ago
@Vin your expertise are required (he's an extremely experienced python dev)
dev00
dev00OP2y ago
noice
MantisInABox
MantisInABox2y ago
Oi!
dev00
dev00OP2y ago
thanks for help Brody 🙂
MantisInABox
MantisInABox2y ago
Let me read and catch up
dev00
dev00OP2y ago
take your time
Brody
Brody2y ago
why gunicorn necessary
MantisInABox
MantisInABox2y ago
Thanks. I’m caught up. Gunicorn isn’t a process manager, it is a whole production WSGI server. If you just run your manage.py file, it will launch the dev server which is for testing, and as you can see is looking at the wrong port. With Gunicorn, it will not display error logs on the front end when people hit one, exposing not only your file structure, but also exposing a debug terminal in the browser allowing people to run exploitation code
Brody
Brody2y ago
whats more so the "what" and not the "why"
dev00
dev00OP2y ago
do you mind explaining how gunicorn handle running the server? I thought gunicorn somehow run on a local port too?
Brody
Brody2y ago
dev, no problems with wanting to understand it, but regardless if you understand or not, you still need gunicorn
MantisInABox
MantisInABox2y ago
I would place a railway.json file in your project root and place the following contents in it
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn mysite.wsgi",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn mysite.wsgi",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
You can also look at the template for how to configure your port https://GitHub.com/railwayapp-templates/django
GitHub
GitHub - railwayapp-templates/django: 1-Click Django on Railway
1-Click Django on Railway. Contribute to railwayapp-templates/django development by creating an account on GitHub.
dev00
dev00OP2y ago
yeah, i will create the procfile and add the gunicorn command, but i really want to understand why i need it for the future
Brody
Brody2y ago
you need it to run your app in a production environment, its as simple as that
dev00
dev00OP2y ago
Thanks, i will look it up true, but what kind of address does gunicorn run in this case? like in dev mode, i run 127.0.0.1 which is the local host
Brody
Brody2y ago
gunicorn runs on 0.0.0.0 and environment variable PORT by default
MantisInABox
MantisInABox2y ago
gunicorn will listen on the PORT env variable
dev00
dev00OP2y ago
that true, but isnt that local address too? or is 0.0.0.0 a different case?
MantisInABox
MantisInABox2y ago
It’s not a loop back address like 127.0.0.1 0.0.0.0 binds to all network interfaces in a server environment
Brody
Brody2y ago
all ipv4* hehe
dev00
dev00OP2y ago
just had a good read here: https://www.howtogeek.com/225487/what-is-the-difference-between-127.0.0.1-and-0.0.0.0/ I guess 0.0.0.0 work as a placeholder address, which let all addresses access it
How-To Geek
Most of us have heard of ‘127.0.0.1 and 0.0.0.0’ but have probably not given much thought to them, but if both actually seem to point to the same location, then what is the actual difference between the two? Today’s SuperUser Q&A post helps clear things up for a confused reader.
Brody
Brody2y ago
thats a good enough analogy
dev00
dev00OP2y ago
wtf is this embed tho 😭
MantisInABox
MantisInABox2y ago
Discord being dumb
dev00
dev00OP2y ago
i will re-deploy and give you a feedback!
dev00
dev00OP2y ago
why is $schema a not allowed property in json?
Brody
Brody2y ago
dont worry about that
dev00
dev00OP2y ago
was busy for a while, i re-deployed, now i get too many redirects error
MantisInABox
MantisInABox2y ago
Do you have your cloudflare ssl settings on “Full”
Brody
Brody2y ago
remember when i said this lol
dev00
dev00OP2y ago
let me check, but last time it was
MantisInABox
MantisInABox2y ago
If it’s anything other than “Full”, it will not work
dev00
dev00OP2y ago
dev00
dev00OP2y ago
well, it is Full but not strict
MantisInABox
MantisInABox2y ago
No, don’t use strict
Brody
Brody2y ago
django may also be a culprit for too many redirects
MantisInABox
MantisInABox2y ago
And you used the cname address provided by railway when you added the domain?
dev00
dev00OP2y ago
100%
MantisInABox
MantisInABox2y ago
Not the railway generated domain as the target, correct?
dev00
dev00OP2y ago
yes the one they gave me when i set my custom domain (it was a dialog box)
MantisInABox
MantisInABox2y ago
Yes, that’s the one you should be using. Unfortunately I’m not on the computer for another 4 1/2 hours, so I can’t really help troubleshoot too much more
dev00
dev00OP2y ago
all good fam, thanks for your help 🙂 !
MantisInABox
MantisInABox2y ago
Anytime
dev00
dev00OP2y ago
alright i fixed everything i had set SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') in settings.py for django, which fixed the redirect error.
MantisInABox
MantisInABox2y ago
You’re good. It’s solved
Brody
Brody2y ago
woohoo
Want results from more Discord servers?
Add your server