-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfabfile.py
executable file
·70 lines (52 loc) · 1.56 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
from distutils.util import strtobool
from fabric.api import local, abort, run, sudo
from fabric.context_managers import cd, settings, hide, shell_env
from fabric.contrib.console import confirm
from getpass import getpass
from fabric.utils import puts
from fabric.state import env
env.control_dir = 'pipecontrol'
def with_sudo():
"""
Prompts and sets the sudo password for all following commands.
Use like
fab with_sudo command
"""
env.sudo_password = getpass('Please enter sudo password: ')
env.password = env.sudo_password
def down():
with cd(env.control_dir):
sudo('docker-compose down')
def get_branch(gitdir):
"""
Gets the branch of a git directory.
Args:
gitdir: path of the git directory
Returns: current active branch
"""
return local('git symbolic-ref --short HEAD', capture=True)
def pull():
with cd(env.control_dir):
puts(run('pwd'))
branch = get_branch(env.control_dir)
run('git reset --hard')
run('git clean -fd')
run('git pull')
run('git checkout {}'.format(branch))
run('git pull origin ' + branch)
def build():
with cd(env.control_dir):
sudo('docker-compose build pipecontrol')
def start():
with cd(env.control_dir):
sudo('docker-compose up -d pipecontrol')
def sync_files():
local('scp dj_local_conf.json ' + env.host_string + ':' + env.control_dir)
def deploy():
with settings(warn_only=True):
pull()
sync_files()
with_sudo()
down()
build()
start()