diff mbox

settings: Use environment variables by default

Message ID 1455467456-26754-1-git-send-email-stephen.finucane@intel.com
State Accepted
Headers show

Commit Message

Stephen Finucane Feb. 14, 2016, 4:30 p.m. UTC
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 <stephen.finucane@intel.com>
---
 patchwork/settings/production.example.py |   24 ++++++++++++++++++------
 patchwork/wsgi.py                        |    1 -
 2 files changed, 18 insertions(+), 7 deletions(-)

Comments

Stephen Finucane Feb. 17, 2016, 7:39 p.m. UTC | #1
On 14 Feb 16:30, Stephen Finucane wrote:
> 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 <stephen.finucane@intel.com>

Merged.
diff mbox

Patch

diff --git a/patchwork/settings/production.example.py b/patchwork/settings/production.example.py
index 5530bf9..195ffcc 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 <patchwork@patchwork.example.com>'
 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 c304830..714ea12 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