Skip to content

Commit d6dc849

Browse files
authored
HUB_HOST and HUB_PORT to handle hub and nodes (SeleniumHQ#640)
* Introducing HUB_HOST and HUB_PORT to start deprecating HUB_PORT_4444_TCP_ADDR and HUB_PORT_4444_TCP_PORT, in favor of the future deprecation of links in docker. * Updating main README to introduce HUB_HOST, HUB_PORT and more ways to start a grid.
1 parent 7864ac4 commit d6dc849

File tree

3 files changed

+107
-7
lines changed

3 files changed

+107
-7
lines changed

NodeBase/entry_point.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ if [ ! -e /opt/selenium/config.json ]; then
1010
exit 1
1111
fi
1212

13+
# In the long term the idea is to remove $HUB_PORT_4444_TCP_ADDR and $HUB_PORT_4444_TCP_PORT and only work with
14+
# $HUB_HOST and $HUB_PORT
15+
if [ ! -z "$HUB_HOST" ]; then
16+
HUB_PORT_PARAM=4444
17+
if [ ! -z "$HUB_PORT" ]; then
18+
HUB_PORT_PARAM=${HUB_PORT}
19+
fi
20+
echo "Connecting to the Hub using the host ${HUB_HOST} and port ${HUB_PORT_PARAM}"
21+
HUB_PORT_4444_TCP_ADDR=${HUB_HOST}
22+
HUB_PORT_4444_TCP_PORT=${HUB_PORT_PARAM}
23+
fi
24+
1325
if [ -z "$HUB_PORT_4444_TCP_ADDR" ]; then
14-
echo Not linked with a running Hub container 1>&2
26+
echo "Not linked with a running Hub container" 1>&2
1527
exit 1
1628
fi
1729

NodeDebug/entry_point.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ if [ ! -e /opt/selenium/config.json ]; then
1212
exit 1
1313
fi
1414

15+
# In the long term the idea is to remove $HUB_PORT_4444_TCP_ADDR and $HUB_PORT_4444_TCP_PORT and only work with
16+
# $HUB_HOST and $HUB_PORT
17+
if [ ! -z "$HUB_HOST" ]; then
18+
HUB_PORT_PARAM=4444
19+
if [ ! -z "$HUB_PORT" ]; then
20+
HUB_PORT_PARAM=${HUB_PORT}
21+
fi
22+
echo "Connecting to the Hub using the host ${HUB_HOST} and port ${HUB_PORT_PARAM}"
23+
HUB_PORT_4444_TCP_ADDR=${HUB_HOST}
24+
HUB_PORT_4444_TCP_PORT=${HUB_PORT_PARAM}
25+
fi
26+
1527
if [ -z "$HUB_PORT_4444_TCP_ADDR" ]; then
16-
echo Not linked with a running Hub container 1>&2
28+
echo "Not linked with a running Hub container" 1>&2
1729
exit 1
1830
fi
1931

README.md

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ $ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-firefox:3.
4141
#OR
4242
$ docker run -d -p 4444:4444 --shm-size 2g selenium/standalone-firefox:3.8.1-bohrium
4343
```
44-
This is a known workaround to avoid the browser crashing inside a docker container, here are the documented issues for [Chrome](https://code.google.com/p/chromium/issues/detail?id=519952) and [Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1338771#c10). The shm size of 2gb is arbitrary but known to work well, your specific use case might need a different value, it is recommended to tune this value according to your needs. Along the examples `-v /dev/shm:/dev/shm` will be used, but both are known to work.
44+
This is a known workaround to avoid the browser crashing inside a docker container, here are the documented issues for
45+
[Chrome](https://code.google.com/p/chromium/issues/detail?id=519952) and [Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1338771#c10).
46+
The shm size of 2gb is arbitrary but known to work well, your specific use case might need a different value, it is recommended
47+
to tune this value according to your needs. Along the examples `-v /dev/shm:/dev/shm` will be used, but both are known to work.
4548

4649

4750
### Standalone Chrome and Firefox
@@ -57,6 +60,68 @@ _Note: Only one standalone image can run on port_ `4444` _at a time._
5760
To inspect visually what the browser is doing use the `standalone-chrome-debug` or `standalone-firefox-debug` images. See [Debugging](#debugging) section for details.
5861

5962
### Selenium Grid Hub and Nodes
63+
There are different ways to run the images and create a grid, check the following options.
64+
65+
#### Using docker networking
66+
With this option, the hub and nodes will be created in the same network and they will recognize each other by their container name.
67+
A docker [network](https://docs.docker.com/engine/reference/commandline/network_create/) needs to be created as a first step.
68+
69+
``` bash
70+
$ docker network create grid
71+
$ docker run -d -p 4444:4444 --net grid --name selenium-hub selenium/hub:3.8.1-bohrium
72+
$ docker run -d --net grid -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm selenium/node-chrome:3.8.1-bohrium
73+
$ docker run -d --net grid -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm selenium/node-firefox:3.8.1-bohrium
74+
```
75+
76+
When you are done using the grid and the containers have exited, the network can be removed with the following command:
77+
78+
``` bash
79+
# Remove all unused networks
80+
$ docker network prune
81+
# OR
82+
# Removes the grid network
83+
$ docker network rm grid
84+
```
85+
86+
#### Via docker-compose
87+
The most simple way to start a grid is with [docker-compose](https://docs.docker.com/compose/overview/), use the following
88+
snippet as your `docker-compose.yaml`, save it locally and in the same folder run `docker-compose up`.
89+
90+
```yaml
91+
# To execute this docker-compose yml file use docker-compose -f <file_name> up
92+
# Add the "-d" flag at the end for deattached execution
93+
version: '2'
94+
services:
95+
firefox:
96+
image: selenium/node-firefox:3.8.1-bohrium
97+
volumes:
98+
- /dev/shm:/dev/shm
99+
depends_on:
100+
- hub
101+
environment:
102+
HUB_HOST: hub
103+
104+
chrome:
105+
image: selenium/node-chrome:3.8.1-bohrium
106+
volumes:
107+
- /dev/shm:/dev/shm
108+
depends_on:
109+
- hub
110+
environment:
111+
HUB_HOST: hub
112+
113+
hub:
114+
image: selenium/hub:3.8.1-bohrium
115+
ports:
116+
- "4444:4444"
117+
```
118+
119+
To stop the grid and cleanup the created containers, run `docker-compose down`.
120+
121+
#### Using `--link`
122+
This option can be used for a single host scenario (hub and nodes running in a single machine), but it is not recommended
123+
for longer term usage since this is a a docker [legacy feature](https://docs.docker.com/compose/compose-file/#links).
124+
It could serve you as an option for a proof of concept, and for simplicity it is used in the examples shown from now on.
60125

61126
``` bash
62127
$ docker run -d -p 4444:4444 --name selenium-hub selenium/hub:3.8.1-bohrium
@@ -82,13 +147,24 @@ You can pass `SE_OPTS` variable with additional commandline parameters for start
82147
$ docker run -d -p 4444:4444 -e SE_OPTS="-debug true" --name selenium-hub selenium/hub:3.8.1-bohrium
83148
```
84149

85-
### HUB_PORT_4444_TCP_ADDR and HUB_PORT_4444_TCP_PORT Selenium Node Configuration options
150+
### Selenium Hub and Node Configuration options
151+
152+
For special network configurations or when the hub and the nodes are running on different machines `HUB_HOST` and `HUB_PORT`
153+
or `REMOTE_HOST` can be used.
154+
155+
You can pass the `HUB_HOST` and `HUB_PORT` options to provide the hub address to a node when needed.
156+
157+
``` bash
158+
# Assuming a hub was already started
159+
$ docker run -d -e HUB_HOST=<hub_ip|hub_name> -e HUB_PORT=4444 selenium/node-chrome:3.8.1-bohrium
160+
```
86161

87-
You can pass `HUB_PORT_4444_TCP_ADDR` and `HUB_PORT_4444_TCP_PORT` options to provide the hub address to a node when needed.
162+
Some network topologies might prevent the hub to reach the node through the url given at registration time, `REMOTE_HOST`
163+
can be used to supply the hub a url where the node is reachable under your specific network configuration
88164

89165
``` bash
90-
$ docker run -d -p 4444:4444 -e HUB_PORT_4444_TCP_ADDR=10.10.1.10 -e HUB_PORT_4444_TCP_PORT=4444 \
91-
--name selenium-hub selenium/node-chrome:3.8.1-bohrium
166+
# Assuming a hub was already started
167+
$ docker run -d -e HUB_HOST=<hub_ip|hub_name> -e REMOTE_HOST="http://node_ip|node_name:node_port" selenium/node-firefox:3.8.1-bohrium
92168
```
93169

94170
## Building the images

0 commit comments

Comments
 (0)