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

Pass username/password to Cassandra docker-compose health check #6214

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker-compose/cassandra/v4/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
cassandra:
image: cassandra:4.1
container_name: "cassandra-4"
ports:
- "9042:9042"
- "9160:9160"
Expand All @@ -11,7 +12,7 @@ services:
networks:
- cassandra-net
healthcheck:
test: ["CMD", "cqlsh", "-e", "describe keyspaces"]
test: ["CMD", "cqlsh", "-u", "cassandra", "-p", "cassandra", "-e", "describe keyspaces"]
interval: 30s
timeout: 10s
retries: 5
Expand Down
3 changes: 2 additions & 1 deletion docker-compose/cassandra/v5/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
cassandra:
image: cassandra:5.0
container_name: "cassandra-5"
ports:
- "9042:9042"
- "9160:9160"
Expand All @@ -11,7 +12,7 @@ services:
networks:
- cassandra-net
healthcheck:
test: ["CMD", "cqlsh", "-e", "describe keyspaces"]
test: ["CMD", "cqlsh", "-u", "cassandra", "-p", "cassandra", "-e", "describe keyspaces"]
interval: 30s
timeout: 10s
retries: 5
Expand Down
24 changes: 24 additions & 0 deletions scripts/cassandra-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set -euxf -o pipefail
export CASSANDRA_USERNAME="cassandra"
export CASSANDRA_PASSWORD="cassandra"
success="false"
timeout=600
end_time=$((SECONDS + timeout))

usage() {
echo $"Usage: $0 <cassandra_version> <schema_version>"
Expand All @@ -26,6 +28,26 @@ setup_cassandra() {
docker compose -f "$compose_file" up -d
}

healthcheck_cassandra() {
local cas_version=$1
local container_name="cassandra-${cas_version}"
# Since the healthcheck in cassandra is done at the interval of 30s
local wait_seconds=30

while [ $SECONDS -lt $end_time ]; do
status=$(docker inspect -f '{{ .State.Health.Status }}' "${container_name}")
if [[ ${status} == "healthy" ]]; then
echo "✅ $container_name is healthy"
return 0
fi
echo "Waiting for $container_name to be healthy. Current status: $status"
sleep $wait_seconds
done

echo "❌ ERROR: $container_name did not become healthy in time"
exit 1
}

dump_logs() {
local compose_file=$1
echo "::group::🚧 🚧 🚧 Cassandra logs"
Expand Down Expand Up @@ -74,6 +96,8 @@ run_integration_test() {
# shellcheck disable=SC2064
trap "teardown_cassandra ${compose_file}" EXIT

healthcheck_cassandra "${major_version}"

apply_schema "$schema_version" "$primaryKeyspace"
apply_schema "$schema_version" "$archiveKeyspace"

Expand Down
Loading