-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
163 lines (126 loc) · 4.3 KB
/
fabfile.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
"""Management utilities."""
from fabric.contrib.console import confirm
from fabric.api import abort, env, local, settings, task
########## GLOBALS
env.run = 'heroku run python manage.py'
HEROKU_ADDONS = (
'cloudamqp:lemur',
'heroku-postgresql:dev',
'scheduler:standard',
'memcachier:dev',
'newrelic:standard',
'pgbackups:auto-month',
'sentry:developer',
)
HEROKU_CONFIGS = (
'DJANGO_SETTINGS_MODULE=redcaptainhook.settings.prod',
'SECRET_KEY=&=3d_$7!_cy9jbv((ir!%)u+lrj%-sc1nd&rtv*+bbvmfj$y-1'
'AWS_ACCESS_KEY_ID=xxx',
'AWS_SECRET_ACCESS_KEY=xxx',
'AWS_STORAGE_BUCKET_NAME=xxx',
)
RCH_CONFIGS = (
'RCH_PROD_DB_HOST',
'RCH_PROD_DB_PASS',
'RCH_PROD_DB_USER',
'RCH_PROD_DB_PORT',
'RCH_PROD_DB_NAME',
'RCH_PROD_BROKER_URL',
'SECRET_KEY',
'EMAIL_HOST',
'EMAIL_HOST_PASSWORD',
'EMAIL_HOST_USER',
'RCH_PROD_BASE_DOMAIN',
)
########## END GLOBALS
########## HELPERS
def cont(cmd, message):
"""Given a command, ``cmd``, and a message, ``message``, allow a user to
either continue or break execution if errors occur while executing ``cmd``.
:param str cmd: The command to execute on the local system.
:param str message: The message to display to the user on failure.
.. note::
``message`` should be phrased in the form of a question, as if ``cmd``'s
execution fails, we'll ask the user to press 'y' or 'n' to continue or
cancel exeuction, respectively.
Usage::
cont('heroku run ...', "Couldn't complete %s. Continue anyway?" % cmd)
"""
with settings(warn_only=True):
result = local(cmd, capture=True)
if message and result.failed and not confirm(message):
abort('Stopped execution per user request.')
########## END HELPERS
########## DATABASE MANAGEMENT
@task
def syncdb():
"""Run a syncdb."""
local('%(run)s syncdb --noinput' % env)
@task
def migrate(app=None):
"""Apply one (or more) migrations. If no app is specified, fabric will
attempt to run a site-wide migration.
:param str app: Django app name to migrate.
"""
if app:
local('%s migrate %s --noinput' % (env.run, app))
else:
local('%(run)s migrate --noinput' % env)
########## END DATABASE MANAGEMENT
########## FILE MANAGEMENT
@task
def collectstatic():
"""Collect all static files, and copy them to S3 for production usage."""
local('%(run)s collectstatic --noinput' % env)
########## END FILE MANAGEMENT
########## HEROKU MANAGEMENT
@task
def bootstrap():
"""Bootstrap your new application with Heroku, preparing it for a production
deployment. This will:
- Create a new Heroku application.
- Install all ``HEROKU_ADDONS``.
- Sync the database.
- Apply all database migrations.
- Initialize New Relic's monitoring add-on.
"""
cont('heroku create', "Couldn't create the Heroku app, continue anyway?")
for addon in HEROKU_ADDONS:
cont('heroku addons:add %s' % addon,
"Couldn't add %s to your Heroku app, continue anyway?" % addon)
for config in HEROKU_CONFIGS:
cont('heroku config:add %s' % config,
"Couldn't add %s to your Heroku app, continue anyway?" % config)
cont('git push heroku master',
"Couldn't push your application to Heroku, continue anyway?")
syncdb()
migrate()
cont('%(run)s newrelic-admin validate-config - stdout' % env,
"Couldn't initialize New Relic, continue anyway?")
@task
def destroy():
"""Destroy this Heroku application. Wipe it from existance.
.. note::
This really will completely destroy your application. Think twice.
"""
local('heroku apps:destroy')
@task
def heroku_sync_config():
"""Sync specific envars
"""
config_cmd = 'heroku config:set %s' % ' '.join(['%s=$%s' % (k, k) for k in RCH_CONFIGS])
local(config_cmd)
########## END HEROKU MANAGEMENT
########## DJANGO HELPERS
@task
def startapp(app):
app_dir = 'redcaptainhook/apps/%s' % app
local('mkdir %s' % app_dir)
local('python manage.py startapp %s %s' % (app, app_dir))
@task
def load():
local("python manage.py loaddata redcaptainhook/apps/workflow/fixtures/{project,trigger,process}.json")
@task
def test():
local("python manage.py test main workflow")
########## END DJANGO HELPERS