Skip to content

Commit 206999f

Browse files
authored
[7.11] [CI] Update integration test suite with new Docker distribution format
1 parent f5e441d commit 206999f

File tree

13 files changed

+288
-305
lines changed

13 files changed

+288
-305
lines changed

.ci/functions/cleanup.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Shared cleanup routines between different steps
4+
#
5+
# Please source .ci/functions/imports.sh as a whole not just this file
6+
#
7+
# Version 1.0.0
8+
# - Initial version after refactor
9+
10+
function cleanup_volume {
11+
if [[ "$(docker volume ls -q -f name=$1)" ]]; then
12+
echo -e "\033[34;1mINFO:\033[0m Removing volume $1\033[0m"
13+
(docker volume rm "$1") || true
14+
fi
15+
}
16+
function container_running {
17+
if [[ "$(docker ps -q -f name=$1)" ]]; then
18+
return 0;
19+
else return 1;
20+
fi
21+
}
22+
function cleanup_node {
23+
if container_running "$1"; then
24+
echo -e "\033[34;1mINFO:\033[0m Removing container $1\033[0m"
25+
(docker container rm --force --volumes "$1") || true
26+
fi
27+
if [[ -n "$1" ]]; then
28+
echo -e "\033[34;1mINFO:\033[0m Removing volume $1-${suffix}-data\033[0m"
29+
cleanup_volume "$1-${suffix}-data"
30+
fi
31+
}
32+
function cleanup_network {
33+
if [[ "$(docker network ls -q -f name=$1)" ]]; then
34+
echo -e "\033[34;1mINFO:\033[0m Removing network $1\033[0m"
35+
(docker network rm "$1") || true
36+
fi
37+
}
38+
39+
function cleanup_trap {
40+
status=$?
41+
set +x
42+
if [[ "$DETACH" != "true" ]]; then
43+
echo -e "\033[34;1mINFO:\033[0m clean the network if not detached (start and exit)\033[0m"
44+
cleanup_all_in_network "$1"
45+
fi
46+
# status is 0 or SIGINT
47+
if [[ "$status" == "0" || "$status" == "130" ]]; then
48+
echo -e "\n\033[32;1mSUCCESS run-tests\033[0m"
49+
exit 0
50+
else
51+
echo -e "\n\033[31;1mFAILURE during run-tests\033[0m"
52+
exit ${status}
53+
fi
54+
};
55+
function cleanup_all_in_network {
56+
57+
if [[ -z "$(docker network ls -q -f name="^$1\$")" ]]; then
58+
echo -e "\033[34;1mINFO:\033[0m $1 is already deleted\033[0m"
59+
return 0
60+
fi
61+
containers=$(docker network inspect -f '{{ range $key, $value := .Containers }}{{ printf "%s\n" .Name}}{{ end }}' $1)
62+
while read -r container; do
63+
cleanup_node "$container"
64+
done <<< "$containers"
65+
cleanup_network $1
66+
echo -e "\033[32;1mSUCCESS:\033[0m Cleaned up and exiting\033[0m"
67+
};

.ci/functions/imports.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
9+
function 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+
16+
require_stack_version
17+
18+
if [[ -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+
if [[ $TEST_SUITE != "platinum" ]]; then
31+
export elasticsearch_url=http://${es_node_name}:9200
32+
fi
33+
export external_elasticsearch_url=${elasticsearch_url/$es_node_name/localhost}
34+
export elasticsearch_container="${elasticsearch_image}:${STACK_VERSION}"
35+
36+
export suffix=rest-test
37+
export moniker=$(echo "$elasticsearch_container" | tr -C "[:alnum:]" '-')
38+
export network_name=${moniker}${suffix}
39+
40+
export ssl_cert="${script_path}/certs/testnode.crt"
41+
export ssl_key="${script_path}/certs/testnode.key"
42+
export ssl_ca="${script_path}/certs/ca.crt"
43+
44+
fi
45+
46+
export script_path=$(dirname $(realpath -s $0))
47+
source $script_path/functions/cleanup.sh
48+
source $script_path/functions/wait-for-container.sh
49+
trap "cleanup_trap ${network_name}" EXIT
50+
51+
52+
if [[ "$CLEANUP" == "true" ]]; then
53+
cleanup_all_in_network $network_name
54+
exit 0
55+
fi
56+
57+
echo -e "\033[34;1mINFO:\033[0m Creating network $network_name if it does not exist already \033[0m"
58+
docker network inspect "$network_name" > /dev/null 2>&1 || docker network create "$network_name"
59+

.ci/functions/wait-for-container.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Exposes a routine scripts can call to wait for a container if that container set up a health command
4+
#
5+
# Please source .ci/functions/imports.sh as a whole not just this file
6+
#
7+
# Version 1.0.1
8+
# - Initial version after refactor
9+
# - Make sure wait_for_contiainer is silent
10+
11+
function wait_for_container {
12+
set +x
13+
until ! container_running "$1" || (container_running "$1" && [[ "$(docker inspect -f "{{.State.Health.Status}}" ${1})" != "starting" ]]); do
14+
echo ""
15+
docker inspect -f "{{range .State.Health.Log}}{{.Output}}{{end}}" ${1}
16+
echo -e "\033[34;1mINFO:\033[0m waiting for node $1 to be up\033[0m"
17+
sleep 2;
18+
done;
19+
20+
# Always show logs if the container is running, this is very useful both on CI as well as while developing
21+
if container_running $1; then
22+
docker logs $1
23+
fi
24+
25+
if ! container_running $1 || [[ "$(docker inspect -f "{{.State.Health.Status}}" ${1})" != "healthy" ]]; then
26+
cleanup_all_in_network $2
27+
echo
28+
echo -e "\033[31;1mERROR:\033[0m Failed to start $1 in detached mode beyond health checks\033[0m"
29+
echo -e "\033[31;1mERROR:\033[0m dumped the docker log before shutting the node down\033[0m"
30+
return 1
31+
else
32+
echo
33+
echo -e "\033[32;1mSUCCESS:\033[0m Detached and healthy: ${1} on docker network: ${network_name}\033[0m"
34+
return 0
35+
fi
36+
}

.ci/jobs/defaults.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
- axis:
4141
type: yaml
4242
filename: .ci/test-matrix.yml
43-
name: ELASTICSEARCH_VERSION
43+
name: STACK_VERSION
4444
- axis:
4545
type: yaml
4646
filename: .ci/test-matrix.yml

0 commit comments

Comments
 (0)