forked from inspirehep/inspire-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
169 lines (135 loc) · 5.91 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# -*- coding: utf-8 -*-
"""Deployment of INSPIRE Labs."""
import json
from fabric.api import *
from fabric.utils import error
from fabric.contrib.files import exists
env.directory = '/opt' # remote directory
env.conf_directory = "/afs/cern.ch/project/inspire/repo/inspire-configuration.git"
env.roledefs = {
'prod': ['inspirelabsvm01'],
'dev01': ['inspirevm08.cern.ch'],
'dev02': ['inspirevm11.cern.ch'],
}
@task
def prod():
"""Activate configuration for INSPIRE PROD server."""
env.roles = ['prod']
env.site_url = "http://inspirelabsvm01.cern.ch"
env.site_secure_url = "https://inspirelabsvm01.cern.ch"
env.conf_branch = "prod"
@task
def vm08():
"""Activate configuration for INSPIRE DEV server."""
env.roles = ['dev01']
env.site_url = "http://inspirelabstest.cern.ch"
env.site_secure_url = "https://inspirelabstest.cern.ch"
env.conf_branch = "dev"
@task
def vm11():
"""Activate configuration for INSPIRE DEV server."""
env.roles = ['dev02']
env.site_url = "http://inspirevm11.cern.ch"
env.site_secure_url = "https://inspirevm11.cern.ch"
@task
def pack():
"""Create a new source distribution as tarball."""
with open(".bowerrc") as fp:
bower = json.load(fp)
choice = prompt("Clean and reinstall local assets? (y/N)", default="no")
if choice.lower() in ["y", "ye", "yes"]:
clean_assets()
local("inveniomanage assets build --directory {directory}/../gen"
.format(**bower))
return local("python setup.py sdist --formats=gztar", capture=False) \
.succeeded
@task
def create_virtualenv():
"""Create the virtualenv."""
package = local("python setup.py --fullname", capture=True).strip()
pythonpath = "/opt/rh/python27/root/usr/bin/python"
with cd(env.directory):
if exists(package):
return error("This version {0} is already installed."
.format(package))
with settings(sudo_user="invenio"):
return sudo("virtualenv {0} --python={1}".format(package, pythonpath)).succeeded
@task
def install():
"""Install package."""
package = local("python setup.py --fullname", capture=True).strip()
venv = "{0}/{1}".format(env.directory, package)
if not exists(venv):
return error("Meh? I need a virtualenv first.")
success = 1
# Upload the package and put it into our virtualenv.
put("dist/{0}.tar.gz".format(package), "/tmp/app.tgz")
with settings(sudo_user="invenio"):
sudo("mkdir -p {0}/src".format(venv))
with cd("{0}/src".format(venv)):
sudo("tar xzf /tmp/app.tgz")
run("rm -rf /tmp/app.tgz")
# Jump into the virtualenv and install stuff
with cd("{0}/src/{1}".format(venv, package)):
with prefix('source {0}/bin/activate'.format(venv)):
sudo("pip install Babel")
sudo("pip install numpy")
sudo("pip install git+git://github.com/mrjoes/flask-admin.git#egg=Flask-Admin-1.0.9.dev0")
success = sudo("python setup.py install")
if success:
# INSPIRE specific configuration
with cd(env.conf_directory):
config_location = "/tmp/inspire-configuration"
sudo("mkdir -p {0}".format(config_location))
sudo("GIT_WORK_TREE={0} git checkout -f {1}".format(config_location, env.conf_branch))
sudo("pip install {0} --upgrade".format(config_location))
# post install
sudo("inveniomanage collect")
with warn_only():
# Compile base Invenio translatation to avoid translation error
prefix_folder = sudo('python -c "import invenio; print(invenio.__path__[0])"')
prefix_folder = prefix_folder.split("\n")
sudo("pybabel compile -fd {0}/base/translations".format(prefix_folder[-1]))
# Set Flask Host configuration
sudo("inveniomanage config set CFG_SITE_URL {0}".format(env.site_url))
sudo("inveniomanage config set CFG_SITE_SECURE_URL {0}".format(env.site_secure_url))
# Create Apache configuration
sudo("inveniomanage apache create-config")
sudo("rm /opt/invenio")
sudo("ln -s {0} /opt/invenio".format(venv))
with cd("{0}/var".format(venv)):
sudo("mkdir -p log/bibsched")
sudo("chown -R invenio.invenio log/bibsched")
if success:
sudo("supervisorctl restart celeryd")
return success
@task
def restart_celery():
"""Restart celery workers."""
return sudo("supervisorctl restart celeryd")
@task
def restart_apache():
"""Restart celery workers."""
return sudo("service httpd restart")
@task
def clean_assets():
"""Helper to ensure all assets are up to date."""
local("rm -rf $VIRTUAL_ENV/var/invenio.base-instance/static/")
local("rm -rf inspire/base/static/gen/")
local("rm -rf inspire/base/static/vendors/")
local("inveniomanage bower -i bower-base.json > bower.json")
local("bower install")
local("inveniomanage collect")
@task
def compile_translations():
"""Compile the Invenio translations."""
package = local("python setup.py --fullname", capture=True).strip()
venv = "{0}/{1}".format(env.directory, package)
if not exists(venv):
return error("Meh? I need a virtualenv first.")
with settings(sudo_user="invenio"):
with cd("{0}/src/{1}".format(venv, package)):
with prefix('source {0}/bin/activate'.format(venv)):
prefix_folder = sudo('python -c "import invenio; print(invenio.__path__[0])"')
prefix_folder = prefix_folder.split("\n")
sudo("pybabel compile -fd {0}/base/translations".format(prefix_folder[-1]))