Skip to content
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
2 changes: 2 additions & 0 deletions core/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 32 additions & 0 deletions core/docker/bin/health-check
Original file line number Diff line number Diff line change
@@ -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
22 changes: 13 additions & 9 deletions core/docker/container-test.sh
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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..."
Expand All @@ -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
Expand All @@ -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}"
}