forked from mozilla/addon-registration
/
fabfile.py
79 lines (58 loc) · 2.02 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
import os
from os.path import join as pjoin
from fabric.api import (env, execute, lcd, local, parallel,
run, roles, task)
from fabdeploytools.rpm import RPMBuild
from fabdeploytools import helpers
import fabdeploytools.envs
import deploysettings as settings
env.key_filename = settings.SSH_KEY
fabdeploytools.envs.loadenv(settings.CLUSTER)
ROOT, ADDON_REGISTRATION = helpers.get_app_dirs(__file__)
VIRTUALENV = os.path.join(ROOT, 'venv')
PYTHON = os.path.join(VIRTUALENV, 'bin', 'python')
@task
def create_virtualenv(update_on_change=False):
helpers.create_venv(VIRTUALENV, settings.PYREPO,
pjoin(ADDON_REGISTRATION, 'requirements/prod.txt'),
update_on_change=update_on_change)
@task
def setup_install():
with lcd(ADDON_REGISTRATION):
local("%s setup.py install" % PYTHON)
@task
def update_info(ref='origin/master'):
helpers.git_info(ADDON_REGISTRATION)
with lcd(ADDON_REGISTRATION):
local("/bin/bash -c "
"'source /etc/bash_completion.d/git && __git_ps1'")
local('git show -s {0} --pretty="format:%h" '
'> media/git-rev.txt'.format(ref))
@task
@roles('celery')
@parallel
def update_celery():
if getattr(settings, 'CELERY_SERVICE', False):
restart = 'supervisorctl restart %s' % settings.CELERY_SERVICE
if restarts:
run(restart)
@task
def deploy():
helpers.deploy(name='addon_registration',
env=settings.ENV,
cluster=settings.CLUSTER,
domain=settings.DOMAIN,
root=ROOT,
deploy_roles=['web', 'celery'],
package_dirs=['addon_registration', 'venv'])
helpers.restart_uwsgi(getattr(settings, 'UWSGI', []))
execute(update_celery)
@task
def pre_update(ref=settings.UPDATE_REF):
local('date')
execute(helpers.git_update, ADDON_REGISTRATION, ref)
execute(update_info, ref)
@task
def update():
execute(create_virtualenv)
execute(setup_install)