forked from mvpdev/xls2xform
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
76 lines (63 loc) · 2.42 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
import os
from fabric.api import *
from fabric.contrib import files, console
from fabric import utils
from fabric.decorators import hosts
from datetime import datetime
env.home = '/home/wsgi/srv/'
env.project = 'xls2xform'
HOST_INFO = ["[email protected]"]
DEPLOYMENTS = {
'alpha': {
'project': 'xls2xform',
'branch': 'develop',
'pyxform_branch': 'develop',
},
'prod': {
'project': 'xls2xform_production',
'branch': 'master',
'pyxform_branch': 'develop',
}
}
@hosts(HOST_INFO)
def deploy(deployment_name="alpha"):
"""
TODO: figure out how to best use "@hosts" decorator.
"""
setup_env(deployment_name)
pull_from_origin()
install_requirements()
remove_old_pyxform()
with cd(env.code_src):
# run_in_virtualenv("pip install -e ")
run_in_virtualenv("python manage.py migrate")
run_in_virtualenv("python manage.py collectstatic --noinput")
restart_wsgi()
@hosts(HOST_INFO)
def install_requirements():
run_in_virtualenv("pip install -r %s" % env.pip_requirements_file)
def remove_old_pyxform():
# remove the old pyxform from the virtualenvironment
with cd(env.ve_src_dir):
run("rm -rf pyxform")
# replace with the branch specified in deployment settings
run_in_virtualenv("pip install -e git://github.com/mvpdev/pyxform.git@%s#egg=pyxform" % env.pyxform_branch)
def setup_env(deployment_name):
env.project_directory = os.path.join(env.home, DEPLOYMENTS[deployment_name]['project'])
env.code_src = os.path.join(env.project_directory, env.project)
env.branch = DEPLOYMENTS[deployment_name]['branch']
env.pyxform_branch = DEPLOYMENTS[deployment_name]['pyxform_branch']
env.virtualenv_activate_script = "source %s" % os.path.join(env.project_directory, 'project_env', 'bin', 'activate')
env.ve_src_dir = os.path.join(env.project_directory, 'project_env', 'src')
env.wsgi_config_file = os.path.join(env.project_directory, 'apache', 'environment.wsgi')
env.pip_requirements_file = os.path.join(env.code_src, 'requirements.pip')
def pull_from_origin():
with cd(env.code_src):
run("git pull origin %(branch)s" % env)
def run_in_virtualenv(command):
run(env.virtualenv_activate_script + ' && ' + command)
def migrate():
with cd(env.code_src):
run_in_virtualenv("python manage.py migrate")
def restart_wsgi():
run('touch %s' % env.wsgi_config_file)