From 84a25b59e822c99ec3ef38452df267d69308ef55 Mon Sep 17 00:00:00 2001 From: elianddb Date: Tue, 23 Sep 2025 12:21:55 -0700 Subject: [PATCH] add health checks for config requirements --- docker/docker-entrypoint.sh | 40 ++++++++++++----- integration-tests/bats/docker-entrypoint.bats | 44 +++++++++++++++++++ 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 71208f34ed..948a14d049 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -23,7 +23,11 @@ mysql_warn() { } mysql_error() { mysql_log ERROR "$@" >&2 - mysql_note "Remove this container with 'docker rm -f ' before retrying" + if [ -f "/tmp/server.log" ]; then + mysql_note "Server log:" + cat /tmp/server.log >&2 + fi + mysql_note "Remove this container with 'docker rm -f ' before retrying" exit 1 } docker_process_sql() { @@ -236,34 +240,48 @@ _main() { mysql_note "Starting Dolt server in background..." dolt sql-server --host=0.0.0.0 --port=3306 "$@" > /tmp/server.log 2>&1 & local server_pid=$! - - # Wait for server to be ready + + # Wait for server to be ready and all required capabilities to be functional local max_attempts=30 local attempt=0 + local last_error="" while [ $attempt -lt $max_attempts ]; do - if dolt sql -q "SELECT 1;" >/dev/null 2>&1; then + # Connectivity + local basic_output + if ! basic_output=$(dolt sql -q "SELECT 1;" 2>&1); then + last_error="Basic connectivity failed: $basic_output" + # MySQL system tables are accessible + elif ! mysql_output=$(dolt sql -q "SELECT COUNT(*) FROM mysql.user;" 2>&1); then + last_error="MySQL system tables not accessible: $mysql_output" + # Database creation capability + elif ! db_test_output=$(dolt sql -q "CREATE DATABASE IF NOT EXISTS __health_check_db__; DROP DATABASE __health_check_db__;" 2>&1); then + last_error="Database creation/deletion not working: $db_test_output" + # User privilege queries work + elif ! priv_output=$(dolt sql -q "SELECT COUNT(*) FROM mysql.db;" 2>&1); then + last_error="Privilege tables not accessible: $priv_output" + else mysql_note "Server initialization complete!" break fi sleep 1 attempt=$((attempt + 1)) done - + if [ $attempt -eq $max_attempts ]; then - mysql_error "Server failed to start within 30 seconds" + mysql_error "Server failed to be ready within 30 seconds. Last error: $last_error" fi - + # Create root user with the specified host (defaults to localhost if not specified) local root_host="${DOLT_ROOT_HOST:-localhost}" mysql_note "Ensuring root@${root_host} superuser exists with password" - + # Ensure root user exists with correct password and permissions mysql_note "Configuring root@${root_host} user" dolt sql -q "CREATE USER IF NOT EXISTS 'root'@'${root_host}' IDENTIFIED BY '${DOLT_ROOT_PASSWORD}'; ALTER USER 'root'@'${root_host}' IDENTIFIED BY '${DOLT_ROOT_PASSWORD}'; GRANT ALL ON *.* TO 'root'@'${root_host}' WITH GRANT OPTION;" >/dev/null 2>&1 || mysql_error "Failed to configure root@${root_host} user." - + # If DOLT_DATABASE or MYSQL_DATABASE has been specified, create the database if it does not exist create_default_database_from_env - + # Show what users exist for debugging mysql_note "Current users in the system:" dolt sql -q "SELECT User, Host FROM mysql.user;" 2>&1 | grep -v "^$" || mysql_warn "Could not list users" @@ -274,7 +292,7 @@ _main() { # Kill the background process and restart in foreground to show live output kill $server_pid 2>/dev/null || true wait $server_pid 2>/dev/null || true - + # Start server in foreground to show live output exec dolt sql-server --host=0.0.0.0 --port=3306 "$@" } diff --git a/integration-tests/bats/docker-entrypoint.bats b/integration-tests/bats/docker-entrypoint.bats index 532f894a40..787b8d8250 100644 --- a/integration-tests/bats/docker-entrypoint.bats +++ b/integration-tests/bats/docker-entrypoint.bats @@ -636,3 +636,47 @@ EOF docker rmi "$SPECIFIC_IMAGE" >/dev/null 2>&1 || true } + +# bats test_tags=no_lambda +@test "docker-entrypoint: multiple server start/stop cycles to confirm no timing issues" { + cname="${TEST_PREFIX}multi-restart" + db="testdb" + usr="testuser" + pwd="testpass" + + # Test multiple start/stop cycles to verify health check robustness + for cycle in {1..20}; do + echo "# Starting server cycle $cycle" >&3 + + # Start container with user and database configuration + run_container_with_port "$cname-$cycle" 3306 \ + -e DOLT_ROOT_PASSWORD=rootpass \ + -e DOLT_ROOT_HOST=% \ + -e DOLT_DATABASE="$db" \ + -e DOLT_USER="$usr" \ + -e DOLT_PASSWORD="$pwd" + + echo "# Server cycle $cycle completed successfully" >&3 + + # Verify no errors in container logs + run docker logs "$cname-$cycle" 2>&1 + [ $status -eq 0 ] + # Should not contain ERROR messages (but allow warnings) + ! echo "$output" | grep -i "ERROR" >/dev/null || false + # Should contain success indicators + [[ "$output" =~ "Server initialization complete" ]] || false + [[ "$output" =~ "Server ready. Accepting connections" ]] || false + + # Stop the container + run docker stop "$cname-$cycle" + [ $status -eq 0 ] + + # Clean up for next cycle + run docker rm "$cname-$cycle" + [ $status -eq 0 ] + + echo "# Server cycle $cycle stopped and cleaned up" >&3 + done + + echo "# All $cycle server start/stop cycles completed successfully" >&3 +}