R
Railway•7mo ago
Novixel

Issue Deploying Django App with Gunicorn on Railway

It's been a few days of trying to get this up for some production tests but I'm having issues getting it to launch on railway. Everything works great locally in the debug environment 'python manage.py runserver'. I'm still relatively new regarding web server deployment but from what I read railway was a good starting point for my use case but I'm still unsure. I've added all the necessary files for deployment, changed my settings for production, and hidden my variables in the environment (I have them on railway too). Requirements, Runtime, procfile and gunicorn.conf. For some reason, I always seem to encounter an issue with the docker image building or it says no start-up command and I'm not sure what command would be required while I have the procfile. Any help would be appreciated and if anyone has the time to help me out more in-depth, I'm willing to pay if you can help me solve my issue.
130 Replies
Percy
Percy•7mo ago
Project ID: N/A
Brody
Brody•7mo ago
if your Procfile doesn't have a capital P it wont be detected.
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
what are its contents?
Novixel
NovixelOP•7mo ago
release: python manage.py migrate web: gunicorn dragon.wsgi -c gunicorn.conf.py
Brody
Brody•7mo ago
i think it would be best to delete the heroku Procfile and use a railway.json file instead - https://github.com/railwayapp-templates/django/blob/main/railway.json
Novixel
NovixelOP•7mo ago
Ill try that So it looks like it deployed correctly but it failed to respond
Novixel
NovixelOP•7mo ago
No description
Novixel
NovixelOP•7mo ago
could it be my port with the conf file
Brody
Brody•7mo ago
yes, send your gunicorn.conf please
Novixel
NovixelOP•7mo ago
bind = "0.0.0.0:8000" workers = 3 timeout = 120
Brody
Brody•7mo ago
remove the bind line
Novixel
NovixelOP•7mo ago
okay Same thing
Novixel
NovixelOP•7mo ago
No description
Novixel
NovixelOP•7mo ago
it selected a port tho Invalid HTTP_HOST header: 'dragon-production.up.railway.app'. You may need to add 'dragon-production.up.railway.app' to ALLOWED_HOSTS. oo
Brody
Brody•7mo ago
please be more specfic when you say there is an error
Novixel
NovixelOP•7mo ago
this is the first actual error ive gotten so. Progress lol ima try to add that I appreciate your time. I've tried to deploy with he cli as it seems faster but I always run in to this error
Failed to stream build logs: TLS error: webpki error: MissingOrMalformedExtensions
Failed to stream deploy logs: TLS error: webpki error: MissingOrMalformedExtensions
Failed to stream build logs: TLS error: webpki error: MissingOrMalformedExtensions
Failed to stream deploy logs: TLS error: webpki error: MissingOrMalformedExtensions
Brody
Brody•7mo ago
thats an issue with your os, but the code would have still been uploaded
Novixel
NovixelOP•7mo ago
No description
Novixel
NovixelOP•7mo ago
I thought soo I was gonna run a virtual env for it but I figured if I'm launching in railway I don't need to
Brody
Brody•7mo ago
are you using a custom domain?
Novixel
NovixelOP•7mo ago
no just he railway generated one
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
your code and or gunicorn is sending redirects when it shouldnt try adding --forwarded-allow-ips "*" to your gunicorn start command
Novixel
NovixelOP•7mo ago
No description
Novixel
NovixelOP•7mo ago
would it be any of this
Brody
Brody•7mo ago
no, please read the message again
Novixel
NovixelOP•7mo ago
okay i will try that WOOO okay sooo --forwarded-allow-ips "* what does it do is that an usecure thing i should worrie about
Brody
Brody•7mo ago
did it fix the redirect issue?
Novixel
NovixelOP•7mo ago
Yes
Novixel
NovixelOP•7mo ago
I have another issue too i see none of djangos static files are found
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
whats your current railway.json in use?
Novixel
NovixelOP•7mo ago
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn dragon.wsgi --forwarded-allow-ips '*'",
"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 dragon.wsgi --forwarded-allow-ips '*'",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
Brody
Brody•7mo ago
send your settings.py file please
Novixel
NovixelOP•7mo ago
Novixel
NovixelOP•7mo ago
Do you prefer bmac or do you want some crypto >?
Brody
Brody•7mo ago
use these -
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
you dont need to send me anything, but thank you
Novixel
NovixelOP•7mo ago
Well, I think you deserve something. You've been a great help. what you do want 😄 steam card or somthing
Brody
Brody•7mo ago
bmac if you insist
Novixel
NovixelOP•7mo ago
Sounds good Enjoy your trains
Brody
Brody•7mo ago
thank you very much
Novixel
NovixelOP•7mo ago
I may need a hand in the future so I'm gonna add you 😄 nothing is free in this world and your time is valuable so I will pay for your services. ?: (staticfiles.W004) The directory '/app/static' in the STATICFILES_DIRS setting does not exist. 125 static files copied to '/app/staticfiles'.
Brody
Brody•7mo ago
i appreciate that but i wouldn’t be here if i wanted the people i help to pay
Novixel
NovixelOP•7mo ago
i feel like I'm missing something
Brody
Brody•7mo ago
might be easier if you could share your repo?
Novixel
NovixelOP•7mo ago
Whats your git
Brody
Brody•7mo ago
brody192
Novixel
NovixelOP•7mo ago
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
looking i assume you have the root directory set to /app?
Novixel
NovixelOP•7mo ago
yes
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
where are your static files, i dont see them anywhere in the repo?
Novixel
NovixelOP•7mo ago
I dont have any stored just the django ones that install with pip would i need to store them in the repo ? everything else is working just not the admin not a big deal but I would like it to look properly
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
do you not have a static folder locally?
Novixel
NovixelOP•7mo ago
no worked fine without it
Brody
Brody•7mo ago
send a link to your site please
Brody
Brody•7mo ago
what do you see when you visit that site?
Novixel
NovixelOP•7mo ago
Eveything is working correctly
Brody
Brody•7mo ago
yep, looks like it was just cache
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
what does it look like running locally
Novixel
NovixelOP•7mo ago
One moment not letting me run it local now
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
why are you trying to access it with https?
Novixel
NovixelOP•7mo ago
im not lol its forcing
Brody
Brody•7mo ago
what command did you run
Novixel
NovixelOP•7mo ago
python manage.py runserver was working fine before
Brody
Brody•7mo ago
django seems to disagree with you on this
Novixel
NovixelOP•7mo ago
No description
Novixel
NovixelOP•7mo ago
but it forces https
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
dont open it with https
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
is it redirecting you?
Novixel
NovixelOP•7mo ago
yes it sends me to https either way i try to access it now
Brody
Brody•7mo ago
something somewhere is set to do that
Novixel
NovixelOP•7mo ago
okay i found it
Brody
Brody•7mo ago
what was it?
Novixel
NovixelOP•7mo ago
If i go with http://localhost:8000 it works but not http://127.0.0.1:8000/ very odd
Novixel
NovixelOP•7mo ago
No description
Novixel
NovixelOP•7mo ago
this is what its suppose to look like
Brody
Brody•7mo ago
what page is that
Novixel
NovixelOP•7mo ago
django admin
Brody
Brody•7mo ago
what url path
Brody
Brody•7mo ago
please go to the path you are having issues with on railway
Novixel
NovixelOP•7mo ago
im there
Novixel
NovixelOP•7mo ago
No description
Novixel
NovixelOP•7mo ago
seem the css static files are not found
Brody
Brody•7mo ago
so same thing locally then
Novixel
NovixelOP•7mo ago
locally is showing it correctly
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
please go to the same path you are having issues with on railway
Novixel
NovixelOP•7mo ago
I am
Brody
Brody•7mo ago
/admin != /admin/login/?next=/admin/
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
i can only go off the information you provide me
Novixel
NovixelOP•7mo ago
Yes i know lol sorry I have a bigger issue. i can fix the static thing im sure by just grabbing the django files and loading adding them to the repo My threading loop wont work on the server
Brody
Brody•7mo ago
you only have 1 vcpu so theres nothing to thread
Novixel
NovixelOP•7mo ago
that makes sence anyway to fix it ?
Novixel
NovixelOP•7mo ago
No description
Brody
Brody•7mo ago
upgrade to the hobby plan
Novixel
NovixelOP•7mo ago
okay
Brody
Brody•7mo ago
i mean thats what i assume is the issue
Novixel
NovixelOP•7mo ago
It would make the most sense if i only have one thread to work off of
root
root•7mo ago
Python should be smart enough to run it anyway
Brody
Brody•7mo ago
true
root
root•7mo ago
JS's event loop does fake threading, I'd be very surprised if Python can't do the same
Brody
Brody•7mo ago
its either bad code or trial plan
Novixel
NovixelOP•7mo ago
yeah I wasn't sure if it was the best way to go but this is just proof of concept right now getting everything working I was going to use celery but that was a can of worms i couldn't figure out without deep dive 2 vCPU per Container the trial has 2 soo it should work if that was the issue
Brody
Brody•7mo ago
where does it say that, i thought it was 1
Novixel
NovixelOP•7mo ago
No description
Novixel
NovixelOP•7mo ago
im planning on upgrading once i get it working but I'm not sure how railway handles threading
Brody
Brody•7mo ago
well then that leaves code issue nothing to do with railway
Novixel
NovixelOP•7mo ago
Okay. So if it works locally without issues where would i start looking if its on railway my logs give me nothing
Brody
Brody•7mo ago
i honestly wouldnt know, but if your logs give you nothing then you are not logging anything, id start by adding verbose logging
Novixel
NovixelOP•7mo ago
that would be good how can i add the verbose logging to my start up with gunicorn
Brody
Brody•7mo ago
find a logging package you like and start using it
Novixel
NovixelOP•7mo ago
I can just use regular python logging packages? nothing special for railway?
Brody
Brody•7mo ago
of course, what makes you think youd need to use something special?
Novixel
NovixelOP•7mo ago
Idk still relatively new to web server stuff wasn't sure if there was anything special about it
Brody
Brody•7mo ago
when it comes down to it, its just printing text, nothing platform specific in any way
Novixel
NovixelOP•7mo ago
I appreciate all your help I'm gonna do some bug testing and some deeper logging. Thank you
Brody
Brody•7mo ago
no problem!
Want results from more Discord servers?
Add your server