How to correctly deploy Django + Postgres with Depot?

I encountered the following error while deploying my Django web app with the latest remote builder:

2.946   File "/usr/local/lib/python3.10/site-packages/psycopg/_conninfo_attempts.py", line 50, in conninfo_attempts
2.946     raise e.OperationalError(str(last_exc))
2.946 django.db.utils.OperationalError: [Errno -5] No address associated with hostname

it seems like psycopg can no longer find the DATABASE_URL correctly. The problem is gone with fly deploy --depot=false, so i guess the problem is from Depot.

Any suggestions for how to fix it with the new builder?

Can you post your dockerfile? Are you trying to access your database during your build? That’s not possible using Depot builders, for now.

The DOCKERFILE is mostly the default one generated during fly launch:

ARG PYTHON_VERSION=3.10-slim-buster

FROM python:${PYTHON_VERSION}

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN mkdir -p /code

WORKDIR /code

COPY requirements.txt /tmp/requirements.txt
RUN set -ex && \
    pip install --upgrade pip && \
    pip install -r /tmp/requirements.txt && \
    rm -rf /root/.cache/
COPY . /code

ENV DJANGO_SETTINGS_MODULE "config.settings.production"
RUN python manage.py collectstatic --noinput
RUN python manage.py migrate

EXPOSE 8000

CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "config.wsgi"]

except that I changed the config file to the production one, which read the .env, which contains the DATABASE_URL. Running python manage.py migrate requires the connection to the database.

So I guess all Django apps have to be deployed with the --depot=false flag?

From General to Build debugging

fly launch will have placed python manage.py migrate into your fly.toml as the release_command, which gets run in the production environment after the build. Your production environment likely has DATABASE_URL already set using fly secrets.

Running migrations in builds in not recommended. One reason: your production credentials in .env are embedded in the Docker image in the Fly Docker repository.

thanks a lot!

Added builders, postgres

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.