This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
/
fabfile.py
74 lines (50 loc) · 1.54 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
from fabric.api import env, task, run, local, require, cd
from gitric.api import ( # noqa
git_seed, git_reset, git_init, git_head_rev, allow_dirty, force_push
)
from fabvenv import virtualenv, make_virtualenv
env.use_ssh_config = True
@task
def prod():
'''an example production deployment'''
env.hosts = ['welt2000']
env.repo_path = '/home/welt2000/src'
env.venv_path = '/home/welt2000/venv'
@task
def test():
""" run the unit test suite """
local('py.test')
@task
def init():
""" initialize the virtualenv and git repo on the server """
require('repo_path', 'venv_path')
# Create the virtualenv
make_virtualenv(env.venv_path, system_site_packages=False)
# Create the git repo
git_init(env.repo_path)
@task
def deploy():
""" deploy the app to the server """
require('repo_path', 'venv_path')
commit = git_head_rev()
# Run the test suite first !
test()
# Update the new code
git_seed(env.repo_path, commit=commit)
# Activate the new code
git_reset(env.repo_path, commit=commit)
with cd(env.repo_path), virtualenv(env.venv_path):
run('pip install -r requirements-prod.txt')
restart()
@task
def clean():
run('rm -rf /home/welt2000/src')
run('rm -rf /home/welt2000/venv')
def supervisor_run(cmd):
run("supervisorctl {}".format(cmd), shell=False)
@task
def restart():
""" Restart supervisor service and view some output of log file """
supervisor_run("restart welt2000")
run("sleep 1")
supervisor_run("tail welt2000")