Issue Deploying Django App with Gunicorn on Railway

AnonymousTRIAL

a year ago

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.

0 Replies

a year ago

if your Procfile doesn't have a capital P it wont be detected.


AnonymousTRIAL

a year ago

1234180008180973800


a year ago

what are its contents?


AnonymousTRIAL

a year ago

release: python manage.py migrate
web: gunicorn dragon.wsgi -c gunicorn.conf.py


a year ago

i think it would be best to delete the heroku Procfile and use a railway.json file instead -


AnonymousTRIAL

a year ago

Ill try that


AnonymousTRIAL

a year ago

So it looks like it deployed correctly but it failed to respond


AnonymousTRIAL

a year ago

1234181485767037200


AnonymousTRIAL

a year ago

could it be my port


AnonymousTRIAL

a year ago

with the conf file


a year ago

yes, send your gunicorn.conf please


AnonymousTRIAL

a year ago

bind = "0.0.0.0:8000"
workers = 3
timeout = 120


a year ago

remove the bind line


AnonymousTRIAL

a year ago

okay


AnonymousTRIAL

a year ago

Same thing


AnonymousTRIAL

a year ago

1234182677985362200


AnonymousTRIAL

a year ago

it selected a port tho


AnonymousTRIAL

a year ago

Invalid HTTPHOST header: 'dragon-production.up.railway.app'. You may need to add 'dragon-production.up.railway.app' to ALLOWEDHOSTS.


AnonymousTRIAL

a year ago

oo


a year ago

please be more specfic when you say there is an error


AnonymousTRIAL

a year ago

this is the first actual error ive gotten so. Progress lol


AnonymousTRIAL

a year ago

ima try to add that


AnonymousTRIAL

a year ago

I appreciate your time.


AnonymousTRIAL

a year ago

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


a year ago

thats an issue with your os, but the code would have still been uploaded


AnonymousTRIAL

a year ago

1234183862796423200


AnonymousTRIAL

a year 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


a year ago

are you using a custom domain?


AnonymousTRIAL

a year ago

no just he railway generated one


AnonymousTRIAL

a year ago

1234184350879187000


a year ago

your code and or gunicorn is sending redirects when it shouldnt


a year ago

try adding --forwarded-allow-ips "*" to your gunicorn start command


AnonymousTRIAL

a year ago

1234184962706505700


AnonymousTRIAL

a year ago

would it be any of this


a year ago

no, please read the message again


AnonymousTRIAL

a year ago

okay i will try that


AnonymousTRIAL

a year ago

WOOO


AnonymousTRIAL

a year ago

okay sooo


AnonymousTRIAL

a year ago

--forwarded-allow-ips "* what does it do


AnonymousTRIAL

a year ago

is that an usecure thing i should worrie about


a year ago

did it fix the redirect issue?


AnonymousTRIAL

a year ago

Yes


a year ago


AnonymousTRIAL

a year ago

I have another issue too i see


AnonymousTRIAL

a year ago

none of djangos static files are found


AnonymousTRIAL

a year ago

1234186788289904600


a year ago

whats your current railway.json in use?


AnonymousTRIAL

a year 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 } }


a year ago

send your settings.py file please


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

Do you prefer bmac or do you want some crypto >?


a year ago

use these -

STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

a year ago

you dont need to send me anything, but thank you


AnonymousTRIAL

a year ago

Well, I think you deserve something. You've been a great help.


AnonymousTRIAL

a year ago

what you do want 😄


AnonymousTRIAL

a year ago

steam card or somthing


a year ago

bmac if you insist


AnonymousTRIAL

a year ago

Sounds good


AnonymousTRIAL

a year ago

Enjoy your trains


a year ago

thank you very much


AnonymousTRIAL

a year ago

I may need a hand in the future so I'm gonna add you 😄


AnonymousTRIAL

a year ago

nothing is free in this world and your time is valuable so I will pay for your services.


AnonymousTRIAL

a year ago

?: (staticfiles.W004) The directory '/app/static' in the STATICFILES_DIRS setting does not exist.

125 static files copied to '/app/staticfiles'.


a year ago

i appreciate that but i wouldn’t be here if i wanted the people i help to pay


AnonymousTRIAL

a year ago

i feel like I'm missing something


a year ago

might be easier if you could share your repo?


AnonymousTRIAL

a year ago

Whats your git


a year ago

brody192


AnonymousTRIAL

a year ago

ive added you


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

1234190576027697200


a year ago

looking


a year ago

i assume you have the root directory set to /app?


AnonymousTRIAL

a year ago

yes


AnonymousTRIAL

a year ago

1234191124554453200


a year ago

where are your static files, i dont see them anywhere in the repo?


AnonymousTRIAL

a year ago

I dont have any stored just the django ones that install with pip


AnonymousTRIAL

a year ago

would i need to store them in the repo ?


AnonymousTRIAL

a year ago

everything else is working


AnonymousTRIAL

a year ago

just not the admin


AnonymousTRIAL

a year ago

not a big deal but I would like it to look properly


AnonymousTRIAL

a year ago

1234191616663883800


a year ago

do you not have a static folder locally?


AnonymousTRIAL

a year ago

no


AnonymousTRIAL

a year ago

worked fine without it


a year ago

send a link to your site please



a year ago

what do you see when you visit that site?


AnonymousTRIAL

a year ago

Eveything is working correctly


a year ago

yep, looks like it was just cache



AnonymousTRIAL

a year ago

looks off


AnonymousTRIAL

a year ago

1234192952109170700


a year ago

what does it look like running locally


AnonymousTRIAL

a year ago

One moment not letting me run it local now


AnonymousTRIAL

a year ago

1234194236296003600


a year ago

why are you trying to access it with https?


AnonymousTRIAL

a year ago

im not lol


AnonymousTRIAL

a year ago

its forcing


a year ago

what command did you run


AnonymousTRIAL

a year ago

python manage.py runserver


AnonymousTRIAL

a year ago

was working fine before


a year ago

django seems to disagree with you on this


AnonymousTRIAL

a year ago

1234195204894888200


AnonymousTRIAL

a year ago

but it forces https


AnonymousTRIAL

a year ago

1234195272666452000


a year ago

dont open it with https


AnonymousTRIAL

a year ago

1234195389280948200


a year ago

is it redirecting you?


AnonymousTRIAL

a year ago

yes


AnonymousTRIAL

a year ago

it sends me to https either way i try to access it now


a year ago

something somewhere is set to do that


AnonymousTRIAL

a year ago

okay


AnonymousTRIAL

a year ago

i found it


a year ago

what was it?


AnonymousTRIAL

a year ago

If i go with http://localhost:8000 it works


AnonymousTRIAL

a year ago


AnonymousTRIAL

a year ago

very odd


AnonymousTRIAL

a year ago

1234196218058510300


AnonymousTRIAL

a year ago

this is what its suppose to look like


a year ago

what page is that


AnonymousTRIAL

a year ago

django admin


a year ago

what url path



AnonymousTRIAL

a year ago


a year ago

please go to the path you are having issues with on railway


AnonymousTRIAL

a year ago

im there


AnonymousTRIAL

a year ago

1234196475806880000


AnonymousTRIAL

a year ago

seem the css static files are not found


a year ago

so same thing locally then


AnonymousTRIAL

a year ago

locally is showing it correctly


AnonymousTRIAL

a year ago

1234196688864940000


a year ago

please go to the same path you are having issues with on railway


AnonymousTRIAL

a year ago

I am


a year ago

/admin != /admin/login/?next=/admin/


AnonymousTRIAL

a year ago

1234196926686036000


a year ago

i can only go off the information you provide me


AnonymousTRIAL

a year ago

Yes i know lol sorry


AnonymousTRIAL

a year ago

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


AnonymousTRIAL

a year ago

My threading loop wont work on the server


a year ago

you only have 1 vcpu so theres nothing to thread


AnonymousTRIAL

a year ago

that makes sence


AnonymousTRIAL

a year ago

anyway to fix it ?


AnonymousTRIAL

a year ago

1234197483085889800


a year ago

upgrade to the hobby plan


AnonymousTRIAL

a year ago

okay


a year ago

i mean thats what i assume is the issue


AnonymousTRIAL

a year ago

It would make the most sense if i only have one thread to work off of


a year ago

Python should be smart enough to run it anyway


a year ago

true


a year ago

JS's event loop does fake threading, I'd be very surprised if Python can't do the same


a year ago

its either bad code or trial plan


AnonymousTRIAL

a year 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


AnonymousTRIAL

a year ago

I was going to use celery but that was a can of worms i couldn't figure out without deep dive


AnonymousTRIAL

a year ago

2 vCPU per Container


AnonymousTRIAL

a year ago

the trial has 2 soo it should work if that was the issue


a year ago

where does it say that, i thought it was 1


AnonymousTRIAL

a year ago

1234198844128886800


AnonymousTRIAL

a year ago

im planning on upgrading once i get it working


AnonymousTRIAL

a year ago

but I'm not sure how railway handles threading


a year ago

well then that leaves code issue


a year ago

nothing to do with railway


AnonymousTRIAL

a year ago

Okay. So if it works locally without issues where would i start looking if its on railway


AnonymousTRIAL

a year ago

my logs give me nothing


a year ago

i honestly wouldnt know, but if your logs give you nothing then you are not logging anything, id start by adding verbose logging


AnonymousTRIAL

a year ago

that would be good how can i add the verbose logging to my start up with gunicorn


a year ago

find a logging package you like and start using it


AnonymousTRIAL

a year ago

I can just use regular python logging packages? nothing special for railway?


a year ago

of course, what makes you think youd need to use something special?


AnonymousTRIAL

a year ago

Idk still relatively new to web server stuff wasn't sure if there was anything special about it


a year ago

when it comes down to it, its just printing text, nothing platform specific in any way


AnonymousTRIAL

a year ago

I appreciate all your help I'm gonna do some bug testing and some deeper logging.


AnonymousTRIAL

a year ago

Thank you


a year ago

no problem!