forked from nprapps/carebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_config.py
167 lines (137 loc) · 4.23 KB
/
app_config.py
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
#!/usr/bin/env python
"""
Project-wide application configuration.
DO NOT STORE SECRETS, PASSWORDS, ETC. IN THIS FILE.
They will be exposed to users. Use environment variables instead.
See get_secrets() below for a fast way to access them.
"""
import os
"""
NAMES
"""
# Project name to be used in urls
# Use dashes, not underscores!
PROJECT_SLUG = 'carebot'
# Project name to be used in file paths
PROJECT_FILENAME = 'carebot'
# The name of the repository containing the source
REPOSITORY_NAME = 'carebot'
GITHUB_USERNAME = 'nprapps'
REPOSITORY_URL = '[email protected]:%s/%s.git' % (GITHUB_USERNAME, REPOSITORY_NAME)
REPOSITORY_ALT_URL = None # '[email protected]:nprapps/%s.git' % REPOSITORY_NAME'
# Project name used for assets rig
# Should stay the same, even if PROJECT_SLUG changes
ASSETS_SLUG = 'carebot'
"""
DEPLOYMENT
"""
PRODUCTION_SERVERS = ['cron.nprapps.org']
STAGING_SERVERS = ['cron-staging.nprapps.org']
# Should code be deployed to the web/cron servers?
DEPLOY_TO_SERVERS = True
SERVER_USER = 'ubuntu'
SERVER_PYTHON = 'python2.7'
SERVER_PROJECT_PATH = '/home/%s/apps/%s' % (SERVER_USER, PROJECT_FILENAME)
SERVER_REPOSITORY_PATH = '%s/repository' % SERVER_PROJECT_PATH
SERVER_VIRTUALENV_PATH = '%s/virtualenv' % SERVER_PROJECT_PATH
# Should the crontab file be installed on the servers?
# If True, DEPLOY_TO_SERVERS must also be True
DEPLOY_CRONTAB = True
# Should the service configurations be installed on the servers?
# If True, DEPLOY_TO_SERVERS must also be True
DEPLOY_SERVICES = True
UWSGI_SOCKET_PATH = '/tmp/%s.uwsgi.sock' % PROJECT_FILENAME
# Services are the server-side services we want to enable and configure.
# A three-tuple following this format:
# (service name, service deployment path, service config file extension)
SERVER_SERVICES = [
('app', SERVER_REPOSITORY_PATH, 'ini'),
('uwsgi', '/etc/init', 'conf'),
('nginx', '/etc/nginx/locations-enabled', 'conf'),
]
# These variables will be set at runtime. See configure_targets() below
SERVERS = []
SERVER_BASE_URL = None
SERVER_LOG_PATH = None
DEBUG = True
SES_REGION = 'us-east-1'
PROJECT_TYPES = [
('app', 'App'),
('seamus-graphic', 'Seamus Graphic'),
('lookatthis-post', 'Look At This Post')
]
DEFAULT_QUERIES = [
'totals',
'sessions-by-device-category',
'sessions-by-browser',
'sessions-by-referring-domain',
'sessions-by-referring-social-network',
'performance',
'time-spent-on-page-by-device-category'
]
DEFAULT_EVENT_QUERIES = [
'share-discuss-panel-opened',
'tweet-link-clicked',
'facebook-share-link-clicked',
'email-link-clicked',
'summary-copied'
]
DEFAULT_REPORT_NDAYS = [
1,
7,
30
]
EMAIL_SEND_ADDRESS = '[email protected]'
EMAIL_NOTIFY_ADDRESS = '[email protected]'
"""
Utilities
"""
def get_secrets():
"""
A method for accessing our secrets.
"""
secrets = [
'POSTGRES_USER',
'POSTGRES_PASSWORD',
'POSTGRES_HOST',
'POSTGRES_PORT',
'SHAREDCOUNT_API_KEY',
'GECKOBOARD_API_KEY'
]
secrets_dict = {}
for secret in secrets:
name = '%s_%s' % (PROJECT_FILENAME, secret)
secrets_dict[secret] = os.environ.get(name, None)
return secrets_dict
def configure_targets(deployment_target):
"""
Configure deployment targets. Abstracted so this can be
overriden for rendering before deployment.
"""
global SERVERS
global SERVER_BASE_URL
global SERVER_LOG_PATH
global DEBUG
global DEPLOYMENT_TARGET
global DISQUS_SHORTNAME
if deployment_target == 'production':
SERVERS = PRODUCTION_SERVERS
SERVER_BASE_URL = 'http://%s/%s' % (SERVERS[0], PROJECT_SLUG)
SERVER_LOG_PATH = '/var/log/%s' % PROJECT_FILENAME
DEBUG = False
elif deployment_target == 'staging':
SERVERS = STAGING_SERVERS
SERVER_BASE_URL = 'http://%s/%s' % (SERVERS[0], PROJECT_SLUG)
SERVER_LOG_PATH = '/var/log/%s' % PROJECT_FILENAME
DEBUG = True
else:
SERVERS = []
SERVER_BASE_URL = 'http://127.0.0.1:8001/%s' % PROJECT_SLUG
SERVER_LOG_PATH = '/tmp'
DEBUG = True
DEPLOYMENT_TARGET = deployment_target
"""
Run automated configuration
"""
DEPLOYMENT_TARGET = os.environ.get('DEPLOYMENT_TARGET', None)
configure_targets(DEPLOYMENT_TARGET)