Skip to content

Environment variables test

Tyapkov requested to merge environment-variables-test into master

In the previous setup we had different settings files in settings folder. These settings where later mounted into the docker container on docker-compose up.

Drawbacks of previous aproach:

  1. Settings specified in separate files are not secured. Users who can see settings files do also have access to all the "secured" variables.
  2. Mounting the volume is a bad idea, because we cannot collect static files or create folders in the mounting volume during the docker build.
  3. Tree structure does not allow to find required settings in a fast way, you have to switch between different settings files.
  4. During the mount of the settings file, empty files appeared in the git (, which should be deleted after containers are off. Otherwise we have to create empty file in the repository.

How it works:

  1. In the root of the project we have env file in which all the production variables are saved. In my case ENV file looks like:

where *** are actual settings

  1. We have 2 yml files used for docker-compose. One is used to run production environment, another for development environment. If you use PyCharm then you can create setup to run either development or production environment.
  2. Variables of docker-compose-dev.yml (DEBUG and etc) override variables defined in ENV file and enables development settings.
  3. It is still possible to use local development environment without docker. When you run python runserver default variables from are in use.
Edited by Tyapkov

Merge request reports