Permalink
Fetching contributors…
Cannot retrieve contributors at this time
125 lines (90 sloc) 2.95 KB
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()