forked from querqy/chorus-elasticsearch-edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickstart.sh
executable file
·230 lines (197 loc) · 7.91 KB
/
quickstart.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
# This script starts up Chorus and runs through the basic setup tasks.
set -e
# Ansi color code variables
ERROR='\033[0;31m[QUICKSTART] '
MAJOR='\033[0;34m[QUICKSTART] '
MINOR='\033[0;37m[QUICKSTART] '
RESET='\033[0m' # No Color
export DOCKER_SCAN_SUGGEST=false
if ! [ -x "$(command -v curl)" ]; then
echo "${ERROR}Error: curl is not installed.${RESET}" >&2
exit 1
fi
if ! [ -x "$(command -v docker-compose)" ]; then
echo "${ERROR}Error: docker-compose is not installed.${RESET}" >&2
exit 1
fi
if ! [ -x "$(command -v jq)" ]; then
echo "${ERROR}Error: jq is not installed.${RESET}" >&2
exit 1
fi
if ! [ -x "$(command -v wget)" ]; then
echo "${ERROR}Error: wget is not installed.${RESET}" >&2
exit 1
fi
observability=false
shutdown=false
offline_lab=false
local_deploy=true
stop=false
while [ ! $# -eq 0 ]
do
case "$1" in
--help | -h)
echo -e "Use the option --with-offline-lab | -lab to include Quepid and RRE services in Chorus."
echo -e "Use the option --with-observability | -obs to include Grafana, Prometheus, and Elasticsearch Exporter services in Chorus."
echo -e "Use the option --shutdown | -s to shutdown and remove the Docker containers and data."
echo -e "Use the option --stop to stop the Docker containers."
echo -e "Use the option --online-deployment | -online to update configuration to run on chorus-es-edition.dev.o19s.com environment."
exit
;;
--with-observability | -obs)
observability=true
echo -e "${MAJOR}Running Chorus with observability services enabled\n${RESET}"
;;
--with-offline-lab | -lab)
offline_lab=true
echo -e "${MAJOR}Running Chorus with offline lab environment enabled\n${RESET}"
;;
--online-deployment | -online)
local_deploy=false
echo -e "${MAJOR}Configuring Chorus for chorus-es-edition.dev.o19s.com environment${RESET}"
;;
--shutdown | -s)
shutdown=true
echo -e "${MAJOR}Shutting down Chorus\n${RESET}"
;;
--stop)
stop=true
echo -e "${MAJOR}Stopping Chorus\n${RESET}"
;;
esac
shift
done
services="elasticsearch kibana chorus-ui smui"
if $observability; then
services="${services} grafana elasticsearch-exporter"
fi
if $offline_lab; then
services="${services} quepid rre keycloak"
fi
if ! $local_deploy; then
echo -e "${MAJOR}Updating configuration files for online deploy${RESET}"
sed -i.bu 's/localhost:3000/chorus-es-edition.dev.o19s.com:3000/g' ./keycloak/realm-config/chorus-realm.json
sed -i.bu 's/keycloak:9080/chorus-es-edition.dev.o19s.com:9080/g' ./keycloak/wait-for-keycloak.sh
sed -i.bu 's/keycloak:9080/chorus-es-edition.dev.o19s.com:9080/g' ./docker-compose.yml
sed -i.bu 's/localhost:9200/chorus-es-edition.dev.o19s.com:9200/g' ./reactivesearch/src/App.js
fi
if $stop; then
services="${services} grafana elasticsearch-exporter quepid rre keycloak"
docker-compose stop ${services}
exit
fi
if $shutdown; then
docker-compose down -v
exit
fi
docker-compose up -d --build ${services}
echo -e "${MAJOR}Waiting for Elasticsearch to start up and be online.${RESET}"
./elasticsearch/wait-for-es.sh # Wait for Elasticsearch to be online
echo -e "${MAJOR}Setting up an admin user to explore Elasticsearch and a role for anonymous access to run RRE offline tests.\n${RESET}"
curl -u 'elastic:ElasticRocks' -X POST "localhost:9200/_security/user/chorus_admin?pretty" -H 'Content-Type: application/json' -d'
{
"password" : "password",
"roles" : ["superuser"]
}
'
curl -u 'elastic:ElasticRocks' -X POST "localhost:9200/_security/role/anonymous_user" -H 'Content-Type: application/json' -d'
{
"run_as": [ ],
"cluster": [ ],
"indices": [
{
"names": [ "ecommerce" ],
"privileges": [ "read" ]
}
]
}
'
echo -e "${MAJOR}Creating ecommerce index, defining its mapping & settings\n${RESET}"
curl -u 'elastic:ElasticRocks' -s -X PUT "localhost:9200/ecommerce/" -H 'Content-Type: application/json' --data-binary @./elasticsearch/schema.json
if [ ! -f ./icecat-products-w_price-19k-20201127.tar.gz ]; then
echo -e "${MAJOR}Downloading the sample product data\n${RESET}"
wget https://querqy.org/datasets/icecat/icecat-products-w_price-19k-20201127.tar.gz
fi
if [ ! -f ./icecat-products-w_price-19k-20201127.json ]; then
echo -e "${MAJOR}Unpacking the sample product data, please give it a few minutes!\n${RESET}"
tar xzf icecat-products-w_price-19k-20201127.tar.gz
fi
if [ ! -f ./transformed_data.json ]; then
output=transformed_data.json
for row in $(cat icecat-products-w_price-19k-20201127.json | jq -r '.[] | @base64'); do
my_line=$(echo ${row} | base64 --decode)
_id() {
echo ${my_line} | jq -r .id
}
_jq() {
echo ${my_line} | jq -r ${1}
}
echo { \"index\" : {\"_id\" : \"$(_id)\"}} >> ${output}
echo $(_jq '.') >> ${output}
done
fi
echo -e "${MAJOR}Indexing the sample product data, please wait...\n${RESET}"
curl -u 'elastic:ElasticRocks' -s -X POST "localhost:9200/ecommerce/_bulk?pretty" -H 'Content-Type: application/json' --data-binary @transformed_data.json
echo -e "${MAJOR}Creating default (emty) query rewriters\n${RESET}"
# Query rewriters are configured empty, without any rules. This ensures that no errors occur when the different
# relevance algorithms are used in the frontend before any rules are set.
# For configuring the rules SMUI will be set up and used.
curl -u 'elastic:ElasticRocks' -s --request PUT 'http://localhost:9200/_querqy/rewriter/common_rules' \
--header 'Content-Type: application/json' \
--data-raw '{
"class": "querqy.elasticsearch.rewriter.SimpleCommonRulesRewriterFactory",
"config": {
"rules": ""
}
}'
curl -u 'elastic:ElasticRocks' -s --request PUT 'http://localhost:9200/_querqy/rewriter/common_rules_prelive' \
--header 'Content-Type: application/json' \
--data-raw '{
"class": "querqy.elasticsearch.rewriter.SimpleCommonRulesRewriterFactory",
"config": {
"rules": ""
}
}'
curl -u 'elastic:ElasticRocks' -s --request PUT 'http://localhost:9200/_querqy/rewriter/replace' \
--header 'Content-Type: application/json' \
--data-raw '{
"class": "querqy.elasticsearch.rewriter.ReplaceRewriterFactory",
"config": {
"rules": ""
}
}'
curl -u 'elastic:ElasticRocks' -s --request PUT 'http://localhost:9200/_querqy/rewriter/replace_prelive' \
--header 'Content-Type: application/json' \
--data-raw '{
"class": "querqy.elasticsearch.rewriter.ReplaceRewriterFactory",
"config": {
"rules": ""
}
}'
echo -e "${MAJOR}Setting up SMUI\n${RESET}"
while [ $(curl -s http://localhost:9000/api/v1/solr-index | wc -c) -lt 2 ]; do
echo "Waiting 5s for SMUI to be ready..."
sleep 5
done
curl -X PUT -H "Content-Type: application/json" -d '{"name":"ecommerce", "description":"Chorus Webshop"}' http://localhost:9000/api/v1/solr-index
if $offline_lab; then
if $local_deploy; then
./keycloak/check-for-host-configuration.sh
fi
echo -e "${MINOR}Waiting for Keycloak to be available${RESET}"
./keycloak/wait-for-keycloak.sh
echo -e "${MAJOR}Setting up Quepid${RESET}"
docker-compose run --rm quepid bin/rake db:setup
docker-compose run quepid thor user:create -a admin@choruselectronics.com "Chorus Admin" password
echo -e "${MAJOR}Setting up RRE\n${RESET}"
docker-compose run rre mvn rre:evaluate
docker-compose run rre mvn rre-report:report
fi
if $observability; then
echo -e "${MAJOR}Setting up Grafana\n${RESET}"
curl -u admin:password -S -X POST -H "Content-Type: application/json" -d '{"email":"admin@choruselectronics.com", "name":"Chorus Admin", "role":"admin", "login":"admin@choruselectronics.com", "password":"password", "theme":"light"}' http://localhost:9091/api/admin/users
curl -u admin:password -S -X PUT -H "Content-Type: application/json" -d '{"isGrafanaAdmin": true}' http://localhost:9091/api/admin/users/2/permissions
curl -u admin:password -S -X POST -H "Content-Type: application/json" http://localhost:9091/api/users/2/using/1
fi
echo -e "${MAJOR}Welcome to Chorus ES Edition!${RESET}"