-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
106 lines (77 loc) · 1.93 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
import os
from fabric import api
DEFAULT_BRANCH = 'master'
DEFAULT_SERVICE = 'nginx'
REPO = '[email protected]:learnpython/web-02.git'
PROJECT_DIR = '/Users/playpauseandstop/Projects/learnpython-web-02'
def bootstrap():
"""
Bootstrap project on remote server.
"""
with api.cd(PROJECT_DIR):
api.run('make bootstrap')
api.run('make syncdb')
def commit():
"""
Commit changed files if any.
"""
with api.settings(warn_only=True):
api.local('git add -i && git commit')
def deploy(branch=None):
"""
Run full deploy process.
"""
pre_deploy(branch)
init()
pull(branch)
bootstrap()
restart()
post_deploy()
def init():
"""
Initialize project dir on remote host.
"""
parent = os.path.abspath(os.path.join(PROJECT_DIR, '..'))
api.run('[ ! -d "{0}" ] && mkdir "{0}" || :'.format(parent))
api.run('[ ! -d "{0}" ] && git clone {1} "{0}" || :'.
format(PROJECT_DIR, REPO))
with api.cd(PROJECT_DIR):
api.run('make createdb')
def pre_deploy(branch=None):
"""
Prepare code deployment.
"""
test()
commit()
push(branch)
def post_deploy():
"""
Code to run after successful deployment.
"""
def pull(branch=None):
"""
Pull fresh changes on remote server.
"""
with api.cd(PROJECT_DIR):
api.run('git pull origin {0}'.format(branch or DEFAULT_BRANCH))
def push(branch=None):
"""
Push commited files to remote repo.
"""
api.local('git push origin {0}'.format(branch or DEFAULT_BRANCH))
def restart(service=None):
"""
Restart service on remote server.
"""
api.sudo('service {0} restart'.format(service or DEFAULT_SERVICE))
def syncdb():
"""
Run syncdb and migrate commands on remote server.
"""
with api.cd(PROJECT_DIR):
api.run('make syncdb')
def test():
"""
Run project tests.
"""
api.local('make test')