gault-millau/fabfile.py
Виктор Гладких 386e7d1bf8 First CI
2019-10-22 15:39:51 +03:00

76 lines
1.5 KiB
Python

import os # NOQA
from fabric.api import * # NOQA
user = 'gm'
env.root = '~/'
env.src = '~/project'
env.default_branch = 'feature/develop_ci'
env.tmpdir = '~/tmp'
env.roledefs = {
'develop': {
'branch': env.default_branch,
'hosts': ['%s@rock.spider.ru:31' % user, ]
},
'staging': {
'hosts': ['%s@5.200.53.99' % user, ]
},
'production': {
'branch': 'master',
'hosts': ['%s@87.226.166.80' % user, ]
}
}
def fetch(branch=None):
with cd(env.src):
role = env.roles[0]
run('git pull origin {}'.format(env.roledefs[role]['branch']))
run('git submodule update')
def migrate():
with cd(env.src):
run('./manage.py migrate')
def install_requirements():
with cd(env.src):
run('pip install -r requirements/base.txt')
def touch():
with cd(env.src):
run('touch ~/%s.touch' % user)
def kill_celery():
"""Kill celery workers for $user."""
with cd(env.src):
run('ps -u %s -o pid,fname | grep celery | (while read a b; do kill -9 $a; done;)' % user)
def collectstatic():
with cd(env.src):
run('./manage.py collectstatic --noinput')
def deploy(branch=None):
fetch()
install_requirements()
migrate()
collectstatic()
touch()
kill_celery()
def rev():
"""Show head commit."""
with hide('running', 'stdout'):
with cd(env.src):
commit = run('git rev-parse HEAD')
return local('git show -q %s' % commit)