Migrate secrets to environment variables
[oweals/karmaworld.git] / karmaworld / settings / prod.py
1 #!/usr/bin/env python
2 # -*- coding:utf8 -*-
3 # Copyright (C) 2012  FinalsClub Foundation
4 """ Production settings and globals. """
5 from os import environ
6 from datetime import timedelta
7 from S3 import CallingFormat
8
9 from common import *
10
11 try:
12     # Include email is settings are there
13     SMTP_HOST = os.environ['SMTP_HOST']
14     SMTP_USERNAME = os.environ['SMTP_USERNAME']
15     SMTP_PASSWORD = os.environ['SMTP_PASSWORD']
16     EMAIL = True
17 except:
18     EMAIL = False
19
20 ########## EMAIL CONFIGURATION
21 if EMAIL:
22     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
23     EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
24     
25     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host
26     EMAIL_HOST = environ.get('EMAIL_HOST', SMTP_HOST)
27     
28     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
29     EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', SMTP_PASSWORD)
30     
31     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
32     EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', SMTP_USERNAME)
33     
34     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port
35     EMAIL_PORT = environ.get('EMAIL_PORT', 587)
36     
37     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
38     EMAIL_SUBJECT_PREFIX = 'KarmaNotes '
39     
40     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
41     EMAIL_USE_TLS = True
42     
43     DEFAULT_FROM_EMAIL = 'info@karmanotes.org'
44     
45     # See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
46     SERVER_EMAIL = EMAIL_HOST_USER
47 ########## END EMAIL CONFIGURATION
48
49
50 ########## CACHE CONFIGURATION
51 # See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
52 CACHES = {
53     'default': {
54         'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
55         'LOCATION': '127.0.0.1:11211'
56     }
57 }
58 ########## END CACHE CONFIGURATION
59
60
61 ########## CELERY CONFIGURATION
62 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-transport
63 BROKER_TRANSPORT = 'amqplib'
64
65 # Set this number to the amount of allowed concurrent connections on your AMQP
66 # provider, divided by the amount of active workers you have.
67 #
68 # For example, if you have the 'Little Lemur' CloudAMQP plan (their free tier),
69 # they allow 3 concurrent connections. So if you run a single worker, you'd
70 # want this number to be 3. If you had 3 workers running, you'd lower this
71 # number to 1, since 3 workers each maintaining one open connection = 3
72 # connections total.
73 #
74 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-pool-limit
75 BROKER_POOL_LIMIT = 3
76
77 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries
78 BROKER_CONNECTION_MAX_RETRIES = 0
79
80 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url
81 BROKER_URL = environ.get('RABBITMQ_URL') or environ.get('CLOUDAMQP_URL')
82
83 # See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend
84 CELERY_RESULT_BACKEND = 'amqp'
85
86 # Periodic tasks
87 CELERYBEAT_SCHEDULE = {
88     'tweet-about-notes': {
89         'task': 'tweet_note',
90         'schedule': timedelta(minutes=60),
91     },
92     'check-mturk-results': {
93         'task': 'get_extract_keywords_results',
94         'schedule': timedelta(minutes=20),
95     },
96 }
97
98 CELERY_TIMEZONE = 'UTC'
99
100 ########## END CELERY CONFIGURATION
101
102
103 ########## STORAGE CONFIGURATION
104 # See: http://django-storages.readthedocs.org/en/latest/index.html
105 INSTALLED_APPS += (
106     'storages',
107     'gunicorn',
108 )
109
110 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
111 # DEFAULT_FILE_STORAGE comes from karmaworld.secret.static_s3
112 STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
113
114 # Put static files in the folder 'static' in our S3 bucket.
115 # This is so they have the same path as they do when served
116 # locally for development.
117 AWS_LOCATION = 'static'
118
119 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
120 AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN
121
122 # AWS cache settings, don't change unless you know what you're doing:
123 AWS_EXPIREY = 60 * 60 * 24 * 7
124 AWS_HEADERS = {
125     'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
126         AWS_EXPIREY)
127 }
128
129 # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
130 # S3_URL comes from karmaworld.secret.static_s3
131 STATIC_URL = os.environ.get('CLOUDFRONT_URL') + AWS_LOCATION + '/'
132 ########## END STORAGE CONFIGURATION
133
134 ########## SSL FORWARDING CONFIGURATION
135 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
136 ########## END SSL FORWARDING CONFIGURATION
137
138 ########## COMPRESSION CONFIGURATION
139 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
140 COMPRESS_OFFLINE = True
141
142 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
143 COMPRESS_STORAGE = os.environ.get('DEFAULT_FILE_STORAGE')
144
145 # Make sure that django-compressor serves from CloudFront
146 AWS_S3_CUSTOM_DOMAIN = os.environ.get('CLOUDFRONT_DOMAIN')
147
148 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
149 COMPRESS_CSS_FILTERS += [
150     'compressor.filters.datauri.CssDataUriFilter',
151     'compressor.filters.cssmin.CSSMinFilter',
152 ]
153 COMPRESS_DATA_URI_MAX_SIZE = 5120
154
155 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
156 COMPRESS_JS_FILTERS += [
157     'compressor.filters.closure.ClosureCompilerFilter',
158 ]
159 COMPRESS_CLOSURE_COMPILER_BINARY = 'java -jar /usr/bin/compiler.jar'
160
161 # Links generated by compress are valid for about ten years
162 AWS_QUERYSTRING_EXPIRE = 60 * 60 * 24 * 365 * 10
163 ########## END COMPRESSION CONFIGURATION
164
165
166 ########## SECRET CONFIGURATION
167 # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
168 SECRET_KEY = environ.get('SECRET_KEY', SECRET_KEY)
169 ########## END SECRET CONFIGURATION