R
Railway•2y ago
zimapurple

Having trouble starting gunicorn with Django deployed from dockerfile resulting in 503

Trying to deploy a django project that was developed locally with this Docker File
# Pull base image
FROM python:3.10.4-slim-bullseye

# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# Copy project
COPY . .
# Pull base image
FROM python:3.10.4-slim-bullseye

# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# Copy project
COPY . .
From the Django Railway template I've set the railway.json to be:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && gunicorn engi_alpha.wsgi",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 1
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && gunicorn engi_alpha.wsgi",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 1
}
}
I've also set ALLOWED_HOSTS to be *, though I would like to make that specific soon. After running railway up in a linked project the build appears to install all requirements fine, and proceeds to deploy. With a Postgres DB service I'm able to get the DB to run the migrations successfully, creating empty tables, however at that point the logs stop (no errors, just no more entries). I've attached a screenshot of the repo structure and the end of the railway up command. I feel like I'm missing something to do with either permissions, URLS or the deployment commands, but I've not got there yet. It's my first personal project in web dev so I;m sure the answer is obvious to many :p Any help appreciated 🙂
36 Replies
Percy
Percy•2y ago
Project ID: ee6fe531-fb8f-45f3-906e-f22374d487ac
zimapurple
zimapurple•2y ago
ee6fe531-fb8f-45f3-906e-f22374d487ac
Brody
Brody•2y ago
does the logs in the railway UI also stop at this point?
zimapurple
zimapurple•2y ago
They do
Brody
Brody•2y ago
looks like the migration runs, but it never gets to start gunicorn do you have a start setting configured somewhere else like in the service settings?
zimapurple
zimapurple•2y ago
If you mean through the value in permissable-voleyball > settings > deploy > start command the value has a nite that say it's sourced from the settings file. Was that the question? Also, Ive just come back to the page and am now seeing Deployments Paused Builds need to drain. null
Brody
Brody•2y ago
yeah lets come back to this after the incidents are resolved https://discord.com/channels/713503345364697088/846875565357006878/1103346301829136414
zimapurple
zimapurple•2y ago
Sure, thanks for taking a gander
Brody
Brody•2y ago
hey wanna try again?
zimapurple
zimapurple•2y ago
Sure, I'll run a 'railway up' and see what happens.
zimapurple
zimapurple•2y ago
Interesting, totally different error. Trying to work out if I changed something that would cause it. Looks like the behaviour is now to prioritise the settings file and not the docker file?
Brody
Brody•2y ago
click the code button and show me a screenshot
zimapurple
zimapurple•2y ago
except it's also not accessing my settings file? locally it;s still got my start command
zimapurple
zimapurple•2y ago
Brody
Brody•2y ago
you must not have your railway.json file in the right place
zimapurple
zimapurple•2y ago
ohhhhh i;ve run the cli in the wrong place, was working in a diff project. 1 sec
Brody
Brody•2y ago
show me your dockerignore file lol
zimapurple
zimapurple•2y ago
XD thought it was odd I had to relink the project.... building (theres a fat dep tree here 😦 )
Brody
Brody•2y ago
whats your requirements.txt look like?
zimapurple
zimapurple•2y ago
OK, build complete, succesful. Depployment completed, logs stop at no migrations to apply
asgiref==3.6.0
Bokeh == 3.1.0
crispy-bootstrap5==0.6
Django==4.0.10
django-allauth==0.50.0
django-crispy-forms==2.0
djlint==1.23.0
environs[django]==9.5.0
gunicorn==20.1.0
pandas==1.5.3
pandera==0.13.4
pytest-django==4.5.2
psycopg2-binary==2.9.3
requests==2.28.2
requests-mock==1.9.3
statsforecast==1.5.0
sqlparse==0.4.3
types-requests==2.28.11.17
whitenoise==6.2.0
asgiref==3.6.0
Bokeh == 3.1.0
crispy-bootstrap5==0.6
Django==4.0.10
django-allauth==0.50.0
django-crispy-forms==2.0
djlint==1.23.0
environs[django]==9.5.0
gunicorn==20.1.0
pandas==1.5.3
pandera==0.13.4
pytest-django==4.5.2
psycopg2-binary==2.9.3
requests==2.28.2
requests-mock==1.9.3
statsforecast==1.5.0
sqlparse==0.4.3
types-requests==2.28.11.17
whitenoise==6.2.0
statsforcast has a fat set of it;s own dependencies however, they all completed
Brody
Brody•2y ago
did build finish?
zimapurple
zimapurple•2y ago
yup yup same behaviour
zimapurple
zimapurple•2y ago
Is it possible the difference between my railway.json and the fact I have a dockerfile in the repo itself is causing issues? The deploy is obviously automatically pointing at my docker, event though the railway.json points it to "NIXPACKS"
Brody
Brody•2y ago
why not just remove the railway.json file and then do (hold on)
# Pull base image
FROM python:3.10.4-slim-bullseye

# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Copy project
COPY . .

# Install dependencies
RUN pip install -r requirements.txt

# run migrations
RUN python manage.py migrate

# start server
CMD gunicorn engi_alpha.wsgi
# Pull base image
FROM python:3.10.4-slim-bullseye

# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Copy project
COPY . .

# Install dependencies
RUN pip install -r requirements.txt

# run migrations
RUN python manage.py migrate

# start server
CMD gunicorn engi_alpha.wsgi
so yeah delete the railway.json file, and ust that as your dockerfile
zimapurple
zimapurple•2y ago
I'll have a crack
zimapurple
zimapurple•2y ago
Failed at RUN python manage.py migrate, e.g. the step before the logs dropped previously. Issue seems to be related to detecting the SECRET_KEY varable, which it must have found succesfully before and is set in teh env vars
Brody
Brody•2y ago
# Pull base image
FROM python:3.10.4-slim-bullseye

# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Copy project
COPY . .

# Install dependencies
RUN pip install -r requirements.txt

# run migrations and start server
CMD python manage.py migrate && gunicorn engi_alpha.wsgi
# Pull base image
FROM python:3.10.4-slim-bullseye

# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Copy project
COPY . .

# Install dependencies
RUN pip install -r requirements.txt

# run migrations and start server
CMD python manage.py migrate && gunicorn engi_alpha.wsgi
try that
zimapurple
zimapurple•2y ago
well that built a lot faster, I guess railway caches the layer?
Brody
Brody•2y ago
maybe
zimapurple
zimapurple•2y ago
OHO! Closer, got more logs. URL still errors, but 301 this time.
Brody
Brody•2y ago
okay and now its a code issue, that i unfortunately cant help with, off to google you go!
zimapurple
zimapurple•2y ago
Sure, thanks for your help this evening, I'll head into the wild tomorrow.
Brody
Brody•2y ago
no problem!
zimapurple
zimapurple•2y ago
Seemingly just solved using the same info as in this SO: https://stackoverflow.com/questions/55726610/django-ssl-redirection-on-heroku-too-many-redirects Specifically adding the line SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') to the settings.py file. My current (and new) understanding is that this is a required setting when your project starts implementing more secure practices on proxy servers?
Stack Overflow
Django SSL redirection on Heroku: 'Too many redirects'
I have a web app deployed to Heroku with a custom domain name which DNS is managed through CloudFlare. What I want to do is redirect HTTP requests to HTTPS. After setting SECURE_SSL_REDIRECT to T...
zimapurple
zimapurple•2y ago
@Brody I've spotted that railway has community templates, and there is one for Django, however I didn't start from there because a) I wasn't sure if this would ever be worth deploying, b) the template used is extremely basic, verging on unsafe unless configured? and c) I didn't actually know about railway in the first stage of the work. Therefore my question is effectively: Is this deliberately railways approach, e.g. ALL complexity of the framework is up to the user, or is there an interest in 1) extending the existing template or 2) creating a second "auth focussed" django template? (fine both ways btw, straight up honest question)
Brody
Brody•2y ago
the purpose of the framework templates (like django's template) is just to show the user how to get the project active on railway, the rest it completely up to the user
Want results from more Discord servers?
Add your server