forked from TracyWebTech/colab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
130 lines (91 loc) · 3.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from fabric.operations import put
from fabric.api import run, sudo, env
from fabric.contrib.files import exists
from fabric.decorators import with_settings
from fabric.context_managers import prefix, cd, settings
env.user = 'colab' # key depends on env
env.use_shell = False
environments = {
'dev': {
'hosts': ['127.0.0.1'],
'key_filename': '~/.vagrant.d/insecure_private_key',
'port': 2222,
},
'live': {
'hosts': ['10.1.2.153'],
'key_filename': '~/.ssh/id_rsa',
'port': 22,
},
'demo': {
'hosts': ['colab-demo.tracy.com.br'],
'key_filename': '~/.ssh/id_rsa',
'port': 22,
},
}
SOURCE_VENV = 'source /usr/local/bin/virtualenvwrapper.sh'
WORKON_COLAB = '{} && workon colab'.format(SOURCE_VENV)
def environment(name):
env.update(environments[name])
env.environment = name
environment('dev')
def mkvirtualenv():
if not exists('~/.virtualenvs/colab'):
with prefix(SOURCE_VENV):
run('mkvirtualenv colab')
return True
def install(local_settings=None):
env_created = mkvirtualenv()
if not exists('~/colab'):
run('git clone https://github.com/TracyWebTech/colab ~/colab')
if local_settings:
put(local_settings, '~/colab/src/colab/local_settings.py')
if not exists('~/apache-solr-3.6.2/'):
run('wget http://archive.apache.org/dist/lucene/solr/3.6.2/apache-solr-3.6.2.tgz')
run('tar xzf apache-solr-3.6.2.tgz')
run('rm apache-solr-3.6.2.tgz')
with cd('~/apache-solr-3.6.2/example/solr/conf/'):
if not exists('stopwords_en.txt'):
run('cp stopwords.txt stopwords_en.txt')
if env_created:
update_requirements()
sudo('supervisorctl reload', shell=False)
def update_requirements():
with cd('~/colab'), prefix(WORKON_COLAB):
run('pip install -U -r requirements.txt')
def deploy(update=False):
with cd('~/colab/src/'), prefix(WORKON_COLAB):
run('git pull')
if update:
update_requirements()
with cd('~/colab/src/'), prefix(WORKON_COLAB):
run('python manage.py syncdb')
run('python manage.py migrate')
run('python manage.py collectstatic --noinput')
run('python manage.py build_solr_schema -f ~/apache-solr-3.6.2/example/solr/conf/schema.xml')
sudo('supervisorctl restart all')
def rebuild_index(age=None, batch=None):
with cd('~/colab/src/'), prefix(WORKON_COLAB):
age_arg = ''
if age:
age_arg = '--age={}'.format(age)
batch_arg = ''
if batch:
batch_arg = '--batch-size={}'.format(batch)
run('python manage.py rebuild_index {} {}'.format(age_arg, batch_arg))
@with_settings(user='vagrant')
def build_solr_schema():
with cd('/vagrant/src/'), prefix(WORKON_COLAB):
run('python manage.py build_solr_schema -f /tmp/schema.xml')
with settings(user='colab'):
run('cp /tmp/schema.xml ~/apache-solr-3.6.2/example/solr/conf/schema.xml')
sudo('supervisorctl restart solr')
@with_settings(user='vagrant')
def runserver(update_requirements=False):
env_created = mkvirtualenv()
with cd('/vagrant/src/'), prefix(WORKON_COLAB):
# If explicitly called or if it's a new environment
if update_requirements or env_created:
run('pip install -r /vagrant/requirements.txt')
run('python manage.py syncdb')
run('python manage.py migrate')
run('python manage.py runserver 0.0.0.0:7000')