diff --git a/core/docker/Dockerfile b/core/docker/Dockerfile index ae025a8ad21e..5827a04f3db9 100644 --- a/core/docker/Dockerfile +++ b/core/docker/Dockerfile @@ -35,3 +35,5 @@ EXPOSE 8080 USER trino:trino ENV LANG en_US.UTF-8 CMD ["/usr/lib/trino/bin/run-trino"] +HEALTHCHECK --interval=10s --timeout=5s --start-period=10s \ + CMD /usr/lib/trino/bin/health-check diff --git a/core/docker/bin/health-check b/core/docker/bin/health-check new file mode 100755 index 000000000000..0f4d50b77a69 --- /dev/null +++ b/core/docker/bin/health-check @@ -0,0 +1,32 @@ +#!/bin/bash + +set -euo pipefail + +function get_property() { + grep "^$1=" "$2" | cut -d'=' -f2 +} + +scheme=http +port=8080 + +config=/etc/trino/config.properties +# prefer to use http even if https is enabled +if [ "$(get_property 'http-server.http.enabled' "$config")" == "false" ]; then + scheme=https + port=$(get_property http-server.https.port "$config") +else + port=$(get_property http-server.http.port "$config") +fi + +endpoint="$scheme://localhost:$port/v1/info" + +# add --insecure to disable certificate verification in curl, in case a self-signed certificate is being used +if ! info=$(curl --fail --silent --show-error --insecure "$endpoint"); then + echo >&2 "Server is not responding to requests" + exit 1 +fi + +if ! grep -q '"starting":\s*false' <<<"$info" >/dev/null; then + echo >&2 "Server is starting" + exit 1 +fi diff --git a/core/docker/container-test.sh b/core/docker/container-test.sh index ccb5a14877fb..08985dc3929c 100644 --- a/core/docker/container-test.sh +++ b/core/docker/container-test.sh @@ -1,5 +1,7 @@ +#!/usr/bin/env bash + function cleanup { - if [[ ! -z ${CONTAINER_ID:-} ]]; then + if [[ -n ${CONTAINER_ID:-} ]]; then docker rm -f "${CONTAINER_ID}" fi } @@ -14,12 +16,11 @@ function test_trino_starts { local CONTAINER_NAME=$1 local PLATFORM=$2 # We aren't passing --rm here to make sure container is available for inspection in case of failures - CONTAINER_ID=$(docker run -d --platform ${PLATFORM} "${CONTAINER_NAME}") + CONTAINER_ID=$(docker run -d --platform "${PLATFORM}" "${CONTAINER_NAME}") set +e I=0 - until RESULT=$(docker exec "${CONTAINER_ID}" trino --execute "SELECT 'success'" 2>/dev/null) - do + until docker inspect "${CONTAINER_ID}" --format "{{json .State.Health.Status }}" | grep -q '"healthy"'; do if [[ $((I++)) -ge ${QUERY_RETRIES} ]]; then echo "🚨 Too many retries waiting for Trino to start" echo "Logs from ${CONTAINER_ID} follow..." @@ -28,6 +29,9 @@ function test_trino_starts { fi sleep ${QUERY_PERIOD} done + if ! RESULT=$(docker exec "${CONTAINER_ID}" trino --execute "SELECT 'success'" 2>/dev/null); then + echo "🚨 Failed to execute a query after Trino container started" + fi set -e cleanup @@ -41,17 +45,17 @@ function test_javahome { local CONTAINER_NAME=$1 local PLATFORM=$2 # Check if JAVA_HOME works - docker run --rm --platform ${PLATFORM} "${CONTAINER_NAME}" \ - /bin/bash -c '$JAVA_HOME/bin/java -version' &> /dev/null + docker run --rm --platform "${PLATFORM}" "${CONTAINER_NAME}" \ + /bin/bash -c '$JAVA_HOME/bin/java -version' &>/dev/null - [[ "$?" == "0" ]] + [[ $? == "0" ]] } function test_container { local CONTAINER_NAME=$1 local PLATFORM=$2 echo "🐢 Validating ${CONTAINER_NAME} on platform ${PLATFORM}..." - test_javahome ${CONTAINER_NAME} ${PLATFORM} - test_trino_starts ${CONTAINER_NAME} ${PLATFORM} + test_javahome "${CONTAINER_NAME}" "${PLATFORM}" + test_trino_starts "${CONTAINER_NAME}" "${PLATFORM}" echo "🎉 Validated ${CONTAINER_NAME} on platform ${PLATFORM}" }