-
Notifications
You must be signed in to change notification settings - Fork 14
/
fabfile.py
76 lines (57 loc) · 1.68 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
# -*- coding: utf-8 -*-
from fabric.api import cd, env, lcd, local, run, task
env.use_ssh_config = True
@task
def get_code_branch():
output = local('git branch', capture=True)
for line in output.splitlines():
if line[:2] == '* ':
return line[2:]
return 'master'
@task
def get_config_branch():
with lcd('private'):
output = local('git branch', capture=True)
for line in output.splitlines():
if line[:2] == '* ':
return line[2:]
return 'master'
@task
def update_code(branch='master'):
with cd('/data/doodle'):
run('git fetch --all')
run('git checkout ' + branch)
run('git reset --hard origin/' + branch)
@task
def update_config(branch='master'):
with cd('/data/doodle/private'):
run('git fetch --all')
run('git checkout ' + branch)
run('git reset --hard origin/' + branch)
@task
def build():
run('sudo pip install virtualenv')
with cd('/data/doodle'):
run('virtualenv .')
run('bin/pip install cython')
run('bin/pip install -r requirements.txt')
run('bin/python scripts/install.py')
@task
def restart():
run('supervisorctl restart doodle:')
run('sudo nginx -s reload')
@task(default=True)
def fast_deploy():
code_branch = get_code_branch()
print('deploying %s code branch' % code_branch)
update_code(code_branch)
restart()
@task()
def deploy():
code_branch = get_code_branch()
config_branch = get_config_branch()
print('deploying %s code branch and %s config branch' % (code_branch, config_branch))
update_code(code_branch)
update_config(config_branch)
build()
restart()