From: Stephen Finucane Date: Tue, 9 Feb 2016 12:12:37 +0000 (+0000) Subject: settings: Use environment variables by default X-Git-Tag: v1.1.0~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7667078e643e02abc4475742894582d2fd3aab54;p=thirdparty%2Fpatchwork.git settings: Use environment variables by default The Django documentation suggests using environment variables as a way to allow devs to commit settings files via source control without including confidential information therein [1]. As such, change the provided 'production' settings to do this. This should promote best practices while also ensuring provisioning tools like 'ansible-django-stack' [2] work as expected. [1] https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ [2] https://github.com/jcalazan/ansible-django-stack Signed-off-by: Stephen Finucane --- diff --git a/patchwork/settings/production.example.py b/patchwork/settings/production.example.py index 5530bf97..195ffcc8 100644 --- a/patchwork/settings/production.example.py +++ b/patchwork/settings/production.example.py @@ -9,6 +9,8 @@ Design based on: from __future__ import absolute_import +import os + from .base import * # noqa # @@ -25,20 +27,26 @@ from .base import * # noqa # chars = string.letters + string.digits + string.punctuation # print repr("".join([random.choice(chars) for i in range(0,50)])) -# SECRET_KEY = '00000000000000000000000000000000000000000000000000' +SECRET_KEY = os.environ['DJANGO_SECRET_KEY'] # Email # # Replace this with your own details -ADMINS = ( - # ('Jeremy Kerr', 'jk@ozlabs.org'), -) +EMAIL_HOST = os.getenv('EMAIL_HOST', 'localhost') +EMAIL_PORT = os.getenv('EMAIL_PORT', 25) +EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', '') +EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD', '') +EMAIL_USE_TLS = True DEFAULT_FROM_EMAIL = 'Patchwork ' SERVER_EMAIL = DEFAULT_FROM_EMAIL NOTIFICATION_FROM_EMAIL = DEFAULT_FROM_EMAIL +ADMINS = ( + ('Jeremy Kerr', 'jk@ozlabs.org'), +) + # Database # # If you're using a postgres database, connecting over a local unix-domain @@ -48,7 +56,11 @@ NOTIFICATION_FROM_EMAIL = DEFAULT_FROM_EMAIL DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'patchwork', + 'NAME': os.environ.get('DATABASE_NAME', ''), + 'USER': os.environ.get('DATABASE_USER', ''), + 'PASSWORD': os.environ.get('DATABASE_PASSWORD', ''), + 'HOST': os.environ.get('DATABASE_HOST', ''), + 'PORT': os.environ.get('DATABASE_PORT', ''), }, } @@ -57,4 +69,4 @@ DATABASES = { # https://docs.djangoproject.com/en/1.7/ref/settings/#static-files # -STATIC_ROOT = '/srv/patchwork/htdocs/static' +STATIC_ROOT = os.environ.get('STATIC_ROOT', '/srv/patchwork/htdocs/static') diff --git a/patchwork/wsgi.py b/patchwork/wsgi.py index c304830d..714ea120 100644 --- a/patchwork/wsgi.py +++ b/patchwork/wsgi.py @@ -22,7 +22,6 @@ # Released under the GNU General Public License v2 or later. import os -import sys from django.core.wsgi import get_wsgi_application