Stop writing settings files

Stop writing settings files

Bd9b4485bcf325b989b5721bd0ef4d91?s=128

Bruno Renié

May 15, 2013
Tweet

Transcript

  1. 3.

    local_settings # settings.py # settings goes here, and at the

    end… try: from local_settings import * except ImportError: pass
  2. 5.

    # settings/base.py INSTALLED_APPS = … # settings/production.py from .base import

    * # override here with # production-specific settings Multiple settings files $ python manage.py shell --settings=settings.production
  3. 7.

    — 12factor.net " " … strict separation of config from

    code. Config varies substantially across deploys,code does not.
  4. 8.

    Expose your configuration as environment variables Derive your settings from

    the environment DEBUG = bool(os.environ.get('DEBUG', False)) Use one settings file
  5. 11.

    daemontools' envdir path/to/env/ DATABASE_URL SENTRY_DSN … $ envdir path/to/env <child

    program> $ envdir path/to/env django-admin.py <command> Sane defaults for development kept under version control
  6. 12.

    envdir in ur manage.py if __name__ == "__main__": if 'test'

    in sys.argv: env_dir = os.path.join('tests', 'envdir') else: env_dir = 'envdir' env_vars = glob.glob(os.path.join(env_dir, '*')) for env_var in env_vars: with open(env_var, 'r') as env_var_file: os.environ.setdefault(env_var.split(os.sep)[-1], env_var_file.read().strip()) from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
  7. 13.

    One settings files, less moving parts Configuration as environment variables

    Production: set them with daemontools, circus, supervisor… Development: use envdir and/or a custom manage.py Your PaaS already supports them Easy to setup with Salt/Puppet/Chef Your sysadmin will thank you