-
Notifications
You must be signed in to change notification settings - Fork 4
/
fabfile.py
56 lines (47 loc) · 2.07 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
from __future__ import with_statement
from fabric.api import env, settings, local, run, cd, abort, prefix
from fabric.contrib.console import confirm
from fabric.exceptions import CommandTimeout
env.hosts = ['[email protected]']
def test():
with settings(warn_only=False):
result = local('"./manage.py" test')
if result.failed and not confirm("Tests failed. Continue anyway?"):
abort("Aborting at user request.")
def commit():
local("git add -p && git commit")
def push():
local("git push")
def prepare_deploy():
test()
commit()
push()
def deploy(state="unstable",app="web_api"):
stable = state == "stable"
branch = "master" if stable else "unstable"
environment = "server-" + ("stable" if stable else "unstable")
message = "Deploying branch %s to %s" % (branch, environment)
print "======================================================"
print ("== %s ==" % message.ljust(42))
print "======================================================"
code_dir = "/home/armadillo/%s" % environment
with cd(code_dir):
with prefix('WORKON_HOME=$HOME/.virtualenvs'):
with prefix('source /usr/local/bin/virtualenvwrapper.sh'):
with prefix('workon %s' % environment):
print "Updating remote code"
run("git pull origin %s" % branch)
print "Migrating database"
run("python manage.py migrate %s" % app)
print "Running tests"
run("python manage.py test")
print "Starting SMTP relay client"
try:
run("./smtp/client_server.sh", pty=False, timeout=2)
except CommandTimeout:
pass
print "Restarting web server"
run("touch armadillo_reuse/wsgi.py")
print "======================================================"
print "== All done! =="
print "======================================================"