Skip to content

Commit

Permalink
fixup! Added dockerization for the Trino Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
rdsarvar committed Dec 29, 2023
1 parent 843dc04 commit 405a06e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 38 deletions.
9 changes: 3 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,20 @@ COPY --from=jdk-download $JAVA_HOME $JAVA_HOME
RUN \
set -xeu && \
microdnf update -y && \
microdnf install -y tar less python3 python3-pip shadow-utils jq && \
update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
pip3 install requests pyyaml && \
microdnf install -y tar less shadow-utils && \
groupadd trino --gid 1000 && \
useradd trino --uid 1000 --gid 1000 --create-home && \
mkdir -p /usr/lib/trino && \
chown -R "trino:trino" /usr/lib/trino /opt/trino

ARG TRINO_GATEWAY_VERSION
COPY --chown=trino:trino gateway-ha-${TRINO_GATEWAY_VERSION}-jar-with-dependencies.jar /usr/lib/trino
COPY --chown=trino:trino gateway-ha /usr/lib/trino

ARG TRINO_GATEWAY_VERSION
ENV GATEWAY_JAR_PATH "/usr/lib/trino/gateway-ha-${TRINO_GATEWAY_VERSION}-jar-with-dependencies.jar"

EXPOSE 8080
USER trino:trino
CMD java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED -jar "${GATEWAY_JAR_PATH}" "server" "/opt/trino/gateway-ha-config.yml"

HEALTHCHECK --interval=10s --timeout=5s --start-period=10s \
CMD /usr/lib/trino/bin/health-check.py
CMD /usr/lib/trino/bin/health-check
4 changes: 2 additions & 2 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ If it is not mounted then the gateway will fail to initialize.

## Health Checking

By default the container health checking is done by the [/usr/lib/trino/bin/health-check.py](./bin/health-check.py)
python script which simply expects a 2XX response from the server at `/api/public/backends`.
By default the container health checking is done by the [/usr/lib/trino/bin/health-check](./bin/health-check)
script which simply expects a 2XX response from the server at `/api/public/backends`.

## Building a custom Docker image

Expand Down
75 changes: 75 additions & 0 deletions docker/bin/health-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

set -euo pipefail

function get_2nd_level_yaml_key() {
local parent_key=$1
local target_key=$2
local yaml_file_path=$3

# In order to get the nested key we will leverage awk to do some parsing
awk -v parent_key=${parent_key} \
-v target_key=${target_key} \
'
function count_indentation(line) {
match(line, /^[[:space:]]*/);
return RLENGTH;
}
# First we search for the parent_key, once we find it we set in_block to true
match($0, "^" parent_key ":") {
in_block=1;
parent_indent_level = count_indentation($0);
next;
} \
in_block {
# All lines we deem to be a comment will be skipped.
if (match($0, "^[[:space:]]*#")) { next; }
# If we determine that we have left the parent_key block we will exit.
if ($0 ~ /^[^\t #]/) { exit; }
current_indent_level = count_indentation($0);
# Next, because we dont know the indentation levels being provided, we will attempt
# to find the indentation level of the 2nd level keys.
if ( !first_level_indentation \
&& match($0, "^[[:space:]]+.*:") \
&& current_indent_level > parent_indent_level) {
first_level_indentation = current_indent_level;
}
# Then we will attempt to find the 2nd level target key based on:
# 1. Theres only spaces before the target_key
# 2. The indentation level is equal to the found 2nd level indentation
if (match($0, "^[[:space:]]+" target_key ":") \
&& current_indent_level == first_level_indentation) {
# If we decide that the key matches our expectations, we will print the matched value
sub(/:/, "", $2);
print $2;
}
}
' \
${yaml_file_path}
}

config=/opt/trino/gateway-ha-config.yml
scheme=http
port=8080

# prefer to use http even if https is enabled
if [ "$(get_2nd_level_yaml_key 'requestRouter' 'ssl' "$config")" == "true" ]; then
scheme=https
fi

potential_port=$(get_2nd_level_yaml_key 'requestRouter' 'port' "$config")
if [ "${potential_port}" != "" ]; then
port=${potential_port}
fi

endpoint="${scheme}://localhost:${port}/api/public/backends"

# 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
23 changes: 0 additions & 23 deletions docker/bin/health-check.py

This file was deleted.

13 changes: 7 additions & 6 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ set -xeuo pipefail
usage() {
cat <<EOF 1>&2
Usage: $0 [-h] [-a <ARCHITECTURES>] [-r <VERSION>]
Builds the Trino Docker image
Builds the Trino Gateway Docker image
-h Display help
-a Build the specified comma-separated architectures, defaults to amd64,arm64,ppc64le
-r Build the specified Trino release version, downloads all required artifacts
-j Build the Trino release with specified Temurin JDK release
-r Build the specified Trino Gateway release version, downloads all required artifacts
-j Build the Trino Gateway release with specified Temurin JDK release
EOF
}

Expand Down Expand Up @@ -102,9 +102,10 @@ fi

echo "🧱 Preparing the image build context directory"
WORK_DIR="$(mktemp -d)"
mkdir "${WORK_DIR}/gateway-ha"
cp "$trino_gateway_ha" "${WORK_DIR}"
cp -R bin "${WORK_DIR}/gateway-ha"
GATEWAY_WORK_DIR="${WORK_DIR}/gateway-ha"
mkdir "${GATEWAY_WORK_DIR}"
cp "$trino_gateway_ha" "${GATEWAY_WORK_DIR}"
cp -R bin "${GATEWAY_WORK_DIR}"
cp "${SCRIPT_DIR}/Dockerfile" "${WORK_DIR}"

TAG_PREFIX="trino-gateway:${TRINO_GATEWAY_VERSION}"
Expand Down
1 change: 0 additions & 1 deletion localdev/gateway-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ services:
postgres:
condition: service_healthy
healthcheck:
test: "/usr/lib/trino/bin/health-check.py"
interval: 10s
timeout: 5s
retries: 3
Expand Down

0 comments on commit 405a06e

Please sign in to comment.