forked from scrapinghub/portia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision.sh
executable file
·168 lines (142 loc) · 3.83 KB
/
provision.sh
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
#!/bin/bash
set -e
if [ "x$APP_ROOT" = x ]
then
for dir in "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" /app /vagrant
do
if [ -d "$dir" ] && [ -d "$dir/slyd" ]
then
APP_ROOT="$dir"
break
fi
done
fi
if [ "x$APP_ROOT" = x ]
then
echo "Could not determine app directory"
exit 1
fi
echo "APP_ROOT=$APP_ROOT"
usage() {
cat <<EOF
Portia provisioner.
Usage: $0 COMMAND [ COMMAND ... ]
Available commands:
usage -- print this message
install_deps -- install system-level dependencies
install_splash -- install splash
install_python_deps -- install python-level dependencies
configure_initctl -- installs initctl configuration
configure_nginx -- installs nginx configuration
cleanup -- remove unnecessary files. DON'T RUN UNLESS IT'S INSIDE AN IMAGE AND YOU KNOW WHAT YOU ARE DOING
EOF
}
export SPLASH_PYTHON_VERSION=${SPLASH_PYTHON_VERSION:-"2"}
activate_venv () {
if [ -e ${VIRTUAL_ENV}/bin/activate ]; then
echo "Activating virtual env..."
source ${VIRTUAL_ENV}/bin/activate
fi
}
install_deps(){
echo deb http://nginx.org/packages/ubuntu/ trusty nginx > /etc/apt/sources.list.d/nginx.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62
wget -O - https://deb.nodesource.com/setup_7.x | bash -
apt-get update -q
apt-get -y --no-install-recommends install \
curl \
libxml2-dev \
libxslt-dev \
libgl1-mesa-dev \
libgl1-mesa-glx \
libglapi-mesa \
libgl1-mesa-dri \
libmysqlclient-dev \
nginx python-dev \
nodejs \
python-mysql.connector \
python-numpy \
python-openssl \
python-pip \
python-software-properties
pip install -U pip setuptools
}
install_python_deps(){
activate_venv
pip install -r "$APP_ROOT/slybot/requirements.txt"
pip install -r "$APP_ROOT/slyd/requirements.txt"
pip install -r "$APP_ROOT/portia_server/requirements.txt"
pip install -e "$APP_ROOT/slyd"
pip install -e "$APP_ROOT/slybot"
}
install_splash(){
cd /tmp
curl -L -o splash.tar.gz 'https://github.com/scrapinghub/splash/archive/2.3.x.tar.gz'
tar -xvf splash.tar.gz --keep-newer-files
cd splash-*
activate_venv
dockerfiles/splash/provision.sh \
prepare_install \
install_builddeps \
install_deps \
install_pyqt5
pip install .
}
cleanup() {
cd /
rm -rf /tmp/splash*
rm -rf /var/lib/apt/lists/*
apt-get remove --purge -y libxml2-dev \
libxslt-dev \
libgl1-mesa-dev \
python-dev
apt-get autoremove -y
apt-get clean
find / | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
}
configure_nginx(){
cp -r $APP_ROOT/nginx/* /etc/nginx
sed 's/\/app\//'""${APP_ROOT//\//\\\/}""'\//g' -i /etc/nginx/nginx.conf
}
configure_initctl(){
cp "$APP_ROOT/portia.conf" /etc/init
}
migrate_django_db(){
python /vagrant/portia_server/manage.py migrate
}
start_portia(){
echo "Starting Nginx"
echo "=============="
/etc/init.d/nginx start
echo "Starting Nginx"
echo "=============="
start portia
}
install_frontend_deps() {
npm install -g bower ember-cli
}
build_assets() {
cd "$APP_ROOT/portiaui"
npm install && bower install
ember build
}
if [ \( $# -eq 0 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]; then
usage
exit 1
fi
UNKNOWN=0
for cmd in "$@"; do
if [ "$(type -t -- "$cmd")" != "function" ]; then
echo "Unknown command: $cmd"
UNKNOWN=1
fi
done
if [ $UNKNOWN -eq 1 ]; then
echo "Unknown commands encountered, exiting..."
exit 1
fi
while [ $# -gt 0 ]; do
echo "Executing command: $1"
"$1"
shift
done