-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathproduction.py
More file actions
186 lines (141 loc) · 4.87 KB
/
production.py
File metadata and controls
186 lines (141 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import os
import dj_database_url
from .base import *
# Do not set SECRET_KEY, Postgres or LDAP password or any other sensitive data here.
# Instead, use environment variables or create a local.py file on the server.
# Disable debug mode
DEBUG = False
TEMPLATES[0]['OPTIONS']['debug'] = False
# Configuration from environment variables
# Alternatively, you can set these in a local.py file on the server
env = os.environ.copy()
# On Torchbox servers, many environment variables are prefixed with "CFG_"
for key, value in os.environ.items():
if key.startswith('CFG_'):
env[key[4:]] = value
# Basic configuration
APP_NAME = env.get('APP_NAME', 'project_tier')
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
PREPEND_WWW = True
if 'SECRET_KEY' in env:
SECRET_KEY = env['SECRET_KEY']
if 'ALLOWED_HOSTS' in env:
ALLOWED_HOSTS = env['ALLOWED_HOSTS'].split(',')
else:
ALLOWED_HOSTS = ['*']
if 'PRIMARY_HOST' in env:
BASE_URL = 'http://%s/' % env['PRIMARY_HOST']
if 'SERVER_EMAIL' in env:
SERVER_EMAIL = env['SERVER_EMAIL']
if 'CACHE_PURGE_URL' in env:
INSTALLED_APPS += ( 'wagtail.contrib.wagtailfrontendcache', )
WAGTAILFRONTENDCACHE = {
'default': {
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
'LOCATION': env['CACHE_PURGE_URL'],
},
}
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
# Compress static files offline and minify CSS
# http://django-compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
COMPRESS_OFFLINE = True
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
]
COMPRESS_CSS_HASHING_METHOD = 'content'
LIBSASS_OUTPUT_STYLE = 'compressed'
LIBSASS_SOURCEMAPS = True
if 'STATIC_URL' in env:
STATIC_URL = env['STATIC_URL']
if 'STATIC_DIR' in env:
STATIC_ROOT = env['STATIC_DIR']
if 'MEDIA_URL' in env:
MEDIA_URL = env['MEDIA_URL']
if 'MEDIA_DIR' in env:
MEDIA_ROOT = env['MEDIA_DIR']
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = env['BUCKETEER_AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = env['BUCKETEER_AWS_SECRET_ACCESS_KEY']
AWS_STORAGE_BUCKET_NAME = env['BUCKETEER_BUCKET_NAME']
# Database
if 'DATABASE_URL' in os.environ:
DATABASES['default'] = dj_database_url.config()
DATABASES['default']['CONN_MAX_AGE'] = 500
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': env.get('PGDATABASE', APP_NAME),
'CONN_MAX_AGE': 600, # number of seconds database connections should persist for
# User, host and port can be configured by the PGUSER, PGHOST and
# PGPORT environment variables (these get picked up by libpq).
}
}
# Redis
# Redis location can either be passed through with REDIS_HOST or REDIS_SOCKET
if 'REDIS_URL' in env:
REDIS_LOCATION = env['REDIS_URL']
BROKER_URL = env['REDIS_URL']
elif 'REDIS_HOST' in env:
REDIS_LOCATION = env['REDIS_HOST']
BROKER_URL = 'redis://%s' % env['REDIS_HOST']
elif 'REDIS_SOCKET' in env:
REDIS_LOCATION = 'unix://%s' % env['REDIS_SOCKET']
BROKER_URL = 'redis+socket://%s' % env['REDIS_SOCKET']
else:
REDIS_LOCATION = None
if REDIS_LOCATION is not None:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': REDIS_LOCATION,
'KEY_PREFIX': APP_NAME,
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
'PASSWORD': env['REDIS_PASSWORD'],
}
}
}
# Elasticsearch
# if 'ELASTICSEARCH_URL' in env:
# WAGTAILSEARCH_BACKENDS = {
# 'default': {
# 'BACKEND': 'wagtail.search.backends.elasticsearch.ElasticSearch',
# 'URLS': [env['ELASTICSEARCH_URL']],
# 'INDEX': APP_NAME,
# 'ATOMIC_REBUILD': True,
# },
# }
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'ERROR'),
},
},
}
# Log errors to file
if 'ERROR_LOG' in env:
LOGGING['handlers']['errors_file'] = {
'level': 'ERROR',
'class': 'logging.handlers.RotatingFileHandler',
'filename': env['ERROR_LOG'],
'maxBytes': 5242880, # 5MB
'backupCount': 5
}
LOGGING['loggers']['django.request']['handlers'].append('errors_file')
LOGGING['loggers']['django.security']['handlers'].append('errors_file')
try:
from .local import *
except ImportError:
pass