This repository has been archived by the owner on Jan 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
fabfile.py
124 lines (90 loc) · 2.95 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
from fabric.api import (env, execute, lcd, local, parallel,
run, roles, task)
from fabdeploytools import helpers
import fabdeploytools.envs
import deploysettings as settings
env.key_filename = settings.SSH_KEY
fabdeploytools.envs.loadenv(settings.CLUSTER)
SCL_NAME = getattr(settings, 'SCL_NAME', False)
if SCL_NAME:
helpers.scl_enable(SCL_NAME)
ROOT, WEBPAY = helpers.get_app_dirs(__file__)
VIRTUALENV = os.path.join(ROOT, 'venv')
PYTHON = os.path.join(VIRTUALENV, 'bin', 'python')
def managecmd(cmd):
with lcd(WEBPAY):
local('%s manage.py %s' % (PYTHON, cmd))
@task
def create_virtualenv():
helpers.create_venv(VIRTUALENV, settings.PYREPO,
'%s/requirements/prod.txt' % WEBPAY,
update_on_change=True, rm_first=True)
@task
def update_locales():
with lcd(os.path.join(WEBPAY, 'locale')):
local("./compile-mo.sh .")
@task
def update_info(ref='origin/master'):
helpers.git_info(WEBPAY)
with lcd(WEBPAY):
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):
run("/sbin/service %s restart" %
settings.CELERY_SERVICE)
@task
def deploy():
helpers.deploy(name='webpay',
env=settings.ENV,
cluster=settings.CLUSTER,
domain=settings.DOMAIN,
root=ROOT,
deploy_roles=['web', 'celery'],
package_dirs=['webpay', 'venv'])
helpers.restart_uwsgi(getattr(settings, 'UWSGI', []))
execute(update_celery)
@task
def pre_update(ref=settings.UPDATE_REF):
local('date')
execute(helpers.git_update, WEBPAY, ref)
execute(update_info, ref)
@task
def build():
execute(create_virtualenv)
execute(update_locales)
@task
def deploy_jenkins():
rpm = helpers.build_rpm(name='webpay',
env=settings.ENV,
cluster=settings.CLUSTER,
domain=settings.DOMAIN,
root=ROOT,
package_dirs=['webpay', 'venv'])
rpm.local_install()
rpm.remote_install(['web', 'celery'])
helpers.restart_uwsgi(getattr(settings, 'UWSGI', []))
execute(update_celery)
rpm.clean()
@task
def update():
execute(create_virtualenv)
execute(update_locales)
@task
def pre_update_latest_tag():
current_tag_file = os.path.join(WEBPAY, '.tag')
latest_tag = helpers.git_latest_tag(WEBPAY)
with open(current_tag_file, 'r+') as f:
if f.read() == latest_tag:
print 'Environemnt is at %s' % latest_tag
else:
pre_update(latest_tag)
f.seek(0)
f.write(latest_tag)
f.truncate()