Skip to content

Commit 048e2e3

Browse files
authored
Adding drain after sessions flag (#1559)
[deploy]
1 parent c61e4e9 commit 048e2e3

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

NodeBase/Dockerfile.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ ENV START_NO_VNC true
165165
# Path to the Configfile
166166
ENV CONFIG_FILE=/opt/selenium/config.toml
167167
ENV GENERATE_CONFIG true
168+
# Drain the Node after N sessions.
169+
# A value higher than zero enables the feature
170+
ENV DRAIN_AFTER_SESSION_COUNT 0
168171

169172
#========================
170173
# Selenium Configuration

NodeBase/generate_config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fi
4646
echo "session-timeout = \"${SE_NODE_SESSION_TIMEOUT}\"" >> "$FILENAME"
4747
echo "override-max-sessions = ${SE_NODE_OVERRIDE_MAX_SESSIONS}" >> "$FILENAME"
4848
echo "detect-drivers = false" >> "$FILENAME"
49+
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT}" >> "$FILENAME"
4950
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
5051
" >> "$FILENAME"
5152

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ variables.
602602
Here is an example with the default values of these environment variables:
603603

604604
```bash
605-
$ docker run -d -e SE_EVENT_BUS_HOST=<event_bus_ip|event_bus_name> -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 --shm-size="2g" selenium/node-chrome:4.1.3-20220427
605+
$ docker run -d -e SE_EVENT_BUS_HOST=<event_bus_ip|event_bus_name> -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
606+
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 --shm-size="2g" selenium/node-chrome:4.1.3-20220427
606607
```
607608

608609
### Setting Screen Resolution
@@ -612,7 +613,7 @@ These settings can be adjusted by specifying `SCREEN_WIDTH`, `SCREEN_HEIGHT`, `S
612613
environmental variables when starting the container.
613614

614615
``` bash
615-
docker run -d -e SCREEN_WIDTH=1366 -e SCREEN_HEIGHT=768 -e SCREEN_DEPTH=24 -e SCREEN_DPI=74 selenium/standalone-firefox
616+
docker run -d -e SCREEN_WIDTH=1366 -e SCREEN_HEIGHT=768 -e SCREEN_DEPTH=24 -e SCREEN_DPI=74 selenium/standalone-firefox:4.1.3-20220427
616617
```
617618

618619
### Grid Url and Session Timeout
@@ -661,10 +662,25 @@ To avoid starting the server you can set the `START_XVFB` environment variable t
661662
(or any other value than `true`), for example:
662663

663664
``` bash
664-
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -e START_XVFB=false --shm-size="2g" selenium/node-chrome
665+
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
666+
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -e START_XVFB=false --shm-size="2g" selenium/node-chrome:4.1.3-20220427
665667
```
666668

667669
For more information, see this GitHub [issue](https://github.com/SeleniumHQ/docker-selenium/issues/567).
670+
671+
### Stopping the Node/Standalone after N sessions have been executed
672+
673+
In some environments, like Docker Swarm or Kubernetes, it is useful to shut down the Node or Standalone
674+
container after N tests have been executed. For example, this can be used in Kubernetes to terminate the
675+
pod and then scale a new one after N sessions. Set the environment variable `DRAIN_AFTER_SESSION_COUNT` to
676+
a value higher than zero to enable this behaviour.
677+
678+
``` bash
679+
$ docker run -e DRAIN_AFTER_SESSION_COUNT=5 --shm-size="2g" selenium/standalone-firefox:4.1.3-20220427
680+
```
681+
682+
With the previous command, the Standalone container will shutdown after 5 sessions have been executed.
683+
668684
___
669685

670686
## Building the images

Standalone/generate_config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fi
2626
echo "session-timeout = \"${SE_NODE_SESSION_TIMEOUT}\"" >> "$FILENAME"
2727
echo "override-max-sessions = ${SE_NODE_OVERRIDE_MAX_SESSIONS}" >> "$FILENAME"
2828
echo "detect-drivers = false" >> "$FILENAME"
29+
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT}" >> "$FILENAME"
2930
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
3031
" >> "$FILENAME"
3132

0 commit comments

Comments
 (0)