Files
opensearch-pyd/.ci/run-opensearch.sh
T

101 lines
3.2 KiB
Bash
Raw Normal View History

2020-02-27 10:13:49 -06:00
#!/usr/bin/env bash
#
2021-08-13 15:51:50 +05:30
# Launch one or more OpenSearch nodes via the Docker image,
2020-02-27 10:13:49 -06:00
# to form a cluster suitable for running the REST API tests.
#
# Export the STACK_VERSION variable, eg. '8.0.0-SNAPSHOT'.
2021-08-06 17:35:41 +05:30
# Export the TEST_SUITE variable, i.e. 'oss'
# Export the NUMBER_OF_NODES variable to start more than 1 node
2020-02-27 10:13:49 -06:00
2021-07-13 19:57:34 -05:00
# Version 1.4.0
2021-08-13 15:51:50 +05:30
# - Initial version of the run-opensearch.sh script
2020-02-27 10:13:49 -06:00
# - Deleting the volume should not dependent on the container still running
# - Fixed `ES_JAVA_OPTS` config
# - Moved to STACK_VERSION and TEST_VERSION
# - Refactored into functions and imports
# - Support NUMBER_OF_NODES
# - Added 5 retries on docker pull for fixing transient network errors
# - Added flags to make local CCR configurations work
# - Added action.destructive_requires_name=false as the default will be true in v8
2020-02-27 10:13:49 -06:00
script_path=$(dirname $(realpath -s $0))
source $script_path/functions/imports.sh
set -euo pipefail
2020-02-27 10:13:49 -06:00
echo -e "\033[34;1mINFO:\033[0m Take down node if called twice with the same arguments (DETACH=true) or on seperate terminals \033[0m"
cleanup_node $es_node_name
2020-02-27 10:13:49 -06:00
master_node_name=${es_node_name}
2021-08-18 00:28:35 +05:30
cluster_name=search-rest-test
2020-02-27 10:13:49 -06:00
declare -a volumes
2020-02-27 10:13:49 -06:00
environment=($(cat <<-END
--env node.name=$es_node_name
--env cluster.name=$cluster_name
--env cluster.initial_master_nodes=$master_node_name
--env discovery.seed_hosts=$master_node_name
2020-02-27 10:13:49 -06:00
--env cluster.routing.allocation.disk.threshold_enabled=false
--env bootstrap.memory_lock=true
--env node.attr.testattr=test
--env path.repo=/tmp
--env repositories.url.allowed_urls=http://snapshot.test*
--env action.destructive_requires_name=false
2020-02-27 10:13:49 -06:00
END
))
NUMBER_OF_NODES=${NUMBER_OF_NODES-1}
http_port=9200
for (( i=0; i<$NUMBER_OF_NODES; i++, http_port++ )); do
node_name=${es_node_name}$i
2021-08-13 15:51:50 +05:30
node_url=${external_opensearch_url/9200/${http_port}}$i
if [[ "$i" == "0" ]]; then node_name=$es_node_name; fi
environment+=($(cat <<-END
--env node.name=$node_name
END
))
echo "$i: $http_port $node_url "
2021-08-18 00:28:35 +05:30
volume_name=${node_name}-rest-test-data
volumes+=($(cat <<-END
2021-08-13 15:51:50 +05:30
--volume $volume_name:/usr/share/opensearch/data${i}
END
))
2020-02-27 10:13:49 -06:00
# make sure we detach for all but the last node if DETACH=false (default) so all nodes are started
local_detach="true"
if [[ "$i" == "$((NUMBER_OF_NODES-1))" ]]; then local_detach=$DETACH; fi
echo -e "\033[34;1mINFO: building $CLUSTER container\033[0m"
echo 'cluster is' $CLUSTER
docker build \
--file=.ci/$CLUSTER/Dockerfile \
--build-arg SECURE_INTEGRATION=false \
--tag=$CLUSTER \
.
echo -e "\033[34;1mINFO:\033[0m Starting container $node_name \033[0m"
set -x
docker run \
--name "$node_name" \
--network "$network_name" \
2021-08-05 20:17:03 +05:30
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g" \
"${environment[@]}" \
"${volumes[@]}" \
--publish "$http_port":9200 \
--ulimit nofile=65536:65536 \
--ulimit memlock=-1:-1 \
--detach="$local_detach" \
2021-08-13 15:51:50 +05:30
--health-cmd="curl -vvv -s --fail $opensearch_url/_cluster/health || exit 1" \
--health-interval=2s \
--health-retries=20 \
--health-timeout=2s \
--rm \
-d \
$CLUSTER;
set +x
if wait_for_container "$es_node_name" "$network_name"; then
echo -e "\033[32;1mSUCCESS:\033[0m Running on: $node_url\033[0m"
2020-02-27 10:13:49 -06:00
fi
done