From c2d4170237e87cd2ad5ed2f38b7fc1625dfcbaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Bla=C5=BEi=C4=8D?= Date: Wed, 10 Sep 2014 19:51:02 +0200 Subject: [PATCH 1/3] Added a separate settings_production.py file that gets imported if env variable ENVIRONMENT is set to production --- codeweekeu/settings.py | 4 +++ codeweekeu/settings_production.py | 47 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 codeweekeu/settings_production.py diff --git a/codeweekeu/settings.py b/codeweekeu/settings.py index faefb17b..a1ba17b9 100644 --- a/codeweekeu/settings.py +++ b/codeweekeu/settings.py @@ -547,3 +547,7 @@ from settings_local import * except ImportError, e: pass + +# if we're running on the server, use server specific settings +if os.environ['ENVIRONMENT'] == 'production': + from settings_production import * diff --git a/codeweekeu/settings_production.py b/codeweekeu/settings_production.py new file mode 100644 index 00000000..3bcb8bd9 --- /dev/null +++ b/codeweekeu/settings_production.py @@ -0,0 +1,47 @@ +from .settings import * +import dj_database_url +import os + +DEBUG = False + +dbconfig = dj_database_url.config() +if dbconfig: + DATABASES['default'] = dbconfig +else: + del DATABASES['default'] + +SECRET_KEY = os.environ['SECRET_KEY'] + +STATIC_URL = '/static/' +STATIC_ROOT = join(DJANGO_ROOT, 'staticfiles') +STATICFILES_DIRS = ( + os.path.join(DJANGO_ROOT, 'static'), +) + +# Honor the 'X-Forwarded-Proto' header for request.is_secure() +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') + +# Allow all host headers +ALLOWED_HOSTS = ['*'] + +# S3 Storage settings +DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' +# use http instead of https +AWS_S3_SECURE_URLS = False +# don't add complex authentication-related query parameters for requests +AWS_QUERYSTRING_AUTH = False +# Read secret data for social logins +AWS_S3_ACCESS_KEY_ID = os.environ['AWS_S3_KEY'] +AWS_S3_SECRET_ACCESS_KEY = os.environ['AWS_S3_SECRET'] +AWS_STORAGE_BUCKET_NAME = os.environ['AWS_BUCKET'] + +# URL that handles the media served from MEDIA_ROOT. +MEDIA_URL = 'http://' + AWS_STORAGE_BUCKET_NAME + '.s3.amazonaws.com/' + +# Get secret data for social logins +SOCIAL_AUTH_GITHUB_KEY = os.environ['GITHUB_KEY'] +SOCIAL_AUTH_GITHUB_SECRET = os.environ['GITHUB_SECRET'] +SOCIAL_AUTH_FACEBOOK_KEY = os.environ['FACEBOOK_KEY'] +SOCIAL_AUTH_FACEBOOK_SECRET = os.environ['FACEBOOK_SECRET'] +SOCIAL_AUTH_TWITTER_KEY = os.environ['TWITTER_KEY'] +SOCIAL_AUTH_TWITTER_SECRET = os.environ['TWITTER_SECRET'] From 103128650dc04290a7d467372b287a3f13ce2eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Bla=C5=BEi=C4=8D?= Date: Wed, 10 Sep 2014 21:00:51 +0200 Subject: [PATCH 2/3] forgot to import os --- codeweekeu/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/codeweekeu/settings.py b/codeweekeu/settings.py index a1ba17b9..9749ad9b 100644 --- a/codeweekeu/settings.py +++ b/codeweekeu/settings.py @@ -3,6 +3,7 @@ """ import sys +import os from os.path import abspath, basename, dirname, join, normpath ########## PATH CONFIGURATION # Absolute filesystem path to this Django project directory. From 1d1b90b801d80e2a496f66e0c22d72e62ad90bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Bla=C5=BEi=C4=8D?= Date: Wed, 10 Sep 2014 21:19:36 +0200 Subject: [PATCH 3/3] Added check if ENVIRONMENT variable is actually set before reading it --- codeweekeu/settings.py | 3 ++- codeweekeu/settings_production.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/codeweekeu/settings.py b/codeweekeu/settings.py index 9749ad9b..91c8011a 100644 --- a/codeweekeu/settings.py +++ b/codeweekeu/settings.py @@ -550,5 +550,6 @@ pass # if we're running on the server, use server specific settings -if os.environ['ENVIRONMENT'] == 'production': +ENVIRONMENT = os.getenv('ENVIRONMENT', 'development') +if ENVIRONMENT == 'production': from settings_production import * diff --git a/codeweekeu/settings_production.py b/codeweekeu/settings_production.py index 3bcb8bd9..e23cfbef 100644 --- a/codeweekeu/settings_production.py +++ b/codeweekeu/settings_production.py @@ -2,6 +2,8 @@ import dj_database_url import os +print "in production mode" + DEBUG = False dbconfig = dj_database_url.config()