1#!/usr/bin/env bash 2# 3# Sets up all the common variables and imports relevant functions 4# 5# Version 1.0.1 6# - Initial version after refactor 7# - Validate STACK_VERSION asap 8 9function require_stack_version() { 10 if [[ -z $STACK_VERSION ]]; then 11 echo -e "\033[31;1mERROR:\033[0m Required environment variable [STACK_VERSION] not set\033[0m" 12 exit 1 13 fi 14} 15 16require_stack_version 17 18if [[ -z $es_node_name ]]; then 19 # only set these once 20 set -euo pipefail 21 export TEST_SUITE=${TEST_SUITE-free} 22 export RUNSCRIPTS=${RUNSCRIPTS-} 23 export DETACH=${DETACH-false} 24 export CLEANUP=${CLEANUP-false} 25 26 export es_node_name=instance 27 export elastic_password=changeme 28 export elasticsearch_image=elasticsearch 29 export elasticsearch_url=https://elastic:${elastic_password}@${es_node_name}:9200 30 export external_elasticsearch_url=${elasticsearch_url/$es_node_name/localhost} 31 export elasticsearch_container="${elasticsearch_image}:${STACK_VERSION}" 32 33 export suffix=rest-test 34 export moniker=$(echo "$elasticsearch_container" | tr -C "[:alnum:]" '-') 35 export network_name=${moniker}${suffix} 36 37 export ssl_cert="${script_path}/certs/testnode.crt" 38 export ssl_key="${script_path}/certs/testnode.key" 39 export ssl_ca="${script_path}/certs/ca.crt" 40 41fi 42 43 export script_path=$(dirname $(realpath -s $0)) 44 source $script_path/functions/cleanup.sh 45 source $script_path/functions/wait-for-container.sh 46 trap "cleanup_trap ${network_name}" EXIT 47 48 49if [[ "$CLEANUP" == "true" ]]; then 50 cleanup_all_in_network $network_name 51 exit 0 52fi 53 54echo -e "\033[34;1mINFO:\033[0m Creating network $network_name if it does not exist already \033[0m" 55docker network inspect "$network_name" > /dev/null 2>&1 || docker network create "$network_name" 56 57