Skip to content

Commit

Permalink
fix: Conflict CLI options from SE_OPTS and corresponding env variables
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Aug 12, 2024
1 parent e7ddd01 commit 799f6f8
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 241 deletions.
54 changes: 31 additions & 23 deletions Distributor/start-selenium-grid-distributor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ set -e

echo "Starting Selenium Grid Distributor..."

function append_se_opts() {
local option="${1}"
local value="${2:-""}"
local log_message="${3:-true}"
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
if [ "${log_message}" = "true" ]; then
echo "Appending Selenium option: ${option} ${value}"
fi
SE_OPTS="${SE_OPTS} ${option}"
if [ ! -z "${value}" ]; then
SE_OPTS="${SE_OPTS} ${value}"
fi
else
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"
fi
}

if [[ -z "${SE_EVENT_BUS_HOST}" ]]; then
echo "SE_EVENT_BUS_HOST not set, exiting!" 1>&2
exit 1
Expand Down Expand Up @@ -40,10 +57,6 @@ if [[ -z "${SE_SESSION_QUEUE_PORT}" ]]; then
exit 1
fi

if [ ! -z "$SE_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi

if [ ! -z "$SE_DISTRIBUTOR_HOST" ]; then
echo "Using SE_DISTRIBUTOR_HOST: ${SE_DISTRIBUTOR_HOST}"
HOST_CONFIG="--host ${SE_DISTRIBUTOR_HOST}"
Expand All @@ -55,23 +68,19 @@ if [ ! -z "$SE_DISTRIBUTOR_PORT" ]; then
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
append_se_opts "--log-level" "${SE_LOG_LEVEL}"
fi

if [ ! -z "$SE_HTTP_LOGS" ]; then
echo "Appending Selenium options: --http-logs ${SE_HTTP_LOGS}"
SE_OPTS="$SE_OPTS --http-logs ${SE_HTTP_LOGS}"
append_se_opts "--http-logs" "${SE_HTTP_LOGS}"
fi

if [ ! -z "$SE_STRUCTURED_LOGS" ]; then
echo "Appending Selenium options: --structured-logs ${SE_STRUCTURED_LOGS}"
SE_OPTS="$SE_OPTS --structured-logs ${SE_STRUCTURED_LOGS}"
append_se_opts "--structured-logs" "${SE_STRUCTURED_LOGS}"
fi

if [ ! -z "$SE_EXTERNAL_URL" ]; then
echo "Appending Selenium options: --external-url ${SE_EXTERNAL_URL}"
SE_OPTS="$SE_OPTS --external-url ${SE_EXTERNAL_URL}"
append_se_opts "--external-url" "${SE_EXTERNAL_URL}"
fi

if [ "${SE_ENABLE_TLS}" = "true" ]; then
Expand All @@ -92,28 +101,23 @@ if [ "${SE_ENABLE_TLS}" = "true" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS -Djdk.internal.httpclient.disableHostnameVerification=${SE_JAVA_DISABLE_HOSTNAME_VERIFICATION}"
# Configure certificate and private key for component communication
if [ ! -z "$SE_HTTPS_CERTIFICATE" ]; then
echo "Appending Selenium options: --https-certificate ${SE_HTTPS_CERTIFICATE}"
SE_OPTS="$SE_OPTS --https-certificate ${SE_HTTPS_CERTIFICATE}"
append_se_opts "--https-certificate" "${SE_HTTPS_CERTIFICATE}"
fi
if [ ! -z "$SE_HTTPS_PRIVATE_KEY" ]; then
echo "Appending Selenium options: --https-private-key ${SE_HTTPS_PRIVATE_KEY}"
SE_OPTS="$SE_OPTS --https-private-key ${SE_HTTPS_PRIVATE_KEY}"
append_se_opts "--https-private-key" "${SE_HTTPS_PRIVATE_KEY}"
fi
fi

if [ ! -z "$SE_REGISTRATION_SECRET" ]; then
echo "Appending Selenium options: --registration-secret ${SE_REGISTRATION_SECRET}"
SE_OPTS="$SE_OPTS --registration-secret ${SE_REGISTRATION_SECRET}"
append_se_opts "--registration-secret" "${SE_REGISTRATION_SECRET}"
fi

if [ ! -z "$SE_REJECT_UNSUPPORTED_CAPS" ]; then
echo "Appending Selenium options: --reject-unsupported-caps ${SE_REJECT_UNSUPPORTED_CAPS}"
SE_OPTS="$SE_OPTS --reject-unsupported-caps ${SE_REJECT_UNSUPPORTED_CAPS}"
append_se_opts "--reject-unsupported-caps" "${SE_REJECT_UNSUPPORTED_CAPS}"
fi

if [ ! -z "$SE_NEW_SESSION_THREAD_POOL_SIZE" ]; then
echo "Appending Selenium options: --newsession-threadpool-size ${SE_NEW_SESSION_THREAD_POOL_SIZE}"
SE_OPTS="$SE_OPTS --newsession-threadpool-size ${SE_NEW_SESSION_THREAD_POOL_SIZE}"
append_se_opts "--newsession-threadpool-size" "${SE_NEW_SESSION_THREAD_POOL_SIZE}"
fi

EXTRA_LIBS=""
Expand Down Expand Up @@ -141,11 +145,15 @@ if [ "$SE_ENABLE_TRACING" = "true" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS ${SE_OTEL_JVM_ARGS}"
fi
else
SE_OPTS="$SE_OPTS --tracing false"
append_se_opts "--tracing" "false"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Dwebdriver.remote.enableTracing=false"
echo "Tracing is disabled"
fi

if [ ! -z "$SE_OPTS" ]; then
echo "All Selenium options: ${SE_OPTS}"
fi

java ${JAVA_OPTS:-$SE_JAVA_OPTS} \
-jar /opt/selenium/selenium-server.jar \
${EXTRA_LIBS} distributor \
Expand Down
45 changes: 28 additions & 17 deletions EventBus/start-selenium-grid-eventbus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ set -e

echo "Starting Selenium Grid EventBus..."

function append_se_opts() {
local option="${1}"
local value="${2:-""}"
local log_message="${3:-true}"
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
if [ "${log_message}" = "true" ]; then
echo "Appending Selenium option: ${option} ${value}"
fi
SE_OPTS="${SE_OPTS} ${option}"
if [ ! -z "${value}" ]; then
SE_OPTS="${SE_OPTS} ${value}"
fi
else
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"
fi
}

if [ ! -z "$SE_EVENT_BUS_HOST" ]; then
echo "Using SE_EVENT_BUS_HOST: ${SE_EVENT_BUS_HOST}"
HOST_CONFIG="--host ${SE_EVENT_BUS_HOST}"
Expand All @@ -15,28 +32,20 @@ if [ ! -z "$SE_EVENT_BUS_PORT" ]; then
PORT_CONFIG="--port ${SE_EVENT_BUS_PORT}"
fi

if [ ! -z "$SE_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
append_se_opts "--log-level" "${SE_LOG_LEVEL}"
fi

if [ ! -z "$SE_HTTP_LOGS" ]; then
echo "Appending Selenium options: --http-logs ${SE_HTTP_LOGS}"
SE_OPTS="$SE_OPTS --http-logs ${SE_HTTP_LOGS}"
append_se_opts "--http-logs" "${SE_HTTP_LOGS}"
fi

if [ ! -z "$SE_STRUCTURED_LOGS" ]; then
echo "Appending Selenium options: --structured-logs ${SE_STRUCTURED_LOGS}"
SE_OPTS="$SE_OPTS --structured-logs ${SE_STRUCTURED_LOGS}"
append_se_opts "--structured-logs" "${SE_STRUCTURED_LOGS}"
fi

if [ ! -z "$SE_EXTERNAL_URL" ]; then
echo "Appending Selenium options: --external-url ${SE_EXTERNAL_URL}"
SE_OPTS="$SE_OPTS --external-url ${SE_EXTERNAL_URL}"
append_se_opts "--external-url" "${SE_EXTERNAL_URL}"
fi

if [ "${SE_ENABLE_TLS}" = "true" ]; then
Expand All @@ -57,12 +66,10 @@ if [ "${SE_ENABLE_TLS}" = "true" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS -Djdk.internal.httpclient.disableHostnameVerification=${SE_JAVA_DISABLE_HOSTNAME_VERIFICATION}"
# Configure certificate and private key for component communication
if [ ! -z "$SE_HTTPS_CERTIFICATE" ]; then
echo "Appending Selenium options: --https-certificate ${SE_HTTPS_CERTIFICATE}"
SE_OPTS="$SE_OPTS --https-certificate ${SE_HTTPS_CERTIFICATE}"
append_se_opts "--https-certificate" "${SE_HTTPS_CERTIFICATE}"
fi
if [ ! -z "$SE_HTTPS_PRIVATE_KEY" ]; then
echo "Appending Selenium options: --https-private-key ${SE_HTTPS_PRIVATE_KEY}"
SE_OPTS="$SE_OPTS --https-private-key ${SE_HTTPS_PRIVATE_KEY}"
append_se_opts "--https-private-key" "${SE_HTTPS_PRIVATE_KEY}"
fi
fi

Expand Down Expand Up @@ -91,11 +98,15 @@ if [ "$SE_ENABLE_TRACING" = "true" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS ${SE_OTEL_JVM_ARGS}"
fi
else
SE_OPTS="$SE_OPTS --tracing false"
append_se_opts "--tracing" "false"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Dwebdriver.remote.enableTracing=false"
echo "Tracing is disabled"
fi

if [ ! -z "$SE_OPTS" ]; then
echo "All Selenium options: ${SE_OPTS}"
fi

java ${JAVA_OPTS:-$SE_JAVA_OPTS} \
-jar /opt/selenium/selenium-server.jar \
${EXTRA_LIBS} event-bus \
Expand Down
63 changes: 35 additions & 28 deletions Hub/start-selenium-grid-hub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@
# set -e: exit asap if a command exits with a non-zero status
set -e

if [ ! -z "$SE_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi
echo "Starting Selenium Grid Hub..."

function append_se_opts() {
local option="${1}"
local value="${2:-""}"
local log_message="${3:-true}"
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
if [ "${log_message}" = "true" ]; then
echo "Appending Selenium option: ${option} ${value}"
fi
SE_OPTS="${SE_OPTS} ${option}"
if [ ! -z "${value}" ]; then
SE_OPTS="${SE_OPTS} ${value}"
fi
else
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"
fi
}

if [ ! -z "$SE_HUB_HOST" ]; then
echo "Using SE_HUB_HOST: ${SE_HUB_HOST}"
Expand All @@ -23,23 +38,19 @@ if [ ! -z "$SE_SUB_PATH" ]; then
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
append_se_opts "--log-level" "${SE_LOG_LEVEL}"
fi

if [ ! -z "$SE_HTTP_LOGS" ]; then
echo "Appending Selenium options: --http-logs ${SE_HTTP_LOGS}"
SE_OPTS="$SE_OPTS --http-logs ${SE_HTTP_LOGS}"
append_se_opts "--http-logs" "${SE_HTTP_LOGS}"
fi

if [ ! -z "$SE_STRUCTURED_LOGS" ]; then
echo "Appending Selenium options: --structured-logs ${SE_STRUCTURED_LOGS}"
SE_OPTS="$SE_OPTS --structured-logs ${SE_STRUCTURED_LOGS}"
append_se_opts "--structured-logs" "${SE_STRUCTURED_LOGS}"
fi

if [ ! -z "$SE_EXTERNAL_URL" ]; then
echo "Appending Selenium options: --external-url ${SE_EXTERNAL_URL}"
SE_OPTS="$SE_OPTS --external-url ${SE_EXTERNAL_URL}"
append_se_opts "--external-url" "${SE_EXTERNAL_URL}"
fi

if [ "${SE_ENABLE_TLS}" = "true" ]; then
Expand All @@ -60,43 +71,35 @@ if [ "${SE_ENABLE_TLS}" = "true" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS -Djdk.internal.httpclient.disableHostnameVerification=${SE_JAVA_DISABLE_HOSTNAME_VERIFICATION}"
# Configure certificate and private key for component communication
if [ ! -z "$SE_HTTPS_CERTIFICATE" ]; then
echo "Appending Selenium options: --https-certificate ${SE_HTTPS_CERTIFICATE}"
SE_OPTS="$SE_OPTS --https-certificate ${SE_HTTPS_CERTIFICATE}"
append_se_opts "--https-certificate" "${SE_HTTPS_CERTIFICATE}"
fi
if [ ! -z "$SE_HTTPS_PRIVATE_KEY" ]; then
echo "Appending Selenium options: --https-private-key ${SE_HTTPS_PRIVATE_KEY}"
SE_OPTS="$SE_OPTS --https-private-key ${SE_HTTPS_PRIVATE_KEY}"
append_se_opts "--https-private-key" "${SE_HTTPS_PRIVATE_KEY}"
fi
fi

if [ ! -z "$SE_REGISTRATION_SECRET" ]; then
echo "Appending Selenium options: --registration-secret ${SE_REGISTRATION_SECRET}"
SE_OPTS="$SE_OPTS --registration-secret ${SE_REGISTRATION_SECRET}"
append_se_opts "--registration-secret" "${SE_REGISTRATION_SECRET}"
fi

if [ ! -z "$SE_DISABLE_UI" ]; then
echo "Appending Selenium options: --disable-ui ${SE_DISABLE_UI}"
SE_OPTS="$SE_OPTS --disable-ui ${SE_DISABLE_UI}"
append_se_opts "--disable-ui" "${SE_DISABLE_UI}"
fi

if [ ! -z "$SE_ROUTER_USERNAME" ]; then
echo "Appending Selenium options: --username ${SE_ROUTER_USERNAME}"
SE_OPTS="$SE_OPTS --username ${SE_ROUTER_USERNAME}"
append_se_opts "--username" "${SE_ROUTER_USERNAME}"
fi

if [ ! -z "$SE_ROUTER_PASSWORD" ]; then
echo "Appending Selenium options: --password ${SE_ROUTER_PASSWORD}"
SE_OPTS="$SE_OPTS --password ${SE_ROUTER_PASSWORD}"
append_se_opts "--password" "${SE_ROUTER_PASSWORD}"
fi

if [ ! -z "$SE_REJECT_UNSUPPORTED_CAPS" ]; then
echo "Appending Selenium options: --reject-unsupported-caps ${SE_REJECT_UNSUPPORTED_CAPS}"
SE_OPTS="$SE_OPTS --reject-unsupported-caps ${SE_REJECT_UNSUPPORTED_CAPS}"
append_se_opts "--reject-unsupported-caps" "${SE_REJECT_UNSUPPORTED_CAPS}"
fi

if [ ! -z "$SE_NEW_SESSION_THREAD_POOL_SIZE" ]; then
echo "Appending Selenium options: --newsession-threadpool-size ${SE_NEW_SESSION_THREAD_POOL_SIZE}"
SE_OPTS="$SE_OPTS --newsession-threadpool-size ${SE_NEW_SESSION_THREAD_POOL_SIZE}"
append_se_opts "--newsession-threadpool-size" "${SE_NEW_SESSION_THREAD_POOL_SIZE}"
fi

EXTRA_LIBS=""
Expand Down Expand Up @@ -124,11 +127,15 @@ if [ "$SE_ENABLE_TRACING" = "true" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS ${SE_OTEL_JVM_ARGS}"
fi
else
SE_OPTS="$SE_OPTS --tracing false"
append_se_opts "--tracing" "false"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Dwebdriver.remote.enableTracing=false"
echo "Tracing is disabled"
fi

if [ ! -z "$SE_OPTS" ]; then
echo "All Selenium options: ${SE_OPTS}"
fi

java ${JAVA_OPTS:-$SE_JAVA_OPTS} \
-jar /opt/selenium/selenium-server.jar \
${EXTRA_LIBS} hub \
Expand Down
Loading

0 comments on commit 799f6f8

Please sign in to comment.