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
Project ID:
N/A
if your Procfile doesn't have a capital P it wont be detected.
what are its contents?
release: python manage.py migrate
web: gunicorn dragon.wsgi -c gunicorn.conf.py
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
Ill try that
So it looks like it deployed correctly but it failed to respond
could it be my port
with the conf file
yes, send your gunicorn.conf please
bind = "0.0.0.0:8000"
workers = 3
timeout = 120
remove the bind line
okay
Same thing
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
please be more specfic when you say there is an error
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
thats an issue with your os, but the code would have still been uploaded
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
are you using a custom domain?
no just he railway generated one
your code and or gunicorn is sending redirects when it shouldnt
try adding
--forwarded-allow-ips "*"
to your gunicorn start commandwould it be any of this
no, please read the message again
okay i will try that
WOOO
okay sooo
--forwarded-allow-ips "* what does it do
is that an usecure thing i should worrie about
did it fix the redirect issue?
Yes
I have another issue too i see
none of djangos static files are found
whats your current railway.json in use?
send your settings.py file please
Do you prefer bmac or do you want some crypto >?
use these -
you dont need to send me anything, but thank you
Well, I think you deserve something. You've been a great help.
what you do want 😄
steam card or somthing
bmac if you insist
Sounds good
Enjoy your trains
thank you very much
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'.
i appreciate that but i wouldn’t be here if i wanted the people i help to pay
i feel like I'm missing something
might be easier if you could share your repo?
Whats your git
brody192
ive added you
https://github.com/Novixel/Dragon/
looking
i assume you have the root directory set to /app?
yes
where are your static files, i dont see them anywhere in the repo?
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
do you not have a static folder locally?
no
worked fine without it
send a link to your site please
what do you see when you visit that site?
Eveything is working correctly
yep, looks like it was just cache
what does it look like running locally
One moment not letting me run it local now
why are you trying to access it with https?
im not lol
its forcing
what command did you run
python manage.py runserver
was working fine before
django seems to disagree with you on this
but it forces https
dont open it with https
is it redirecting you?
yes
it sends me to https either way i try to access it now
something somewhere is set to do that
okay
i found it
what was it?
this is what its suppose to look like
what page is that
django admin
what url path
please go to the path you are having issues with on railway
im there
seem the css static files are not found
so same thing locally then
locally is showing it correctly
please go to the same path you are having issues with on railway
I am
/admin
!= /admin/login/?next=/admin/
i can only go off the information you provide me
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
you only have 1 vcpu so theres nothing to thread
that makes sence
anyway to fix it ?
upgrade to the hobby plan
okay
i mean thats what i assume is the issue
It would make the most sense if i only have one thread to work off of
Python should be smart enough to run it anyway
true
JS's event loop does fake threading, I'd be very surprised if Python can't do the same
its either bad code or trial plan
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
where does it say that, i thought it was 1
im planning on upgrading once i get it working
but I'm not sure how railway handles threading
well then that leaves code issue
nothing to do with railway
Okay. So if it works locally without issues where would i start looking if its on railway
my logs give me nothing
i honestly wouldnt know, but if your logs give you nothing then you are not logging anything, id start by adding verbose logging
that would be good how can i add the verbose logging to my start up with gunicorn
find a logging package you like and start using it
I can just use regular python logging packages? nothing special for railway?
of course, what makes you think youd need to use something special?
Idk still relatively new to web server stuff wasn't sure if there was anything special about it
when it comes down to it, its just printing text, nothing platform specific in any way
I appreciate all your help I'm gonna do some bug testing and some deeper logging.
Thank you
no problem!