-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathstart-selenium-grid-docker.sh
executable file
·160 lines (136 loc) · 5.57 KB
/
start-selenium-grid-docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
# set -e: exit asap if a command exits with a non-zero status
set -e
echo "Starting Selenium Grid Standalone Docker..."
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}"
else
echo "Appending Selenium option: ${option} $(mask ${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_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi
if [ ! -z "$SE_NODE_GRID_URL" ]; then
echo "Appending Grid url: ${SE_NODE_GRID_URL}"
SE_GRID_URL="--grid-url ${SE_NODE_GRID_URL}"
fi
if [ ! -z "$SE_NODE_ENABLE_MANAGED_DOWNLOADS" ]; then
append_se_opts "--enable-managed-downloads" "${SE_NODE_ENABLE_MANAGED_DOWNLOADS}"
fi
if [ ! -z "$SE_NODE_ENABLE_CDP" ]; then
append_se_opts "--enable-cdp" "${SE_NODE_ENABLE_CDP}"
fi
if [ ! -z "$SE_NODE_REGISTER_PERIOD" ]; then
append_se_opts "--register-period" "${SE_NODE_REGISTER_PERIOD}"
fi
if [ ! -z "$SE_NODE_REGISTER_CYCLE" ]; then
append_se_opts "--register-cycle" "${SE_NODE_REGISTER_CYCLE}"
fi
if [ ! -z "$SE_NODE_HEARTBEAT_PERIOD" ]; then
append_se_opts "--heartbeat-period" "${SE_NODE_HEARTBEAT_PERIOD}"
fi
if [ ! -z "$SE_LOG_LEVEL" ]; then
append_se_opts "--log-level" "${SE_LOG_LEVEL}"
fi
if [ ! -z "$SE_HTTP_LOGS" ]; then
append_se_opts "--http-logs" "${SE_HTTP_LOGS}"
fi
if [ ! -z "$SE_STRUCTURED_LOGS" ]; then
append_se_opts "--structured-logs" "${SE_STRUCTURED_LOGS}"
fi
if [ ! -z "$SE_EXTERNAL_URL" ]; then
append_se_opts "--external-url" "${SE_EXTERNAL_URL}"
fi
if [ "${SE_ENABLE_TLS}" = "true" ]; then
# Configure truststore for the server
if [ ! -z "$SE_JAVA_SSL_TRUST_STORE" ]; then
echo "Appending Java options: -Djavax.net.ssl.trustStore=${SE_JAVA_SSL_TRUST_STORE}"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Djavax.net.ssl.trustStore=${SE_JAVA_SSL_TRUST_STORE}"
fi
if [ -f "${SE_JAVA_SSL_TRUST_STORE_PASSWORD}" ]; then
echo "Getting Truststore password from ${SE_JAVA_SSL_TRUST_STORE_PASSWORD} to set Java options: -Djavax.net.ssl.trustStorePassword"
SE_JAVA_SSL_TRUST_STORE_PASSWORD="$(cat ${SE_JAVA_SSL_TRUST_STORE_PASSWORD})"
fi
if [ ! -z "${SE_JAVA_SSL_TRUST_STORE_PASSWORD}" ]; then
echo "Appending Java options: -Djavax.net.ssl.trustStorePassword=$(mask ${SE_JAVA_SSL_TRUST_STORE_PASSWORD})"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Djavax.net.ssl.trustStorePassword=${SE_JAVA_SSL_TRUST_STORE_PASSWORD}"
fi
echo "Appending Java options: -Djdk.internal.httpclient.disableHostnameVerification=${SE_JAVA_DISABLE_HOSTNAME_VERIFICATION}"
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
append_se_opts "--https-certificate" "${SE_HTTPS_CERTIFICATE}"
fi
if [ ! -z "$SE_HTTPS_PRIVATE_KEY" ]; then
append_se_opts "--https-private-key" "${SE_HTTPS_PRIVATE_KEY}"
fi
fi
echo "Selenium Grid Standalone Docker configuration: "
cat "${CONFIG_FILE}"
EXTRA_LIBS=""
if [ "${SE_ENABLE_TRACING}" = "true" ] && [ -n "${SE_OTEL_EXPORTER_ENDPOINT}" ]; then
EXTERNAL_JARS=$(</external_jars/.classpath.txt)
[ -n "$EXTRA_LIBS" ] && [ -n "${EXTERNAL_JARS}" ] && EXTRA_LIBS=${EXTRA_LIBS}:
EXTRA_LIBS="--ext "${EXTRA_LIBS}${EXTERNAL_JARS}
echo "Tracing is enabled"
echo "Classpath will be enriched with these external jars : " ${EXTRA_LIBS}
if [ -n "$SE_OTEL_SERVICE_NAME" ]; then
SE_OTEL_JVM_ARGS="$SE_OTEL_JVM_ARGS -Dotel.resource.attributes=service.name=${SE_OTEL_SERVICE_NAME}"
fi
if [ -n "$SE_OTEL_TRACES_EXPORTER" ]; then
SE_OTEL_JVM_ARGS="$SE_OTEL_JVM_ARGS -Dotel.traces.exporter=${SE_OTEL_TRACES_EXPORTER}"
fi
if [ -n "$SE_OTEL_EXPORTER_ENDPOINT" ]; then
SE_OTEL_JVM_ARGS="$SE_OTEL_JVM_ARGS -Dotel.exporter.otlp.endpoint=$(envsubst < <(echo ${SE_OTEL_EXPORTER_ENDPOINT}))"
fi
if [ -n "$SE_OTEL_JAVA_GLOBAL_AUTOCONFIGURE_ENABLED" ]; then
SE_OTEL_JVM_ARGS="$SE_OTEL_JVM_ARGS -Dotel.java.global-autoconfigure.enabled=${SE_OTEL_JAVA_GLOBAL_AUTOCONFIGURE_ENABLED}"
fi
if [ -n "$SE_OTEL_JVM_ARGS" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS ${SE_OTEL_JVM_ARGS}"
fi
else
append_se_opts "--tracing" "false"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Dwebdriver.remote.enableTracing=false"
echo "Tracing is disabled"
fi
if [ -n "${SE_JAVA_HTTPCLIENT_VERSION}" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS -Dwebdriver.httpclient.version=${SE_JAVA_HTTPCLIENT_VERSION}"
fi
if [ -n "${SE_JAVA_OPTS_DEFAULT}" ]; then
SE_JAVA_OPTS="${SE_JAVA_OPTS_DEFAULT} $SE_JAVA_OPTS"
fi
function handle_heap_dump() {
/opt/bin/handle_heap_dump.sh /opt/selenium/logs
}
if [ "${SE_JAVA_HEAP_DUMP}" = "true" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/selenium/logs"
trap handle_heap_dump ERR SIGTERM SIGINT
fi
if [ -n "${JAVA_OPTS}" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS ${JAVA_OPTS}"
fi
echo "Using JAVA_OPTS: ${SE_JAVA_OPTS}"
java ${SE_JAVA_OPTS} \
-jar /opt/selenium/selenium-server.jar \
${EXTRA_LIBS} standalone \
--session-request-timeout ${SE_SESSION_REQUEST_TIMEOUT} \
--session-retry-interval ${SE_SESSION_RETRY_INTERVAL} \
--relax-checks ${SE_RELAX_CHECKS} \
--detect-drivers false \
--bind-host ${SE_BIND_HOST} \
--config ${CONFIG_FILE} \
${SE_GRID_URL} ${SE_OPTS}