diff --git a/Base/Dockerfile b/Base/Dockerfile index bf6d4ffd01..348e845746 100644 --- a/Base/Dockerfile +++ b/Base/Dockerfile @@ -11,6 +11,8 @@ ARG OPENTELEMETRY_VERSION=1.44.1 ARG GRPC_VERSION=1.68.1 ARG NETTY_VERSION=4.1.115.Final ARG CS_VERSION=2.1.18 +ARG POSTGRESQL_VERSION=42.7.4 +ARG MVN_SELENIUM_VERSION=4.27.0 #Arguments to define the user running Selenium ARG SEL_USER=seluser @@ -118,8 +120,16 @@ RUN --mount=type=secret,id=SEL_PASSWD \ && if [ -f "/tmp/cs" ]; then \ java -jar /tmp/cs fetch --classpath --cache /external_jars \ io.opentelemetry:opentelemetry-exporter-otlp:${OPENTELEMETRY_VERSION} \ - io.grpc:grpc-netty:${GRPC_VERSION} io.netty:netty-codec-http:${NETTY_VERSION} > /external_jars/.classpath.txt \ - && chmod 664 /external_jars/.classpath.txt ; \ + io.grpc:grpc-netty:${GRPC_VERSION} \ + io.netty:netty-codec-http:${NETTY_VERSION} \ + > /external_jars/.classpath.txt \ + && chmod 664 /external_jars/.classpath.txt \ + && java -jar /tmp/cs fetch --classpath --cache /external_jars \ + org.seleniumhq.selenium:selenium-session-map-jdbc:${MVN_SELENIUM_VERSION} \ + org.postgresql:postgresql:${POSTGRESQL_VERSION} \ + org.seleniumhq.selenium:selenium-session-map-redis:${MVN_SELENIUM_VERSION} \ + > /external_jars/.classpath_session_map.txt \ + && chmod 664 /external_jars/.classpath_session_map.txt ; \ fi \ && rm -fr /root/.cache/* \ # (Note that .bashrc is only executed in interactive bash shells.) @@ -165,6 +175,8 @@ ENV SE_BIND_HOST=false \ SE_SUPERVISORD_CHILD_LOG_DIR="/tmp" \ SE_SUPERVISORD_LOG_FILE="/tmp/supervisord.log" \ SE_SUPERVISORD_PID_FILE="/tmp/supervisord.pid" \ + SE_SUPERVISORD_AUTO_RESTART=true \ + SE_SUPERVISORD_START_RETRIES=5 \ SE_LOG_TIMESTAMP_FORMAT="%Y-%m-%d %H:%M:%S,%3N" \ SE_LOG_LEVEL="INFO" \ SE_HTTP_LOGS=false \ diff --git a/Distributor/selenium-grid-distributor.conf b/Distributor/selenium-grid-distributor.conf index 0a3dda3163..8bb3e19f06 100644 --- a/Distributor/selenium-grid-distributor.conf +++ b/Distributor/selenium-grid-distributor.conf @@ -5,9 +5,10 @@ priority=0 command=/opt/bin/start-selenium-grid-distributor.sh autostart=true -autorestart=false +autorestart=%(ENV_SE_SUPERVISORD_AUTO_RESTART)s startsecs=0 -startretries=0 +startretries=%(ENV_SE_SUPERVISORD_START_RETRIES)s +stopsignal=TERM ;Logs (all Hub activity redirected to stdout so it can be seen through "docker logs" redirect_stderr=true diff --git a/EventBus/selenium-grid-eventbus.conf b/EventBus/selenium-grid-eventbus.conf index 3e12c746f8..3409e4f4cd 100644 --- a/EventBus/selenium-grid-eventbus.conf +++ b/EventBus/selenium-grid-eventbus.conf @@ -5,9 +5,10 @@ priority=0 command=/opt/bin/start-selenium-grid-eventbus.sh autostart=true -autorestart=false +autorestart=%(ENV_SE_SUPERVISORD_AUTO_RESTART)s startsecs=0 -startretries=0 +startretries=%(ENV_SE_SUPERVISORD_START_RETRIES)s +stopsignal=TERM ;Logs (all Hub activity redirected to stdout so it can be seen through "docker logs" redirect_stderr=true diff --git a/Hub/selenium-grid-hub.conf b/Hub/selenium-grid-hub.conf index bd67dae312..42ffbfef93 100644 --- a/Hub/selenium-grid-hub.conf +++ b/Hub/selenium-grid-hub.conf @@ -5,9 +5,10 @@ priority=0 command=/opt/bin/start-selenium-grid-hub.sh autostart=true -autorestart=false +autorestart=%(ENV_SE_SUPERVISORD_AUTO_RESTART)s startsecs=0 -startretries=0 +startretries=%(ENV_SE_SUPERVISORD_START_RETRIES)s +stopsignal=TERM ;Logs (all Hub activity redirected to stdout so it can be seen through "docker logs" redirect_stderr=true diff --git a/Makefile b/Makefile index d0c4cfdb41..8b33a498d4 100644 --- a/Makefile +++ b/Makefile @@ -917,7 +917,7 @@ chart_test_autoscaling_disabled: ./tests/charts/make/chart_test.sh NoAutoscaling chart_test_autoscaling_deployment_https: - PLATFORMS=$(PLATFORMS) CHART_FULL_DISTRIBUTED_MODE=true CHART_ENABLE_BASIC_AUTH=true \ + PLATFORMS=$(PLATFORMS) CHART_FULL_DISTRIBUTED_MODE=true CHART_ENABLE_BASIC_AUTH=true TEST_EXTERNAL_DATASTORE=postgresql \ SECURE_INGRESS_ONLY_DEFAULT=true INGRESS_DISABLE_USE_HTTP2=true SELENIUM_GRID_PROTOCOL=https CHART_ENABLE_INGRESS_HOSTNAME=true SELENIUM_GRID_PORT=443 \ SELENIUM_GRID_AUTOSCALING_MIN_REPLICA=0 MAX_SESSIONS_FIREFOX=1 MAX_SESSIONS_EDGE=1 MAX_SESSIONS_CHROME=1 TEST_NAME_OVERRIDE=true \ VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) KEDA_BASED_NAME=$(KEDA_BASED_NAME) KEDA_BASED_TAG=$(KEDA_BASED_TAG) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) BASE_VERSION=$(BASE_VERSION) \ @@ -955,7 +955,7 @@ chart_test_autoscaling_job: ./tests/charts/make/chart_test.sh JobAutoscaling chart_test_autoscaling_playwright_connect_grid: - PLATFORMS=$(PLATFORMS) CHART_ENABLE_TRACING=true CHART_ENABLE_BASIC_AUTH=true MATRIX_TESTS=CDPTests \ + PLATFORMS=$(PLATFORMS) CHART_FULL_DISTRIBUTED_MODE=true CHART_ENABLE_BASIC_AUTH=true TEST_EXTERNAL_DATASTORE=redis MATRIX_TESTS=CDPTests \ BASIC_AUTH_USERNAME=docker-selenium BASIC_AUTH_PASSWORD=2NMI4jdBi6k7bENoeUfV25295VvzwAE9chM24a+2VL95uOHozo \ SECURE_INGRESS_ONLY_DEFAULT=true SECURE_USE_EXTERNAL_CERT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -I | cut -d' ' -f1) SELENIUM_GRID_PORT=443 \ VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) KEDA_BASED_NAME=$(KEDA_BASED_NAME) KEDA_BASED_TAG=$(KEDA_BASED_TAG) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) BASE_VERSION=$(BASE_VERSION) \ diff --git a/Router/selenium-grid-router.conf b/Router/selenium-grid-router.conf index a5c3dca905..931857bb4c 100644 --- a/Router/selenium-grid-router.conf +++ b/Router/selenium-grid-router.conf @@ -5,9 +5,10 @@ priority=0 command=/opt/bin/start-selenium-grid-router.sh autostart=true -autorestart=false +autorestart=%(ENV_SE_SUPERVISORD_AUTO_RESTART)s startsecs=0 -startretries=0 +startretries=%(ENV_SE_SUPERVISORD_START_RETRIES)s +stopsignal=TERM ;Logs (all Hub activity redirected to stdout so it can be seen through "docker logs" redirect_stderr=true diff --git a/SessionQueue/selenium-grid-session-queue.conf b/SessionQueue/selenium-grid-session-queue.conf index e82308526e..0511b993c0 100644 --- a/SessionQueue/selenium-grid-session-queue.conf +++ b/SessionQueue/selenium-grid-session-queue.conf @@ -5,9 +5,10 @@ priority=0 command=/opt/bin/start-selenium-grid-session-queue.sh autostart=true -autorestart=false +autorestart=%(ENV_SE_SUPERVISORD_AUTO_RESTART)s startsecs=0 -startretries=0 +startretries=%(ENV_SE_SUPERVISORD_START_RETRIES)s +stopsignal=TERM ;Logs (all Hub activity redirected to stdout so it can be seen through "docker logs" redirect_stderr=true diff --git a/Sessions/Dockerfile b/Sessions/Dockerfile index a9d550a82c..66f7ceed7d 100644 --- a/Sessions/Dockerfile +++ b/Sessions/Dockerfile @@ -4,17 +4,24 @@ FROM ${NAMESPACE}/base:${VERSION} ARG AUTHORS LABEL authors=${AUTHORS} -USER ${SEL_UID} - #======================== # Selenium SessionMap Configuration #======================== -EXPOSE 5556 +USER root -COPY --chown="${SEL_UID}:${SEL_GID}" start-selenium-grid-sessions.sh \ +COPY --chown="${SEL_UID}:${SEL_GID}" start-selenium-grid-sessions.sh generate_config \ /opt/bin/ +RUN chmod +x /opt/bin/start-selenium-grid-sessions.sh /opt/bin/generate_config COPY selenium-grid-sessions.conf /etc/supervisor/conf.d/ -ENV SE_OTEL_SERVICE_NAME="selenium-session-map" +USER ${SEL_UID} + +EXPOSE 5556 + +ENV SE_OTEL_SERVICE_NAME="selenium-session-map" \ + # Path to the Configfile + CONFIG_FILE=/opt/selenium/config.toml \ + GENERATE_CONFIG=true \ + SE_SESSIONS_MAP_EXTERNAL_DATASTORE=false diff --git a/Sessions/generate_config b/Sessions/generate_config new file mode 100755 index 0000000000..7c41aa1085 --- /dev/null +++ b/Sessions/generate_config @@ -0,0 +1,39 @@ +#!/bin/bash + +if [[ -z "$CONFIG_FILE" ]]; then + FILENAME="/opt/selenium/config.toml" +else + FILENAME="$CONFIG_FILE" +fi + +echo "[sessions]" >"$FILENAME" + +if [ "${SE_SESSIONS_MAP_EXTERNAL_DATASTORE}" = "true" ]; then + if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_SCHEME}" ]]; then + echo "scheme = \"${SE_SESSIONS_MAP_EXTERNAL_SCHEME}\"" >>"$FILENAME" + fi + + if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_IMPLEMENTATION}" ]]; then + echo "implementation = \"${SE_SESSIONS_MAP_EXTERNAL_IMPLEMENTATION}\"" >>"$FILENAME" + fi + + if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_HOSTNAME}" ]]; then + echo "hostname = \"${SE_SESSIONS_MAP_EXTERNAL_HOSTNAME}\"" >>"$FILENAME" + fi + + if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_PORT}" ]]; then + echo "port = \"${SE_SESSIONS_MAP_EXTERNAL_PORT}\"" >>"$FILENAME" + fi + + if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_JDBC_URL}" ]]; then + echo "jdbc-url = \"${SE_SESSIONS_MAP_EXTERNAL_JDBC_URL}\"" >>"$FILENAME" + fi + + if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_JDBC_USER}" ]]; then + echo "jdbc-user = \"${SE_SESSIONS_MAP_EXTERNAL_JDBC_USER}\"" >>"$FILENAME" + fi + + if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_JDBC_PASSWORD}" ]]; then + echo "jdbc-password = \"${SE_SESSIONS_MAP_EXTERNAL_JDBC_PASSWORD}\"" >>"$FILENAME" + fi +fi diff --git a/Sessions/init.sql b/Sessions/init.sql new file mode 100644 index 0000000000..989ee55168 --- /dev/null +++ b/Sessions/init.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS sessions_map( + session_ids varchar(256), + session_caps text, + session_uri varchar(256), + session_stereotype text, + session_start varchar(256) + ); diff --git a/Sessions/selenium-grid-sessions.conf b/Sessions/selenium-grid-sessions.conf index a3b9487ad4..8af1e8855b 100644 --- a/Sessions/selenium-grid-sessions.conf +++ b/Sessions/selenium-grid-sessions.conf @@ -5,9 +5,10 @@ priority=0 command=/opt/bin/start-selenium-grid-sessions.sh autostart=true -autorestart=false +autorestart=%(ENV_SE_SUPERVISORD_AUTO_RESTART)s startsecs=0 -startretries=0 +startretries=%(ENV_SE_SUPERVISORD_START_RETRIES)s +stopsignal=TERM ;Logs (all Hub activity redirected to stdout so it can be seen through "docker logs" redirect_stderr=true diff --git a/Sessions/start-selenium-grid-sessions.sh b/Sessions/start-selenium-grid-sessions.sh index db8dfffdb5..b0357269ff 100755 --- a/Sessions/start-selenium-grid-sessions.sh +++ b/Sessions/start-selenium-grid-sessions.sh @@ -3,8 +3,6 @@ # set -e: exit asap if a command exits with a non-zero status set -e -echo "Starting Selenium Grid Sessions..." - function append_se_opts() { local option="${1}" local value="${2:-""}" @@ -98,12 +96,21 @@ if [ ! -z "$SE_REGISTRATION_SECRET" ]; then append_se_opts "--registration-secret" "${SE_REGISTRATION_SECRET}" "false" fi +if [ "$GENERATE_CONFIG" = true ]; then + echo "Generating Selenium Config for Sessions" + /opt/bin/generate_config +fi + +if [ ! -z "${CONFIG_FILE}" ]; then + append_se_opts "--config" "${CONFIG_FILE}" +fi + EXTRA_LIBS="" if [ "$SE_ENABLE_TRACING" = "true" ]; then EXTERNAL_JARS=$(