-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
128 lines (91 loc) · 3.64 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
from fabric.api import *
# === Environments ===
def development():
env.env = 'development'
env.settings = 'settings.local'
def staging():
env.env = 'staging'
env.settings = 'settings.staging'
env.remote = 'staging'
env.heroku_app = 'staging'
def production():
env.env = 'production'
env.settings = 'settings.production'
env.remote = 'production'
env.heroku_app = 'resident-advisor'
# Default Environment
development()
# === Deployment ===
def start_hotfix(name):
local('git checkout -b hotfix-{name}'.format(name=name))
def close_hotfix(name):
local('git checkout master')
local('git merge --no-ff hotfix-{name}'.format(name=name))
local('git checkout develop')
local('git merge --no-ff hotfix-{name}'.format(name=name))
local('git branch -d hotfix-{name}'.format(name=name))
# === Deployment ===
def deploy():
local('git push origin --all')
local('git push {remote}'.format(**env))
migrate()
collectstatic()
local('heroku open --app {heroku_app}'.format(**env))
def collectstatic():
if raw_input('\nDo you really want to COLLECT STATIC of {heroku_app}? YES or [NO]: '.format(**env)) == 'YES':
local('heroku run python manage.py collectstatic --settings={settings} --app {heroku_app}'.format(**env))
else:
print '\nCOLLECT STATIC aborted'
def open():
if env.env == 'development':
local('/usr/bin/open \'http://127.0.0.1:8000/\'')
local('python manage.py runserver')
else:
local('heroku open --app {heroku_app}'.format(**env))
# === DB ===
def resetdb():
if env.env == 'development':
local('python manage.py syncdb --settings={settings}'.format(**env))
local('python manage.py migrate --settings={settings}'.format(**env))
else:
if raw_input('\nDo you really want to RESET DATABASE of {heroku_app}? YES or [NO]: '.format(**env)) == 'YES':
local('heroku run python manage.py syncdb --settings={settings} --app {heroku_app}'.format(
**env))
local('heroku run python manage.py migrate --settings={settings} --app {heroku_app}'.format(**env))
else:
print '\nRESET DATABASE aborted'
def schemamigration(app_names):
local('python manage.py schemamigration {} --auto --settings={settings}'.format(app_names, **env))
def migrate():
if env.env == 'development':
local('python manage.py migrate --settings={settings}'.format(**env))
else:
if raw_input('\nDo you really want to MIGRATE DATABASE of {heroku_app}? YES or [NO]: '.format(**env)) == 'YES':
local('heroku run python manage.py migrate --settings={settings} --app {heroku_app}'.format(**env))
else:
print '\nMIGRATE DATABASE aborted'
def updatedb(app_names):
schemamigration(app_names)
migrate()
# === Heroku ===
def ps():
local('heroku ps --app {heroku_app}'.format(**env))
def restart():
if raw_input('\nDo you really want to RESTART (web/worker) {heroku_app}? YES or [NO]: '.format(**env)) == 'YES':
local('heroku ps:restart web --app {heroku_app}'.format(**env))
else:
print '\nRESTART aborted'
def tail():
local('heroku logs --tail --app {heroku_app}'.format(**env))
def shell():
if env.env == 'development':
local('python manage.py shell --settings={settings}'.format(**env))
else:
local('heroku run bash --app {heroku_app}'.format(**env))
def config():
local('heroku config --app {heroku_app}'.format(**env))
def set(key=None, value=None):
if key and value:
local('heroku config:add {}={} --app {heroku_app}'.format(key, value, **env))
else:
print '\nErr!'