[Python/Django] qovery run is returning fine but the deployment after git push is still a failure

Issues information

Your issue
Having a hard time deploying an appp

Describe here your issue
Hello, deployment logs doesn’t help me to understand why the app failed to start. It may be related to DB setting or ENV/Built-in Variables with my Dockerfile. As it’s the first i’m using Docker i may have misconfigured things.

I also add 2 ENV (SECREY_KEY and ENV as Environnement variables in qovery GUI.

Here what might help debuugging my deployment failures:

Return of qovery run :
> qovery run

specify here your dockerfile content :

FROM python:3.8.0-alpine

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ARG SECRET_KEY=dummypassword
ARG ENV=PRODUCTION
ENV SECRET_KEY=$SECRET_KEY
ENV ENV=$ENV

RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev

RUN pip install --upgrade pip
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

COPY bakpak_project /usr/src/app/
COPY entrypoint.sh /usr/src/app

EXPOSE 8000

ENTRYPOINT ["./entrypoint.sh"]

Blockquote

my yml file :


application:
name: “brasserie_bakpaker_qovery”
project: “Brasserie_Bakpaker”
publicly_accessible: true
databases:

  • type: “POSTGRESQL”
    name: “bakpakDB”
    version: “12.6.0”
    routers:
  • name: “main”
    routes:
    • application_name: “brasserie_bakpaker_qovery”
      paths:
      • “/”

maybe my DB settings in python might help :

if os.environ.get(‘ENV’) == “PRODUCTION”:
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’,
‘NAME’: os.environ.get(‘QOVERY_DATABASE_BAKPAKDB_DATABASE’),
‘USER’: os.environ.get(‘QOVERY_DATABASE_BAKPAKDB_USERNAME’),
‘PASSWORD’: os.environ.get(‘QOVERY_DATABASE_BAKPAKDB_PASSWORD’),
‘HOST’: os.environ.get(‘QOVERY_DATABASE_BAKPAKDB_HOST’),
‘PORT’: os.environ.get(‘QOVERY_DATABASE_BAKPAKDB_PORT’),
},
}

Thank you !

Hello,
it looks like something is not going well with your Dockerfile. Does it run locally when you use it ?

Here is the return of the cmd “docker build .”:

It looks ok but this my first time working with Docker, i might missing something though.

I’m not an entrypoint user. Prefer to use CMD. If you missed we have a little tutorial on how to write a Dockerfile. Could maybe help to make things clearer.

Here is the update Dockerfile thanks to your link:

FROM python:3.8.0-alpine

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ARG SECRET_KEY=dummypassword
ARG ENV=PRODUCTION
ENV SECRET_KEY=dummypassword
ENV ENV=PRODUCTION


RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev

RUN pip install --upgrade pip
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

COPY ./bakpak_project /usr/src/app/

COPY ./.env /usr/src/app/

COPY entrypoint.sh /usr/src/app

EXPOSE 8000

RUN python3 manage.py collectstatic --noinput

CMD ["python", "manage.py", "makemigrations"]
CMD ["python"," manage.py", " migrate"]
CMD ["python", "manage.py", "runserver"]

The return is ok with “qovery run” but still not when i deploy on Qovery.
Deployment still says the app won’t start after sucessful database deployment.

Is there other ways to debug ?

It looks like you declare two different ports, 8000 in Dockerfile and 8080 in qovery.yaml. Could you set the right one ?

I set the right ports.

Then i tried to do the following commands locally :
docker build . -t test
docker run test

this is the last main output :

Is the server running locally and accepting
connections on Unix domain socket “/tmp/.s.PGSQL.5432”?

could it explain why the app won’t start ?

Few things are still wrong in your dockerfile.

FROM python:3.8.0-alpine

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ARG SECRET_KEY=dummypassword
ARG ENV=PRODUCTION
ENV SECRET_KEY=dummypassword
ENV ENV=PRODUCTION

COPY . .

RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN python3 ./bakpak_project/manage.py collectstatic --noinput
RUN python3 ./bakpak_project/manage.py makemigrations
RUN python3 ./bakpak_project/manage.py migrate

EXPOSE 8000

CMD ["python3", "./bakpak_project/manage.py", "runserver"]

COPY . . copy all files from the project into the image. If you need to prevent some copy, you can add a .dockerignore file in your repo. This file works like .gitignore.

The CMD instruction should only be used once at the end. We could say that it’s used to start the app while RUN instruction is made for preparing stuffs.

This file should work. Don’t hesitate if you still have issue, we’ll see what we can do.

Damm ! it works, thank you a lot Enzo !
The fixes :

  • don’t use underscore in yml, only hyphen
  • start the runserver cmd with 0.0.0.0:8000
  • set the port 8000
  • understand how a dockerfile works
2 Likes