Unable to read Environment Variable using django-decouple when deploying

Issues information

  • OS: python:3.6
  • databases: postgres
  • Programming language and version: Python / Django

Your issue
I am trying to deploy an application built with python/django.
It is running fine locally.
The deployment fails with the error:
01 Jun, 16:07:21.353 app-z75d13a85-65fc45f75f-5v42r decouple.UndefinedValueError: SECRET_KEY not found. Declare it as envvar or define a default value.

We use django-decouple to read the environment variables from .env (works fine with Heroku).

However, it seems that django-decouple is not able to find the SECRET_KEY environment variable.

I have checked and this environment variable is correctly defined in Qovery (Environment Variable - not Secret).

In our code, this is the first environment variable that we try to access. I suppose that all other variables will not be accessible.

Any suggestion on how to debug this issue?

Dockerfile content (if any)

Building Dockerfile at the moment (not an expert), I suppose this is far from being optimized but it is working locally just fine.

FROM python:3.6.13
RUN pip install pipenv
COPY Pipfile Pipfile.lock ./
RUN pipenv install --deploy --system
COPY . ./

# Remove "pipenv run", add the bind argument
# (No need to repeat `command:` in `docker-compose.yml`)
CMD python manage.py runserver```

Does the env variable SECRET_KEY is necessary at the build time or run time of your application?

Qovery injects all your environment variables and secrets at build AND run time. If you are using your environment variables and secrets at the build time AND with a Dockerfile, you will need to indicate that you are using those environment variables in your Dockerfile.

You can refer to this thread.