/
fabfile.py
140 lines (99 loc) · 3.28 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
from fabric.api import *
from functools import wraps
import os, sys
__all__ = ['deploy', 'testing', 'run','collectstatic']
def patch_python_path(f):
@wraps(f)
def wrap(*args, **kwargs):
ROOT = os.pathsep.join([os.path.abspath(os.path.dirname(__file__))])
if not os.environ.has_key("PYTHONPATH"):
os.environ["PYTHONPATH"] = ""
if not (ROOT in os.environ["PYTHONPATH"].split(":")):
os.environ["PYTHONPATH"] = "%s:%s" % (os.environ["PYTHONPATH"], ROOT)
if not ROOT in sys.path:
sys.path.append(ROOT)
return f(*args, **kwargs)
return wrap
@patch_python_path
def deploy():
from tools.git import check_git_state, is_git_clean
from tools.database import needsdatabase, local_migrate, remote_migrate, remote_syncdb
from tools.apps import enumerate_apps
@check_git_state
@needsdatabase
def __deploy():
print "Deploying your application"
print "----------------------------"
print "Migrations..."
for app in enumerate_apps():
local_migrate(app)
if is_git_clean():
print "Pushing code on Heroku"
local("git push heroku master")
else:
print "Committing migrations..."
local("git add .")
local("git commit -a -m '[DHB] data migrations'")
print "Sync remote database"
remote_syncdb()
for app in ["djcelery"]:
with settings(warn_only=True):
print "Migrating %s ..." % app
local("heroku run python manage.py migrate %s --settings=settings.prod" % (app))
for app in enumerate_apps():
remote_migrate(app)
print "Transferring static files to S3"
collectstatic()
__deploy()
@patch_python_path
def testing():
from tools.git import check_git_state, is_git_clean
from tools.database import needsdatabase, local_migrate, testing_migrate, testing_syncdb
from tools.apps import enumerate_apps
@check_git_state
@needsdatabase
def __testing():
print "Deploying your application to testing server"
print "----------------------------"
print "Migrations..."
for app in enumerate_apps():
local_migrate(app)
if is_git_clean():
print "Pushing code on Heroku test server"
local("git push testing develop:master")
else:
print "Committing migrations..."
local("git add .")
local("git commit -a -m '[DHB] data migrations'")
print "Sync remote database"
testing_syncdb("nns-test-server")
for app in ["djcelery"]:
with settings(warn_only=True):
print "Migrating %s ..." % app
local("heroku run python manage.py schemamigration %s --auto --settings=settings.prod" % (app))
local("heroku run python manage.py migrate %s --settings=settings.prod" % (app))
for app in enumerate_apps():
testing_migrate(app)
print "Transferring static files to S3"
collectstatic()
__testing()
@patch_python_path
def run():
print sys.path
from tools.database import needsdatabase, local_migrate
from tools.apps import enumerate_apps
from tools.heroku import start_foreman
@needsdatabase
def __run():
for app in ["djcelery"]:
with settings(warn_only=True):
print "Migrating %s ..." % app
local("python manage.py migrate %s --settings=settings.dev" % (app))
for app in enumerate_apps():
with settings(warn_only=True):
local_migrate(app)
start_foreman()
__run()
@patch_python_path
def collectstatic():
local("python manage.py collectstatic --noinput --settings=settings.static")