Skip to content

Configuration

Angel Rey edited this page Dec 23, 2020 · 1 revision

Intro

We follow a common pattern used by many big projects, we have three levels of config:

  • codebase-wide config defaults (core/oddslingers/settings.py)
  • environment-specific config (env/dev.env, env/prod.env, etc.)
  • machine-specific config (env/secrets.env and/or environment variables)

Machine-specific settings can override the environment-specific settings.
Both environment-specific and machine-specific override the defaults in settings.py.

Want to change a setting?

First identify who you want the new setting to apply to. Do you want to change the setting for:

  • Only for one run (e.g. for quickly testing something): set an environment variable
  • Persistently but only on your own machine, and no one else's: Edit: env/secrets.env
  • Persistently for all dev users of the codebase? Edit: env/dev.env
  • Persistently but only on prod or beta? Edit: env/prod.env or env/beta.env
  • CircleCI builds only? Edit: env/ci.env
  • Everyone? Edit: all instances of the setting in env/*.env first!!, then afterwards change the default in core/oddslingers/settings.py

Precedence Order

  1. Environment variables (you can set these with export name=val in bash, set -x name val in fish, or env name=val ./manage.py command_to_run)
  2. env/secrets.env, this is the proper location for machine-specific settings like DB passwords or local config overrides
  3. env/{ODDSLINGERS_ENV}.env, e.g. if you're on dev env/dev.env, this file is only for defaults, don't modify it unless you want add the change for everyone
  4. core/oddslingers/settings.py, this is the main python settings file with all the settings, everything here is overridden from the settings above

Configuration Loading Code

If you need to inspect the source of the config loaded system, see these areas:

  • general process settings: etc/supervisord/*.conf
  • nginx settings: etc/nginx/conf.d/*.conf
  • django settings: middle section of core/settings.py: import_env_file(...)