Skip to content

Commit db00f02

Browse files
committed
update .ci run scripts
1 parent 3d1e7b3 commit db00f02

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

.ci/run-elasticsearch.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ fi
1212

1313
set -euxo pipefail
1414

15+
SCRIPT_PATH=$(dirname $(realpath -s $0))
16+
1517
moniker=$(echo "$ELASTICSEARCH_VERSION" | tr -C "[:alnum:]" '-')
1618
suffix=rest-test
1719

@@ -21,10 +23,10 @@ CLUSTER_NAME=${CLUSTER_NAME-${moniker}${suffix}}
2123
HTTP_PORT=${HTTP_PORT-9200}
2224

2325
ELASTIC_PASSWORD=${ELASTIC_PASSWORD-changeme}
24-
SSL_CERT=${SSL_CERT-"$PWD/certs/testnode.crt"}
25-
SSL_KEY=${SSL_KEY-"$PWD/certs/testnode.key"}
26-
SSL_CA=${SSL_CA-"$PWD/certs/ca.crt"}
27-
SSL_CA_PEM=${SSL_CA-"$PWD/certs/ca.pem"}
26+
SSL_CERT=${SSL_CERT-"${SCRIPT_PATH}/certs/testnode.crt"}
27+
SSL_KEY=${SSL_KEY-"${SCRIPT_PATH}/certs/testnode.key"}
28+
SSL_CA=${SSL_CA-"${SCRIPT_PATH}/certs/ca.crt"}
29+
SSL_CA_PEM=${SSL_CA-"${SCRIPT_PATH}/certs/ca.pem"}
2830

2931
DETACH=${DETACH-false}
3032
CLEANUP=${CLEANUP-false}
@@ -48,7 +50,7 @@ function container_running {
4850
fi
4951
}
5052
function cleanup_node {
51-
if container_running $1; then
53+
if container_running "$1"; then
5254
echo -e "\033[34;1mINFO:\033[0m Removing container $1\033[0m"
5355
(docker container rm --force --volumes "$1") || true
5456
cleanup_volume "$1-${suffix}-data"
@@ -70,7 +72,7 @@ function cleanup {
7072
echo -e "\033[34;1mINFO:\033[0m clean the network if not detached (start and exit)\033[0m"
7173
cleanup_network "$NETWORK_NAME"
7274
fi
73-
};
75+
};
7476
trap "cleanup 0" EXIT
7577

7678
if [[ "$CLEANUP" == "true" ]]; then
@@ -92,7 +94,7 @@ echo -e "\033[34;1mINFO:\033[0m Making sure previous run leftover infrastructure
9294
cleanup 1
9395

9496
echo -e "\033[34;1mINFO:\033[0m Creating network $NETWORK_NAME if it does not exist already \033[0m"
95-
docker network inspect "$NETWORK_NAME" > /dev/null 2>&1 || docker network create "$NETWORK_NAME"
97+
docker network inspect "$NETWORK_NAME" > /dev/null 2>&1 || docker network create "$NETWORK_NAME"
9698

9799
environment=($(cat <<-END
98100
--env node.name=$NODE_NAME
@@ -166,28 +168,28 @@ docker run \
166168
--rm \
167169
docker.elastic.co/elasticsearch/"$ELASTICSEARCH_VERSION";
168170
set +x
169-
171+
170172
if [[ "$DETACH" == "true" ]]; then
171-
until container_running $NODE_NAME && [[ "$(docker inspect -f "{{.State.Health.Status}}" ${NODE_NAME})" != "starting" ]]; do
173+
until ! container_running "$NODE_NAME" || (container_running "$NODE_NAME" && [[ "$(docker inspect -f "{{.State.Health.Status}}" ${NODE_NAME})" != "starting" ]]); do
172174
echo ""
173175
docker inspect -f "{{range .State.Health.Log}}{{.Output}}{{end}}" ${NODE_NAME}
174176
echo -e "\033[34;1mINFO:\033[0m waiting for node $NODE_NAME to be up\033[0m"
175177
sleep 2;
176178
done;
177179

178180
# Always show logs if the container is running, this is very useful both on CI as well as while developing
179-
if container_running $NODE_NAME; then
181+
if container_running "$NODE_NAME"; then
180182
docker logs $NODE_NAME
181183
fi
182184

183-
if ! container_running $NODE_NAME || [[ "$(docker inspect -f "{{.State.Health.Status}}" ${NODE_NAME})" != "healthy" ]]; then
185+
if ! container_running "$NODE_NAME" || [[ "$(docker inspect -f "{{.State.Health.Status}}" ${NODE_NAME})" != "healthy" ]]; then
184186
cleanup 1
185-
echo
187+
echo
186188
echo -e "\033[31;1mERROR:\033[0m Failed to start ${ELASTICSEARCH_VERSION} in detached mode beyond health checks\033[0m"
187189
echo -e "\033[31;1mERROR:\033[0m dumped the docker log before shutting the node down\033[0m"
188190
exit 1
189-
else
190-
echo
191+
else
192+
echo
191193
echo -e "\033[32;1mSUCCESS:\033[0m Detached and healthy: ${NODE_NAME} on docker network: ${NETWORK_NAME}\033[0m"
192194
echo -e "\033[32;1mSUCCESS:\033[0m Running on: ${url/$NODE_NAME/localhost}:${HTTP_PORT}\033[0m"
193195
exit 0

.ci/run-tests

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ if [[ -z $ELASTICSEARCH_VERSION ]]; then
66
fi
77
set -euxo pipefail
88

9+
910
TEST_SUITE=${TEST_SUITE-oss}
10-
DOTNET_VERSION=${DOTNET_VERSION-3.0.100}
1111
NODE_NAME=instance
1212

13+
1314
repo=$(pwd)
15+
1416
elasticsearch_image=elasticsearch
1517
elasticsearch_url=https://elastic:changeme@${NODE_NAME}:9200
1618
if [[ $TEST_SUITE != "xpack" ]]; then
@@ -43,10 +45,12 @@ ELASTICSEARCH_VERSION=${elasticsearch_image}:${ELASTICSEARCH_VERSION} \
4345
NODE_NAME=${NODE_NAME} \
4446
NETWORK_NAME=elasticsearch \
4547
DETACH=true \
46-
bash ./.ci/run-elasticsearch.sh
48+
bash .ci/run-elasticsearch.sh
4749

4850
echo -e "\033[1m>>>>> Build [elastic/elasticsearch-net container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
4951

52+
DOTNET_VERSION=${DOTNET_VERSION-3.0.100}
53+
5054
docker build --file .ci/DockerFile --tag elastic/elasticsearch-net .
5155

5256
echo -e "\033[1m>>>>> Run [elastic/elasticsearch-net container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
@@ -60,4 +64,4 @@ docker run \
6064
--volume ${repo}/build/output:/sln/build/output \
6165
--rm \
6266
elastic/elasticsearch-net \
63-
./build.sh rest-spec-tests -f create -e ${elasticsearch_url} -o /sln/build/output/rest-spec-junit.xml
67+
./build.sh rest-spec-tests -e ${elasticsearch_url} -o /sln/build/output/rest-spec-junit.xml

0 commit comments

Comments
 (0)