-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathgenerate_config
executable file
·93 lines (83 loc) · 3.44 KB
/
generate_config
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
#!/bin/bash
function short_version() {
local __long_version=$1
local __version_split=(${__long_version//./ })
local __major=${__version_split[0]}
local __minor=${__version_split[1]}
echo "${__major}.${__minor:0:1}"
}
if [[ -z "$CONFIG_FILE" ]]; then
FILENAME="/opt/selenium/config.toml"
else
FILENAME="$CONFIG_FILE"
fi
if [[ -n "${SE_EVENT_BUS_HOST}" ]]; then
echo "[events]
publish = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}\"
subscribe = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}\"
" >"$FILENAME"
fi
if [[ -z "${SE_NODE_HOST}" ]] && [[ -z "${SE_NODE_PORT}" ]]; then
echo "Configuring server..."
else
echo "[server]" >>"$FILENAME"
fi
if [[ -z "${SE_NODE_HOST}" ]]; then
echo "Setting up SE_NODE_HOST..."
else
echo "host = \"${SE_NODE_HOST}\"" >>"$FILENAME"
fi
if [[ -z "${SE_NODE_PORT}" ]]; then
echo "Setting up SE_NODE_PORT..."
else
echo "port = \"${SE_NODE_PORT}\"" >>"$FILENAME"
fi
echo "[node]" >>"$FILENAME"
# String, Url where the Grid can be reached
if [[ -z "${SE_NODE_GRID_URL}" ]]; then
echo "Setting up SE_NODE_GRID_URL..."
else
echo "grid-url = \"${SE_NODE_GRID_URL}\"" >>"$FILENAME"
fi
echo "session-timeout = ${SE_NODE_SESSION_TIMEOUT}" >>"$FILENAME"
echo "override-max-sessions = ${SE_NODE_OVERRIDE_MAX_SESSIONS}" >>"$FILENAME"
echo "detect-drivers = false" >>"$FILENAME"
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT:-$SE_DRAIN_AFTER_SESSION_COUNT}" >>"$FILENAME"
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
" >>"$FILENAME"
if [ -f /opt/selenium/browser_name ]; then
SE_NODE_BROWSER_NAME=$(cat /opt/selenium/browser_name)
fi
if [ -f /opt/selenium/browser_version ] && [ "${SE_NODE_BROWSER_VERSION,,}" = "stable" ]; then
SE_NODE_BROWSER_VERSION=$(short_version $(cat /opt/selenium/browser_version))
fi
if [ -f /opt/selenium/browser_binary_location ] && [ -z "${SE_BROWSER_BINARY_LOCATION}" ]; then
SE_BROWSER_BINARY_LOCATION=$(cat /opt/selenium/browser_binary_location)
fi
SE_NODE_CONTAINER_NAME="${SE_NODE_CONTAINER_NAME:-$(hostname)}"
# 'browserName' is mandatory for default stereotype
if [[ -z "${SE_NODE_STEREOTYPE}" ]] && [[ -n "${SE_NODE_BROWSER_NAME}" ]] && ([[ -z "${SE_NODE_RELAY_URL}" ]] || [[ "${SE_NODE_RELAY_ONLY}" = "false" ]]); then
SE_NODE_STEREOTYPE="{\"browserName\": \"${SE_NODE_BROWSER_NAME}\", \"browserVersion\": \"${SE_NODE_BROWSER_VERSION}\", \"platformName\": \"${SE_NODE_PLATFORM_NAME}\", \"se:containerName\": \"${SE_NODE_CONTAINER_NAME}\", \"container:hostname\": \"$(hostname)\"}"
if [[ -n "${SE_BROWSER_BINARY_LOCATION}" ]]; then
SE_NODE_STEREOTYPE="$(python3 /opt/bin/json_merge.py "${SE_NODE_STEREOTYPE}" "{${SE_BROWSER_BINARY_LOCATION}}")"
fi
else
SE_NODE_STEREOTYPE="${SE_NODE_STEREOTYPE}"
fi
if [[ -n "${SE_NODE_STEREOTYPE_EXTRA}" ]]; then
echo "Merging SE_NODE_STEREOTYPE_EXTRA=${SE_NODE_STEREOTYPE_EXTRA} to main stereotype"
SE_NODE_STEREOTYPE="$(python3 /opt/bin/json_merge.py "${SE_NODE_STEREOTYPE}" "${SE_NODE_STEREOTYPE_EXTRA}")"
if [[ $? -ne 0 ]]; then
echo "Failed to merge SE_NODE_STEREOTYPE_EXTRA. Please check the format of the JSON string. Keep using main stereotype."
else
echo "Merged stereotype: ${SE_NODE_STEREOTYPE}"
fi
fi
# 'stereotype' setting is mandatory
if [[ -n "${SE_NODE_STEREOTYPE}" ]]; then
echo "[[node.driver-configuration]]" >>"$FILENAME"
echo "display-name = \"${SE_NODE_BROWSER_NAME}\"" >>"$FILENAME"
echo "stereotype = '${SE_NODE_STEREOTYPE}'" >>"$FILENAME"
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
" >>"$FILENAME"
fi