forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·205 lines (184 loc) · 8.4 KB
/
run.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
#!/bin/bash
set -ex
# Set the build dir to ./ if not set by travis
BUILD_DIR=$PWD
if [[ -z "$TRAVIS_BUILD_DIR" && "$TRAVIS_BUILD_DIR" -ne "" ]]; then
BUILD_DIR=$TRAVIS_BUILD_DIR
fi
export PATH=$BUILD_DIR/gradle/bin:$PATH
function finish {
last_result=$?
set +e
[[ $last_result -ne 0 ]] && cat /tmp/elasticsearch.log
}
trap finish EXIT
setup_es() {
download_url=$1
xpack_download_url=$2
if [[ ! -d elasticsearch ]]; then
curl -sL $download_url > elasticsearch.tar.gz
mkdir elasticsearch
tar -xzf elasticsearch.tar.gz --strip-components=1 -C ./elasticsearch/.
fi
rm -f elasticsearch/config/scripts || true
mkdir -p elasticsearch/config/scripts
cp $BUILD_DIR/spec/fixtures/scripts/groovy/* elasticsearch/config/scripts
cp $BUILD_DIR/spec/fixtures/scripts/painless/* elasticsearch/config/scripts
# If we're running with xpack SSL/Users enabled...
# Note that 6.3.0 releases and above do not require an x-pack plugin install
if [[ "$DISTRIBUTION" == "legacyxpack" ]]; then
if [[ "$xpack_download_url" == "" ]]; then
yes y | elasticsearch/bin/elasticsearch-plugin install x-pack
else
curl -sL $xpack_download_url > elasticsearch/xpack.zip
yes y | elasticsearch/bin/elasticsearch-plugin install file://$BUILD_DIR/elasticsearch/xpack.zip
fi
fi
if [[ "$SECURE_INTEGRATION" == "true" ]]; then
es_yml=elasticsearch/config/elasticsearch.yml
cp -rv $BUILD_DIR/spec/fixtures/test_certs elasticsearch/config/test_certs
echo "xpack.security.http.ssl.enabled: true" >> $es_yml
echo "xpack.ssl.key: $BUILD_DIR/elasticsearch/config/test_certs/test.key" >> $es_yml
echo "xpack.ssl.certificate: $BUILD_DIR/elasticsearch/config/test_certs/test.crt" >> $es_yml
echo "xpack.ssl.certificate_authorities: [ '$BUILD_DIR/elasticsearch/config/test_certs/ca/ca.crt' ]" >> $es_yml
fi
}
start_es() {
es_args=$@
elasticsearch/bin/elasticsearch $es_args > /tmp/elasticsearch.log 2>/dev/null &
count=120
echo "Waiting for elasticsearch to respond..."
es_url="http://localhost:9200"
if [[ "$SECURE_INTEGRATION" == "true" ]]; then
es_url="https://localhost:9200 -k"
fi
# Needed for travis. On travis the `users` script will fail because it will first try and write
# to /etc/elasticsearch
export CONF_DIR=$BUILD_DIR/elasticsearch/config
if [[ "$DISTRIBUTION" == "default" ]]; then
elasticsearch/bin/elasticsearch-users useradd simpleuser -p abc123 -r superuser
elasticsearch/bin/elasticsearch-users useradd 'f@ncyuser' -p 'ab%12#' -r superuser
elif [[ "$DISTRIBUTION" == "legacyxpack" ]]; then
elasticsearch/bin/x-pack/users useradd simpleuser -p abc123 -r superuser
elasticsearch/bin/x-pack/users useradd 'f@ncyuser' -p 'ab%12#' -r superuser
fi
while ! curl --silent $es_url && [[ $count -ne 0 ]]; do
count=$(( $count - 1 ))
[[ $count -eq 0 ]] && return 1
sleep 1
done
echo "Elasticsearch is Up !"
return 0
}
get_es_distribution_version() {
local version_string=$(elasticsearch/bin/elasticsearch -v -V | tr "," " " | cut -d " " -f 2)
echo $version_string
}
# Ruby build environment does not have gradle in the env, so we need to download it
# Gradle is added to the PATH in the before_script step and *has* to stay there and
# not here because this script runs in a different bash shell.
download_gradle() {
echo $PWD
local version="4.10"
curl -sL https://services.gradle.org/distributions/gradle-$version-bin.zip > gradle.zip
unzip -d . gradle.zip
mv gradle-* gradle
}
# Builds any branch of ES and runs tests against it. Default is master
build_es() {
branch=$1
git clone https://github.com/elastic/elasticsearch.git es_src
cd es_src
gradle :distribution:zip:assemble
unzip -d $BUILD_DIR distribution/zip/build/distributions/elasticsearch-*.zip
mv $BUILD_DIR/elasticsearch-* $BUILD_DIR/elasticsearch
cd $BUILD_DIR
mkdir -p elasticsearch/config/scripts
cp $BUILD_DIR/spec/fixtures/scripts/painless/* elasticsearch/config/scripts
}
start_nginx() {
./start_nginx.sh &
sleep 5
}
bundle install
if [[ "$INTEGRATION" != "true" ]]; then
bundle exec rspec -fd spec -t ~integration -t ~secure_integration
else
if [[ "$1" -eq "" ]]; then
spec_path="spec"
else
spec_path="$1"
fi
extra_tag_args="--tag ~secure_integration --tag integration"
if [[ "$SECURE_INTEGRATION" == "true" ]]; then
extra_tag_args="--tag secure_integration"
fi
case "$ES_VERSION" in
# ES_VERSION prefixed with LATEST-SNAPSHOT- will interrogate the artifacts API to find the latest version that matches
# the part after the prefix - eg LATEST-SNAPSHOT-7 will pull the latest snapshot release of 7.x of Elasticsearch,
# LATEST-SNAPSHOT-6.5 will pull the latest snapshot release of 6.5
LATEST-SNAPSHOT-*)
split_latest=${ES_VERSION##*-}
LATEST_ES_VERSION=$(curl -sL https://artifacts-api.elastic.co/v1/versions/ | jq -r --arg LATEST $split_latest '[.versions[] | select(startswith($LATEST))][-1]')
if [[ "$DISTRIBUTION" == "oss" ]]; then
setup_es https://snapshots.elastic.co/downloads/elasticsearch/elasticsearch-oss-${LATEST_ES_VERSION}.tar.gz
elif [[ "$DISTRIBUTION" == "default" ]]; then
setup_es https://snapshots.elastic.co/downloads/elasticsearch/elasticsearch-${LATEST_ES_VERSION}.tar.gz
fi
es_distribution_version=$(get_es_distribution_version)
start_es
bundle exec rspec -fd $extra_tag_args --tag update_tests:painless --tag update_tests:groovy --tag es_version:$es_distribution_version $spec_path
;;
*-SNAPSHOT)
if [[ "$DISTRIBUTION" == "oss" ]]; then
setup_es https://snapshots.elastic.co/downloads/elasticsearch/elasticsearch-oss-${ES_VERSION}.tar.gz
elif [[ "$DISTRIBUTION" == "default" ]]; then
setup_es https://snapshots.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
fi
es_distribution_version=$(get_es_distribution_version)
start_es
bundle exec rspec -fd $extra_tag_args --tag update_tests:painless --tag update_tests:groovy --tag es_version:$es_distribution_version $spec_path
;;
6.[0-2]*)
setup_es https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-${ES_VERSION}.zip
es_distribution_version=$(get_es_distribution_version)
start_es
bundle exec rspec -fd $extra_tag_args --tag update_tests:painless --tag update_tests:groovy --tag es_version:$es_distribution_version $spec_path
;;
6.*)
if [[ "$DISTRIBUTION" == "oss" ]]; then
setup_es https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-${ES_VERSION}.tar.gz
elif [[ "$DISTRIBUTION" == "default" ]]; then
setup_es https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
fi
es_distribution_version=$(get_es_distribution_version)
start_es
bundle exec rspec -fd $extra_tag_args --tag update_tests:painless --tag update_tests:groovy --tag es_version:$es_distribution_version $spec_path
;;
5.*)
setup_es https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
es_distribution_version=$(get_es_distribution_version)
start_es -Escript.inline=true -Escript.stored=true -Escript.file=true
bundle exec rspec -fd $extra_tag_args --tag update_tests:painless --tag update_tests:groovy --tag es_version:$es_distribution_version $spec_path
;;
2.*)
setup_es https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-$ES_VERSION.tar.gz
es_distribution_version=$(get_es_distribution_version)
start_es -Des.script.inline=on -Des.script.indexed=on -Des.script.file=on
bundle exec rspec -fd $extra_tag_args --tag update_tests:groovy --tag es_version:$es_distribution_version $spec_path
;;
1.*)
setup_es https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-$ES_VERSION.tar.gz
es_distribution_version=$(get_es_distribution_version)
start_es -Des.script.inline=on -Des.script.indexed=on -Des.script.file=on
bundle exec rspec -fd $extra_tag_args --tag es_version:$es_distribution_version $spec_path
;;
*)
download_gradle
build_es master
es_distribution_version=$(get_es_distribution_version)
start_es
bundle exec rspec -fd $extra_tag_args --tag update_tests:painless --tag ~update_tests:groovy --tag es_version:$es_distribution_version $spec_path
;;
esac
fi