forked from SEL-Columbia/formhub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
64 lines (55 loc) · 2.38 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
import os, sys
from fabric.api import env, run, cd
from fabric.decorators import hosts
DEFAULTS = {
'home': '/home/fhuser/',
'repo_name': 'formhub',
}
DEPLOYMENTS = { # why are these here, in a publically-posted file??
'dev': {
'home': '/home/ubuntu/srv/',
'host_string': '[email protected]', # TODO: switch to dev.formhub.org
'project': 'formhub-ec2',
'key_filename': os.path.expanduser('~/.ssh/modilabs.pem'),
},
'prod': {
'home': '/home/ubuntu/srv/',
'host_string': '[email protected]',
'project': 'formhub-ec2',
'key_filename': os.path.expanduser('~/.ssh/modilabs.pem'),
},
}
def check_key_filename(deployment_name):
if DEPLOYMENTS[deployment_name].has_key('key_filename') 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(DEFAULTS)
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.wsgi_config_file = os.path.join(env.project_directory, 'formhub', 'wsgi.py')
env.pip_requirements_file = os.path.join(env.code_src, 'requirements.pip')
def deploy(deployment_name, branch='master'):
setup_env(deployment_name)
with cd(env.code_src):
run("git fetch origin")
run("git checkout origin/%s" % branch)
run("git submodule init")
run("git submodule update")
run('find . -name "*.pyc" -exec rm -rf {} \;')
# numpy pip install from requirments file fails
run("sudo pip install numpy --upgrade")
run("sudo pip install -r %s --upgrade" % env.pip_requirements_file)
with cd(env.code_src):
run("python manage.py syncdb --settings='formhub.preset.default_settings'")
run("python manage.py migrate --settings='formhub.preset.default_settings'")
run("python manage.py collectstatic --settings='formhub.preset.default_settings' --noinput")
run("sudo /etc/init.d/celeryd restart")
run("sudo /etc/init.d/celerybeat restart")
run("sudo /etc/init.d/formhub-uwsgi restart")
run("sudo /etc/init.d/nginx restart")