Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use docker compose for elasticsearch/opensearch integration tests #5490

Merged
merged 16 commits into from
May 28, 2024
8 changes: 3 additions & 5 deletions .github/workflows/ci-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ jobs:
matrix:
version:
- major: 7.x
image: 7.14.0
distribution: elasticsearch
jaeger: v1
- major: 8.x
image: 8.8.2
distribution: elasticsearch
jaeger: v1
- major: 8.x
image: 8.8.2
distribution: elasticsearch
jaeger: v2
name: ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}
Expand All @@ -57,10 +54,10 @@ jobs:
run: make install-ci

- uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0

- name: Run ${{ matrix.version.distribution }} integration tests
id: test-execution
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.image }} ${{ matrix.version.jaeger }}
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}


- name: Output ${{ matrix.version.distribution }} logs
run: docker logs ${{ steps.test-execution.outputs.cid }}
Expand All @@ -71,3 +68,4 @@ jobs:
with:
files: cover.out,cover-index-cleaner.out,cover-index-rollover.out
flags: ${{ matrix.version.distribution }}-${{ matrix.version.major }}-${{ matrix.version.jaeger }}

6 changes: 2 additions & 4 deletions .github/workflows/ci-opensearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ jobs:
matrix:
version:
- major: 1.x
image: 1.3.7
distribution: opensearch
jaeger: v1
- major: 2.x
image: 2.3.0
distribution: opensearch
jaeger: v1
- major: 2.x
image: 2.3.0
distribution: opensearch
jaeger: v2
name: ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}
Expand Down Expand Up @@ -60,7 +57,8 @@ jobs:

- name: Run ${{ matrix.version.distribution }} integration tests
id: test-execution
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.image }} ${{ matrix.version.jaeger }}
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}


- name: Output ${{ matrix.version.distribution }} logs
run: docker logs ${{ steps.test-execution.outputs.cid }}
Expand Down
14 changes: 14 additions & 0 deletions docker-compose/elasticsearch/v7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.8'

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0
environment:
- discovery.type=single-node
- http.host=0.0.0.0
- transport.host=127.0.0.1
- xpack.security.enabled=false # Disable security features
- xpack.security.http.ssl.enabled=false # Disable HTTPS
- xpack.monitoring.enabled=false # Disable monitoring features
ports:
- "9200:9200"
16 changes: 16 additions & 0 deletions docker-compose/elasticsearch/v8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.8.2
environment:
- discovery.type=single-node
- http.host=0.0.0.0
- transport.host=127.0.0.1
- xpack.security.enabled=false # Disable security features
- xpack.security.http.ssl.enabled=false # Disable HTTPS
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
- action.destructive_requires_name=false
- xpack.monitoring.collection.enabled=false # Disable monitoring features
ports:
- "9200:9200"

12 changes: 12 additions & 0 deletions docker-compose/opensearch/v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.8'

services:
opensearch:
image: opensearchproject/opensearch:1.3.9
environment:
- discovery.type=single-node
- plugins.security.disabled=true
- http.host=0.0.0.0
- transport.host=127.0.0.1
ports:
- "9200:9200"
13 changes: 13 additions & 0 deletions docker-compose/opensearch/v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:
opensearch:
image: opensearchproject/opensearch:2.5.0
environment:
- discovery.type=single-node
- plugins.security.disabled=true
- http.host=0.0.0.0
- transport.host=127.0.0.1
ports:
- "9200:9200"

92 changes: 29 additions & 63 deletions scripts/es-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,115 +18,81 @@ check_arg() {
fi
}

setup_es() {
local tag=$1
local image=docker.elastic.co/elasticsearch/elasticsearch
local params=(
--detach
--publish 9200:9200
--env "http.host=0.0.0.0"
--env "transport.host=127.0.0.1"
--env "xpack.security.enabled=false"
)
local major_version=${tag%%.*}
if (( major_version < 8 )); then
params+=(--env "xpack.monitoring.enabled=false")
else
params+=(--env "xpack.monitoring.collection.enabled=false")
fi
if (( major_version > 7 )); then
params+=(
--env "action.destructive_requires_name=false"
)
fi

local cid
cid=$(docker run "${params[@]}" "${image}:${tag}")
echo "cid=${cid}" >> "$GITHUB_OUTPUT"
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
echo "${cid}"
}

setup_opensearch() {
local image=opensearchproject/opensearch
local tag=$1
local params=(
--detach
--publish 9200:9200
--env "http.host=0.0.0.0"
--env "transport.host=127.0.0.1"
--env "plugins.security.disabled=true"
)
local cid
cid=$(docker run "${params[@]}" "${image}:${tag}")
setup_db() {
local distro=$1
local compose_file=$2
docker compose -f "${compose_file}" up -d
local cid
cid=$(docker compose -f "${compose_file}" ps -q "${distro}")
echo "cid=${cid}" >> "$GITHUB_OUTPUT"
echo "${cid}"
}

wait_for_storage() {
local distro=$1
local url=$2
local cid=$3
local compose_file=$3
local params=(
--silent
--output
/dev/null
--write-out
"%{http_code}"
)
local counter=0
local max_counter=60
while [[ "$(curl "${params[@]}" "${url}")" != "200" && ${counter} -le ${max_counter} ]]; do
docker inspect "${cid}" | jq '.[].State'
echo "waiting for ${url} to be up..."
local max_attempts=60
local attempt=0
echo "Waiting for ${distro} to be available at ${url}..."
until [[ "$(curl "${params[@]}" "${url}")" == "200" ]] || (( attempt >= max_attempts )); do
attempt=$(( attempt + 1 ))
echo "Attempt: ${attempt} ${distro} is not yet available at ${url}..."
sleep 10
counter=$((counter+1))
done
# after the loop, do final verification and set status as global var

if [[ "$(curl "${params[@]}" "${url}")" != "200" ]]; then
echo "ERROR: ${distro} is not ready"
docker logs "${cid}"
docker kill "${cid}"
echo "ERROR: ${distro} is not ready at ${url} after $(( attempt * 10 )) seconds"
echo "::group::${distro} logs"
docker compose -f "${compose_file}" logs
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
echo "::endgroup::"
docker compose -f "${compose_file}" down
db_is_up=0
else
echo "SUCCESS: ${distro} is ready"
echo "SUCCESS: ${distro} is available at ${url}"
db_is_up=1
fi
}

bring_up_storage() {
local distro=$1
local version=$2
local cid
local major_version=${version%%.*}
local compose_file="docker-compose/${distro}/v${major_version}.yml"

echo "starting ${distro} ${version}"
for retry in 1 2 3
do
echo "attempt $retry"
if [ "${distro}" = "elasticsearch" ]; then
cid=$(setup_es "${version}")
elif [ "${distro}" == "opensearch" ]; then
cid=$(setup_opensearch "${version}")
if [ "${distro}" = "elasticsearch" ] || [ "${distro}" = "opensearch" ]; then
setup_db "${distro}" "${compose_file}"
else
echo "Unknown distribution $distro. Valid options are opensearch or elasticsearch"
usage
fi
wait_for_storage "${distro}" "http://localhost:9200" "${cid}"
wait_for_storage "${distro}" "http://localhost:9200" "${compose_file}"
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
if [ ${db_is_up} = "1" ]; then
break
fi
done
if [ ${db_is_up} = "1" ]; then
# shellcheck disable=SC2064
trap "teardown_storage ${cid}" EXIT
trap "teardown_storage ${compose_file}" EXIT
else
echo "ERROR: unable to start ${distro}"
exit 1
fi
}

teardown_storage() {
local cid=$1
docker kill "${cid}"
local compose_file=$1
docker compose -f "${compose_file}" down
}

main() {
Expand All @@ -146,4 +112,4 @@ main() {
fi
}

main "$@"
main "$@"
Loading