Skip to content

Commit 677168f

Browse files
authored
[build][doc]: build images with combination Grid and browser versions (#2218)
1 parent 4c572af commit 677168f

File tree

8 files changed

+368
-3
lines changed

8 files changed

+368
-3
lines changed

NodeChrome/Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ ARG TARGETARCH=amd64
1919
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor | tee /etc/apt/trusted.gpg.d/google.gpg >/dev/null \
2020
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
2121
&& apt-get update -qqy \
22-
&& if echo "${CHROME_VERSION}" | grep -qE "google-chrome-stable_[0-9]*"; \
22+
&& if echo "${CHROME_VERSION}" | grep -qE "google-chrome-stable[_|=][0-9]*"; \
2323
then \
24-
wget -qO google-chrome.deb "https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/${CHROME_VERSION}_${TARGETARCH}.deb" \
24+
CHROME_VERSION=$(echo "$CHROME_VERSION" | tr '=' '_') \
25+
&& wget -qO google-chrome.deb "https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/${CHROME_VERSION}_${TARGETARCH}.deb" \
2526
&& apt-get -qqy --no-install-recommends install --allow-downgrades ./google-chrome.deb \
2627
&& rm -rf google-chrome.deb ; \
2728
else \

NodeEdge/Dockerfile

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ USER root
1313
# e.g. microsoft-edge-beta=88.0.692.0-1
1414
#============================================
1515
ARG EDGE_VERSION="microsoft-edge-stable"
16+
ARG TARGETARCH=amd64
1617
RUN wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg >/dev/null \
1718
&& echo "deb https://packages.microsoft.com/repos/edge stable main" >> /etc/apt/sources.list.d/microsoft-edge.list \
1819
&& apt-get update -qqy \
19-
&& apt-get -qqy --no-install-recommends install ${EDGE_VERSION} \
20+
&& if echo "${EDGE_VERSION}" | grep -qE "microsoft-edge-stable[_|=][0-9]*"; \
21+
then \
22+
EDGE_VERSION=$(echo "$EDGE_VERSION" | tr '=' '_') \
23+
&& wget -qO microsoft-edge.deb "https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/${EDGE_VERSION}_${TARGETARCH}.deb" \
24+
&& apt-get -qqy --no-install-recommends install --allow-downgrades ./microsoft-edge.deb \
25+
&& rm -rf microsoft-edge.deb ; \
26+
else \
27+
apt-get -qqy --no-install-recommends install ${EDGE_VERSION} ; \
28+
fi \
2029
&& rm /etc/apt/sources.list.d/microsoft-edge.list \
2130
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
2231

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Talk to us at https://www.selenium.dev/support/
6363
* [Stopping the Node/Standalone after N sessions have been executed](#stopping-the-nodestandalone-after-n-sessions-have-been-executed)
6464
* [Automatic browser leftovers cleanup](#automatic-browser-leftovers-cleanup)
6565
* [Building the images](#building-the-images)
66+
* [Build the images with specific versions](#build-the-images-with-specific-versions)
67+
* [Upgrade browser version in the images](#upgrade-browser-version-in-the-images)
6668
* [Waiting for the Grid to be ready](#waiting-for-the-grid-to-be-ready)
6769
* [Adding a HEALTHCHECK to the Grid](#adding-a-healthcheck-to-the-grid)
6870
* [Using a bash script to wait for the Grid](#using-a-bash-script-to-wait-for-the-grid)
@@ -1027,6 +1029,33 @@ $ BUILD_ARGS="--build-arg SEL_USER=yourseluser --build-arg SEL_PASSWD=welcome" m
10271029
```
10281030
___
10291031

1032+
# Build the images with specific versions
1033+
1034+
Based on the latest Dockerfile (by cloning the repo and from the project directory root), you can build the images with a specific combination of Selenium Grid, and browser versions.
1035+
1036+
For example, you would like to build `node-chrome` and `standalone-chrome` images with the Grid based version `4.17.0`, Chrome browser versions `119`, `120`, `123` respectively.
1037+
1038+
```bash
1039+
$ ./tests/build-backward-compatible/bootstrap.sh 4.17.0 119,120,123 chrome
1040+
```
1041+
1042+
In generic, the script takes the following arguments:
1043+
- `$1` (mandatory): Selenium Grid version. Details are fetching from matrix [file](tests/build-backward-compatible/selenium-matrix.yml)
1044+
- `$2` (mandatory): Browser major version, multiple values separated by comma. Details are fetching from matrix [file](tests/build-backward-compatible/cdp-matrix.yml)
1045+
- `$3` (optional): browser name. If not provided, it will iterate over all the browsers (`chrome`, `edge`, `firefox`)
1046+
- `$4` (optional): Push image to registry. By default, it is `false`. If you want to push the image to the registry, set it to `true` (required Docker login to your namespace done before running the script).
1047+
1048+
To set your namespace for the images, you can set the environment variable `NAME` before running the script. For example:
1049+
1050+
```bash
1051+
$ export NAME=artifactory.yourcompany.com/selenium
1052+
$ ./tests/build-backward-compatible/bootstrap.sh 4.17.0 119,120,123 chrome
1053+
```
1054+
1055+
After running the script, you will see list images with a full tag to pin specific Grid and browser version following [Tagging Conventions](https://github.com/SeleniumHQ/docker-selenium/wiki/Tagging-Convention)
1056+
1057+
---
1058+
10301059
## Upgrade browser version in the images
10311060

10321061
Selenium server, browser and driver are pre-installed in the image. In case you would like to remain on the same Selenium version and just upgrade the browser and its driver to the latest. You can follow below steps

tag_and_push_browser_images.sh

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ chrome)
5757
do
5858
docker tag ${NAMESPACE}/node-chrome:${TAG_VERSION} ${NAMESPACE}/node-chrome:${chrome_tag}
5959
docker tag ${NAMESPACE}/standalone-chrome:${TAG_VERSION} ${NAMESPACE}/standalone-chrome:${chrome_tag}
60+
echo "Tagged ${NAMESPACE}/node-chrome:${chrome_tag}"
61+
echo "Tagged ${NAMESPACE}/standalone-chrome:${chrome_tag}"
6062
if [ "${PUSH_IMAGE}" = true ]; then
6163
docker push ${NAMESPACE}/node-chrome:${chrome_tag}
6264
docker push ${NAMESPACE}/standalone-chrome:${chrome_tag}
@@ -101,6 +103,8 @@ edge)
101103
do
102104
docker tag ${NAMESPACE}/node-edge:${TAG_VERSION} ${NAMESPACE}/node-edge:${edge_tag}
103105
docker tag ${NAMESPACE}/standalone-edge:${TAG_VERSION} ${NAMESPACE}/standalone-edge:${edge_tag}
106+
echo "Tagged ${NAMESPACE}/node-edge:${edge_tag}"
107+
echo "Tagged ${NAMESPACE}/standalone-edge:${edge_tag}"
104108
if [ "${PUSH_IMAGE}" = true ]; then
105109
docker push ${NAMESPACE}/node-edge:${edge_tag}
106110
docker push ${NAMESPACE}/standalone-edge:${edge_tag}
@@ -144,6 +148,8 @@ firefox)
144148
do
145149
docker tag ${NAMESPACE}/node-firefox:${TAG_VERSION} ${NAMESPACE}/node-firefox:${firefox_tag}
146150
docker tag ${NAMESPACE}/standalone-firefox:${TAG_VERSION} ${NAMESPACE}/standalone-firefox:${firefox_tag}
151+
echo "Tagged ${NAMESPACE}/node-firefox:${firefox_tag}"
152+
echo "Tagged ${NAMESPACE}/standalone-firefox:${firefox_tag}"
147153
if [ "${PUSH_IMAGE}" = true ]; then
148154
docker push ${NAMESPACE}/node-firefox:${firefox_tag}
149155
docker push ${NAMESPACE}/standalone-firefox:${firefox_tag}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
cd tests || true
3+
4+
if [ "${CI:-false}" = "false" ]; then
5+
pip3 install virtualenv | grep -v 'Requirement already satisfied'
6+
virtualenv docker-selenium-tests
7+
source docker-selenium-tests/bin/activate
8+
fi
9+
10+
python -m pip install pyyaml==6.0.1 \
11+
| grep -v 'Requirement already satisfied'
12+
13+
cd ..
14+
15+
SELENIUM_VERSION=$1
16+
CDP_VERSIONS=$2
17+
BROWSER=${3:-"all"}
18+
PUSH_IMAGE=${4:-"false"}
19+
20+
IFS=',' read -ra VERSION_LIST <<< "$CDP_VERSIONS"
21+
22+
for CDP_VERSION in "${VERSION_LIST[@]}"; do
23+
python tests/build-backward-compatible/builder.py ${SELENIUM_VERSION} ${CDP_VERSION}
24+
export $(cat .env | xargs)
25+
if [ "${BROWSER}" = "all" ] || [ "${BROWSER}" = "firefox" ]; then
26+
if [ -n "${FIREFOX_VERSION}" ]; then
27+
BUILD_ARGS="--build-arg FIREFOX_VERSION=${FIREFOX_VERSION}"
28+
BUILD_ARGS="${BUILD_ARGS}" make standalone_firefox
29+
else
30+
echo "Firefox version not found in matrix for input ${CDP_VERSION}"
31+
exit 1
32+
fi
33+
fi
34+
if [ "${BROWSER}" = "all" ] || [ "${BROWSER}" = "edge" ]; then
35+
if [ -n "${EDGE_VERSION}" ]; then
36+
BUILD_ARGS="--build-arg EDGE_VERSION=${EDGE_VERSION}"
37+
BUILD_ARGS="${BUILD_ARGS}" make standalone_edge
38+
else
39+
echo "Edge version not found in matrix for input ${CDP_VERSION}"
40+
exit 1
41+
fi
42+
fi
43+
if [ "${BROWSER}" = "all" ] || [ "${BROWSER}" = "chrome" ]; then
44+
if [ -n "${CHROME_VERSION}" ]; then
45+
BUILD_ARGS="--build-arg CHROME_VERSION=${CHROME_VERSION}"
46+
BUILD_ARGS="${BUILD_ARGS}" make standalone_chrome
47+
else
48+
echo "Chrome version not found in matrix for input ${CDP_VERSION}"
49+
exit 1
50+
fi
51+
fi
52+
if [ "${BROWSER}" = "all" ] || [ "${BROWSER}" = "firefox" ]; then
53+
TAG_LOG_OUTPUT="$TAG_LOG_OUTPUT $(PUSH_IMAGE=${PUSH_IMAGE} make tag_and_push_firefox_images)"
54+
fi
55+
if [ "${BROWSER}" = "all" ] || [ "${BROWSER}" = "edge" ]; then
56+
TAG_LOG_OUTPUT="$TAG_LOG_OUTPUT $(PUSH_IMAGE=${PUSH_IMAGE} make tag_and_push_edge_images)"
57+
fi
58+
if [ "${BROWSER}" = "all" ] || [ "${BROWSER}" = "chrome" ]; then
59+
TAG_LOG_OUTPUT="$TAG_LOG_OUTPUT $(PUSH_IMAGE=${PUSH_IMAGE} make tag_and_push_chrome_images)"
60+
fi
61+
done
62+
63+
readarray -t LOG_LINES <<< "$TAG_LOG_OUTPUT"
64+
for line in "${LOG_LINES[@]}"; do
65+
echo "$line"
66+
done
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import yaml
2+
import sys
3+
import logging
4+
5+
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
6+
logger = logging.getLogger(__name__)
7+
8+
def load_template(yaml_file):
9+
try:
10+
with open(yaml_file, 'r') as file:
11+
documents = yaml.safe_load(file)
12+
return documents
13+
except yaml.YAMLError as error:
14+
logger.debug("Error in configuration file: ", error)
15+
16+
def recursive_merge(dict1, dict2):
17+
for key in dict2:
18+
if key in dict1 and isinstance(dict1[key], dict) and isinstance(dict2[key], dict):
19+
recursive_merge(dict1[key], dict2[key])
20+
else:
21+
dict1[key] = dict2[key]
22+
23+
if __name__ == '__main__':
24+
# Load matrix configuration
25+
selenium_matrix = load_template('tests/build-backward-compatible/selenium-matrix.yml')
26+
cdp_matrix = load_template('tests/build-backward-compatible/cdp-matrix.yml')
27+
# Merge configurations into single matrix
28+
recursive_merge(selenium_matrix, cdp_matrix)
29+
matrix = selenium_matrix["matrix"]
30+
# Get versions from arguments
31+
selenium_version = sys.argv[1]
32+
cdp_version = int(sys.argv[2])
33+
# Create .env with component versions
34+
BASE_RELEASE = matrix["selenium"][selenium_version]["BASE_RELEASE"]
35+
BASE_VERSION = matrix["selenium"][selenium_version]["BASE_VERSION"]
36+
VERSION = matrix["selenium"][selenium_version]["VERSION"]
37+
BINDING_VERSION = matrix["selenium"][selenium_version]["BINDING_VERSION"]
38+
FIREFOX_VERSION = matrix["CDP"][cdp_version]["FIREFOX_VERSION"]
39+
EDGE_VERSION = matrix["CDP"][cdp_version]["EDGE_VERSION"]
40+
CHROME_VERSION = matrix["CDP"][cdp_version]["CHROME_VERSION"]
41+
with open('.env', 'w') as f:
42+
f.write(f"BASE_RELEASE={BASE_RELEASE}\n")
43+
f.write(f"BASE_VERSION={BASE_VERSION}\n")
44+
f.write(f"VERSION={VERSION}\n")
45+
f.write(f"BINDING_VERSION={BINDING_VERSION}\n")
46+
f.write(f"FIREFOX_VERSION={FIREFOX_VERSION}\n")
47+
f.write(f"EDGE_VERSION={EDGE_VERSION}\n")
48+
f.write(f"CHROME_VERSION={CHROME_VERSION}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
matrix:
2+
# List of versions get from
3+
# Edge: https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable
4+
# Chrome: https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-stable
5+
# Firefox: https://download-installer.cdn.mozilla.net/pub/firefox/releases
6+
CDP:
7+
124:
8+
EDGE_VERSION: 'microsoft-edge-stable=124.0.2478.51-1'
9+
CHROME_VERSION: 'google-chrome-stable=124.0.6367.60-1'
10+
FIREFOX_VERSION: '124.0.2'
11+
123:
12+
EDGE_VERSION: 'microsoft-edge-stable=123.0.2420.97-1'
13+
CHROME_VERSION: 'google-chrome-stable=123.0.6312.122-1'
14+
FIREFOX_VERSION: '123.0.1'
15+
122:
16+
EDGE_VERSION: 'microsoft-edge-stable=122.0.2365.92-1'
17+
CHROME_VERSION: 'google-chrome-stable=122.0.6261.128-1'
18+
FIREFOX_VERSION: '122.0.1'
19+
121:
20+
EDGE_VERSION: 'microsoft-edge-stable=121.0.2277.98-1'
21+
CHROME_VERSION: 'google-chrome-stable=121.0.6167.184-1'
22+
FIREFOX_VERSION: '121.0.1'
23+
120:
24+
EDGE_VERSION: 'microsoft-edge-stable=120.0.2210.91-1'
25+
CHROME_VERSION: 'google-chrome-stable=120.0.6099.224-1'
26+
FIREFOX_VERSION: '120.0.1'
27+
119:
28+
EDGE_VERSION: 'microsoft-edge-stable=119.0.2151.97-1'
29+
CHROME_VERSION: 'google-chrome-stable=119.0.6045.199-1'
30+
FIREFOX_VERSION: '119.0.1'
31+
118:
32+
EDGE_VERSION: 'microsoft-edge-stable=118.0.2088.76-1'
33+
CHROME_VERSION: 'google-chrome-stable=118.0.5993.117-1'
34+
FIREFOX_VERSION: '118.0.2'
35+
117:
36+
EDGE_VERSION: 'microsoft-edge-stable=117.0.2045.55-1'
37+
CHROME_VERSION: 'google-chrome-stable=117.0.5938.149-1'
38+
FIREFOX_VERSION: '117.0.1'
39+
116:
40+
EDGE_VERSION: 'microsoft-edge-stable=116.0.1938.81-1'
41+
CHROME_VERSION: 'google-chrome-stable=116.0.5845.187-1'
42+
FIREFOX_VERSION: '116.0.3'
43+
115:
44+
EDGE_VERSION: 'microsoft-edge-stable=115.0.1901.203-1'
45+
CHROME_VERSION: 'google-chrome-stable=115.0.5790.170-1'
46+
FIREFOX_VERSION: '115.0.3'
47+
114:
48+
EDGE_VERSION: 'microsoft-edge-stable=114.0.1823.82-1'
49+
CHROME_VERSION: 'google-chrome-stable=114.0.5735.198-1'
50+
FIREFOX_VERSION: '114.0.2'
51+
113:
52+
EDGE_VERSION: 'microsoft-edge-stable=113.0.1774.57-1'
53+
CHROME_VERSION: 'google-chrome-stable=113.0.5672.126-1'
54+
FIREFOX_VERSION: '113.0.2'
55+
112:
56+
EDGE_VERSION: 'microsoft-edge-stable=112.0.1722.64-1'
57+
CHROME_VERSION: 'google-chrome-stable=112.0.5615.165-1'
58+
FIREFOX_VERSION: '112.0.2'

0 commit comments

Comments
 (0)