0

Following multiple articles around the web, I've split my Django 1.11 settings.py file into multiple files, base.py, local.py, staging.py, production.py, in a settings folder.

The Django app runs in a Docker container.

docker-compose.yml:

django:
    build:
      context: .
    env_file: .env
    command: ["/wait-for-it.sh", "mariadb:3306", "--", "/gunicorn.sh"]

In the Dockerfile I export the DJANGO_SETTINGS_MODULE as the local settings file (which in turn imports the base.py settings file).

Dockerfile:

FROM python:3.6.4
RUN mkdir /app
ADD requirements/*.txt app/requirements/
RUN pip install -r mira/requirements/dev.txt
ADD . /app
RUN export DJANGO_SETTINGS_MODULE=app.settings.local
RUN export DJANGO_SECRET_KEY=dummy-secret-key
COPY ./docker/web/entrypoint.sh ./docker/web/gunicorn.sh ./docker/web/wait-for-it.sh ./docker/web/logging.conf ./scripts/setup.sh /
RUN chmod +x /entrypoint.sh /gunicorn.sh /wait-for-it.sh /setup.sh
WORKDIR ./app

settings/base.py:

SECRET_KEY = os.environ['DJANGO_SECRET_KEY']

.env:

DJANGO_SECRET_KEY=FOOBAR

When I try to up the container, I get this error:

The SECRET_KEY setting must not be empty.

GluePear
  • 7,244
  • 20
  • 67
  • 120

0 Answers0