forked from pld/bamboo
-
Notifications
You must be signed in to change notification settings - Fork 20
/
fabfile.py
71 lines (55 loc) · 2.15 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
import os
import sys
from fabric.api import env, run, cd
DEPLOYMENTS = {
'prod': {
'home': '/var/www/',
'host_string': '[email protected]',
'virtual_env': 'bamboo',
'repo_name': 'current',
'project': 'bamboo',
'docs': 'docs',
'branch': 'master',
'key_filename': os.path.expanduser('~/.ssh/modilabs.pem'),
'init_script': 'bamboo_uwsgi.sh',
'celeryd': 'celeryd',
}
}
def _run_in_virtualenv(command):
run('source ~/.virtualenvs/%s/bin/activate && %s' % (env.virtual_env,
command))
def _check_key_filename(deployment_name):
if 'key_filename' in DEPLOYMENTS[deployment_name] and \
not os.path.exists(DEPLOYMENTS[deployment_name]['key_filename']):
print 'Cannot find required permissions file: %s' % \
DEPLOYMENTS[deployment_name]['key_filename']
return False
return True
def _setup_env(deployment_name):
env.update(DEPLOYMENTS[deployment_name])
if not _check_key_filename(deployment_name):
sys.exit(1)
env.project_directory = os.path.join(env.home, env.project)
env.code_src = os.path.join(env.project_directory, env.repo_name)
env.doc_src = os.path.join(env.project_directory, env.repo_name, env.docs)
env.pip_requirements_file = os.path.join(
env.code_src, 'deploy/requirements/requirements.pip')
def deploy(deployment_name):
_setup_env(deployment_name)
# update code
with cd(env.code_src):
run('git fetch origin %(branch)s' % env)
run('git reset --hard origin/%(branch)s' % env)
run('git pull origin %(branch)s' % env)
run('find . -name "*.pyc" -delete')
# update docs
with cd(env.doc_src):
_run_in_virtualenv('make html')
# install dependencies
_run_in_virtualenv('pip install -r %s' % env.pip_requirements_file)
# restart celery
with cd(env.code_src):
_run_in_virtualenv('../shared/%s restart' % env.celeryd)
# restart the server
with cd(env.code_src):
_run_in_virtualenv('./scripts/%s restart' % env.init_script)