Skip to content

Commit d8b7251

Browse files
authored
Docker: Env var flag to upgrade latest version of Chrome and ChromeDriver (#2872)
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent 89707bf commit d8b7251

File tree

10 files changed

+208
-41
lines changed

10 files changed

+208
-41
lines changed

ENV_VARIABLES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,4 @@
153153
| SE_VIDEO_CRF | | | |
154154
| SE_VIDEO_MAXRATE | | | |
155155
| SE_NODE_DELETE_SESSION_ON_UI | true | Enable capability to support deleting session on Grid UI | --delete-session-on-ui |
156+
| SE_UPDATE_CHROME_COMPONENTS | | Applicable for node-chrome, standalone-chrome (arch linux/amd64). Update the latest version of Chrome and ChromeDriver at the beginning of the container startup. Read more: [#2872](https://github.com/SeleniumHQ/docker-selenium/pull/2872) | |

NodeBase/start-selenium-node.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22

3+
# Check if Chrome components update is enabled
4+
if [ "${SE_UPDATE_CHROME_COMPONENTS}" = "true" ] && [ -f /opt/bin/update-chrome-components.sh ]; then
5+
echo "Chrome components update enabled, checking for updates..."
6+
echo "Note that after the container gets restarted, updated binaries will be lost unless you call the update script within the build container process."
7+
/opt/bin/update-chrome-components.sh
8+
fi
9+
310
# Start the pulseaudio server
411
pulseaudio -D --exit-idle-time=-1
512

NodeChrome/Dockerfile

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,16 @@ USER root
1616
# google-chrome-unstable
1717
#============================================
1818
ARG CHROME_VERSION="google-chrome-stable"
19-
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 \
20-
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
21-
&& apt-get update -qqy \
22-
&& if echo "${CHROME_VERSION}" | grep -qE "google-chrome-stable[_|=][0-9]*"; \
23-
then \
24-
CHROME_VERSION=$(echo "$CHROME_VERSION" | tr '=' '_') \
25-
&& wget -qO google-chrome.deb "https://mirror.cs.uchicago.edu/google-chrome/pool/main/g/google-chrome-stable/${CHROME_VERSION}_$(dpkg --print-architecture).deb" \
26-
&& apt-get -qqy --no-install-recommends install --allow-downgrades ./google-chrome.deb \
27-
&& rm -rf google-chrome.deb ; \
28-
else \
29-
apt-get -qqy --no-install-recommends install ${CHROME_VERSION} ; \
30-
fi \
31-
&& rm /etc/apt/sources.list.d/google-chrome.list \
32-
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
19+
COPY --chown="${SEL_UID}:${SEL_GID}" install-chrome.sh update-chrome-components.sh /opt/bin/
20+
RUN chmod +x /opt/bin/install-chrome.sh /opt/bin/update-chrome-components.sh \
21+
&& /opt/bin/install-chrome.sh
3322

3423
#=================================
3524
# Chrome Launch Script Wrapper
3625
#=================================
37-
COPY wrap_chrome_binary /opt/bin/wrap_chrome_binary
38-
RUN /opt/bin/wrap_chrome_binary
26+
COPY --chown="${SEL_UID}:${SEL_GID}" wrap_chrome_binary /opt/bin/wrap_chrome_binary
27+
RUN chmod +x /opt/bin/wrap_chrome_binary \
28+
&& /opt/bin/wrap_chrome_binary
3929

4030
#============================================
4131
# Chrome webdriver
@@ -44,30 +34,9 @@ RUN /opt/bin/wrap_chrome_binary
4434
# Latest released version will be used by default
4535
#============================================
4636
ARG CHROME_DRIVER_VERSION
47-
RUN DRIVER_ARCH=$(if [ "$(dpkg --print-architecture)" = "amd64" ]; then echo "linux64"; else echo "linux-aarch64"; fi) \
48-
&& if [ ! -z "$CHROME_DRIVER_VERSION" ]; \
49-
then CHROME_DRIVER_URL=https://storage.googleapis.com/chrome-for-testing-public/$CHROME_DRIVER_VERSION/${DRIVER_ARCH}/chromedriver-${DRIVER_ARCH}.zip ; \
50-
else CHROME_MAJOR_VERSION=$(google-chrome --version | sed -E "s/.* ([0-9]+)(\.[0-9]+){3}.*/\1/") \
51-
&& if [ $CHROME_MAJOR_VERSION -lt 115 ]; then \
52-
echo "Geting ChromeDriver latest version from https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION}" \
53-
&& CHROME_DRIVER_VERSION=$(wget -qO- https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION} | sed 's/\r$//') \
54-
&& CHROME_DRIVER_URL=https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip ; \
55-
else \
56-
echo "Geting ChromeDriver latest version from https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_${CHROME_MAJOR_VERSION}" \
57-
&& CHROME_DRIVER_VERSION=$(wget -qO- https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_${CHROME_MAJOR_VERSION} | sed 's/\r$//') \
58-
&& CHROME_DRIVER_URL=https://storage.googleapis.com/chrome-for-testing-public/$CHROME_DRIVER_VERSION/${DRIVER_ARCH}/chromedriver-${DRIVER_ARCH}.zip ; \
59-
fi \
60-
fi \
61-
&& echo "Using ChromeDriver from: "$CHROME_DRIVER_URL \
62-
&& echo "Using ChromeDriver version: "$CHROME_DRIVER_VERSION \
63-
&& wget --no-verbose -O /tmp/chromedriver_${DRIVER_ARCH}.zip $CHROME_DRIVER_URL \
64-
&& rm -rf /opt/selenium/chromedriver \
65-
&& unzip /tmp/chromedriver_${DRIVER_ARCH}.zip -d /opt/selenium \
66-
&& rm /tmp/chromedriver_${DRIVER_ARCH}.zip \
67-
&& mv /opt/selenium/chromedriver /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION || true \
68-
&& mv /opt/selenium/chromedriver-${DRIVER_ARCH}/chromedriver /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION || true \
69-
&& chmod 755 /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION \
70-
&& ln -fs /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver
37+
COPY --chown="${SEL_UID}:${SEL_GID}" install-chromedriver.sh /opt/bin/
38+
RUN chmod +x /opt/bin/install-chromedriver.sh \
39+
&& /opt/bin/install-chromedriver.sh
7140

7241
#============================================
7342
# Chrome cleanup script and supervisord file

NodeChrome/install-chrome.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
#============================================
4+
# Google Chrome Installation Script
5+
#============================================
6+
# This script installs Google Chrome with support for:
7+
# - Different channels (stable, beta, unstable)
8+
# - Specific versions
9+
# - Architecture detection
10+
#============================================
11+
12+
set -e
13+
14+
# Default Chrome version/channel
15+
CHROME_VERSION="${CHROME_VERSION:-google-chrome-stable}"
16+
17+
echo "Installing Google Chrome: ${CHROME_VERSION}"
18+
19+
# Add Google Chrome repository
20+
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
21+
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >>/etc/apt/sources.list.d/google-chrome.list
22+
23+
# Update package list
24+
apt-get update -qqy
25+
26+
# Install Chrome based on version specification
27+
if echo "${CHROME_VERSION}" | grep -qE "google-chrome-stable[_|=][0-9]*"; then
28+
# Install specific version
29+
CHROME_VERSION=$(echo "$CHROME_VERSION" | tr '=' '_')
30+
echo "Installing specific Chrome version: ${CHROME_VERSION}"
31+
wget -qO google-chrome.deb "https://mirror.cs.uchicago.edu/google-chrome/pool/main/g/google-chrome-stable/${CHROME_VERSION}_$(dpkg --print-architecture).deb"
32+
apt-get -qqy --no-install-recommends install --allow-downgrades ./google-chrome.deb
33+
rm -rf google-chrome.deb
34+
else
35+
# Install from repository (stable, beta, unstable)
36+
echo "Installing Chrome channel: ${CHROME_VERSION}"
37+
apt-get -qqy --no-install-recommends install ${CHROME_VERSION}
38+
fi
39+
40+
# Cleanup
41+
rm /etc/apt/sources.list.d/google-chrome.list
42+
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
43+
44+
echo "Google Chrome installation completed"
45+
google-chrome --version

NodeChrome/install-chromedriver.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
#============================================
4+
# ChromeDriver Installation Script
5+
#============================================
6+
# This script installs ChromeDriver with support for:
7+
# - Automatic version detection based on Chrome version
8+
# - Specific version installation
9+
# - Architecture detection
10+
#============================================
11+
12+
set -e
13+
14+
# Default ChromeDriver version (empty for auto-detection)
15+
CHROME_DRIVER_VERSION="${CHROME_DRIVER_VERSION:-}"
16+
17+
echo "Installing ChromeDriver..."
18+
19+
# Detect architecture
20+
DRIVER_ARCH=$(if [ "$(dpkg --print-architecture)" = "amd64" ]; then echo "linux64"; else echo "linux-aarch64"; fi)
21+
echo "Detected architecture: ${DRIVER_ARCH}"
22+
23+
# Determine ChromeDriver version and URL
24+
if [ ! -z "$CHROME_DRIVER_VERSION" ]; then
25+
# Use specified version
26+
echo "Using specified ChromeDriver version: ${CHROME_DRIVER_VERSION}"
27+
CHROME_DRIVER_URL="https://storage.googleapis.com/chrome-for-testing-public/$CHROME_DRIVER_VERSION/${DRIVER_ARCH}/chromedriver-${DRIVER_ARCH}.zip"
28+
else
29+
# Auto-detect version based on Chrome version
30+
CHROME_MAJOR_VERSION=$(google-chrome --version | sed -E "s/.* ([0-9]+)(\.[0-9]+){3}.*/\1/")
31+
echo "Detected Chrome major version: ${CHROME_MAJOR_VERSION}"
32+
33+
if [ $CHROME_MAJOR_VERSION -lt 115 ]; then
34+
# Use old ChromeDriver API for versions < 115
35+
echo "Getting ChromeDriver latest version from https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION}"
36+
CHROME_DRIVER_VERSION=$(wget -qO- https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION} | sed 's/\r$//')
37+
CHROME_DRIVER_URL="https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip"
38+
else
39+
# Use new Chrome for Testing API for versions >= 115
40+
echo "Getting ChromeDriver latest version from https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_${CHROME_MAJOR_VERSION}"
41+
CHROME_DRIVER_VERSION=$(wget -qO- https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_${CHROME_MAJOR_VERSION} | sed 's/\r$//')
42+
CHROME_DRIVER_URL="https://storage.googleapis.com/chrome-for-testing-public/$CHROME_DRIVER_VERSION/${DRIVER_ARCH}/chromedriver-${DRIVER_ARCH}.zip"
43+
fi
44+
fi
45+
46+
echo "Using ChromeDriver from: ${CHROME_DRIVER_URL}"
47+
echo "Using ChromeDriver version: ${CHROME_DRIVER_VERSION}"
48+
49+
# Download and install ChromeDriver
50+
wget --no-verbose -O /tmp/chromedriver_${DRIVER_ARCH}.zip $CHROME_DRIVER_URL
51+
52+
# Remove existing ChromeDriver
53+
rm -rf /opt/selenium/chromedriver
54+
55+
# Extract ChromeDriver
56+
unzip /tmp/chromedriver_${DRIVER_ARCH}.zip -d /opt/selenium
57+
rm /tmp/chromedriver_${DRIVER_ARCH}.zip
58+
59+
# Handle different extraction patterns
60+
if [ -f "/opt/selenium/chromedriver" ]; then
61+
mv /opt/selenium/chromedriver /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION
62+
elif [ -f "/opt/selenium/chromedriver-${DRIVER_ARCH}/chromedriver" ]; then
63+
mv /opt/selenium/chromedriver-${DRIVER_ARCH}/chromedriver /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION
64+
rm -rf /opt/selenium/chromedriver-${DRIVER_ARCH}
65+
fi
66+
67+
# Set permissions and create symlink
68+
chmod 755 /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION
69+
ln -fs /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver
70+
71+
echo "ChromeDriver installation completed"
72+
chromedriver --version
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
#============================================
4+
# Chrome Components Update Script
5+
#============================================
6+
# This script updates Chrome and ChromeDriver to latest versions
7+
# Can be run at container startup to ensure latest versions
8+
#============================================
9+
10+
set -e
11+
12+
# Check if update is enabled via environment variable
13+
if [ "${SE_UPDATE_CHROME_COMPONENTS}" != "true" ]; then
14+
echo "Chrome components update disabled (SE_UPDATE_CHROME_COMPONENTS != true)"
15+
exit 0
16+
fi
17+
18+
echo "Starting Chrome components update..."
19+
20+
# Check if we have sudo access
21+
if ! sudo -n true 2>/dev/null; then
22+
echo "Warning: No sudo access available. Chrome components update skipped."
23+
echo "To enable updates, ensure the container user has sudo privileges."
24+
exit 0
25+
fi
26+
27+
# Update Chrome if needed
28+
echo "Checking for Chrome updates..."
29+
CURRENT_CHROME_VERSION=$(google-chrome --version 2>/dev/null || echo "Chrome not found")
30+
31+
if [ "$CURRENT_CHROME_VERSION" = "Chrome not found" ]; then
32+
echo "Chrome not found, installing..."
33+
sudo /opt/bin/install-chrome.sh
34+
else
35+
echo "Current Chrome version: $CURRENT_CHROME_VERSION"
36+
echo "Updating Chrome to latest version..."
37+
sudo /opt/bin/install-chrome.sh
38+
sudo /opt/bin/wrap_chrome_binary
39+
fi
40+
41+
# Update ChromeDriver if needed
42+
echo "Checking for ChromeDriver updates..."
43+
CURRENT_CHROMEDRIVER_VERSION=$(chromedriver --version 2>/dev/null | head -1 || echo "ChromeDriver not found")
44+
45+
if [ "$CURRENT_CHROMEDRIVER_VERSION" = "ChromeDriver not found" ]; then
46+
echo "ChromeDriver not found, installing..."
47+
sudo /opt/bin/install-chromedriver.sh
48+
else
49+
echo "Current ChromeDriver version: $CURRENT_CHROMEDRIVER_VERSION"
50+
echo "Updating ChromeDriver to latest compatible version..."
51+
sudo /opt/bin/install-chromedriver.sh
52+
fi
53+
54+
echo "Chrome components update completed"
55+
echo "Final versions:"
56+
google-chrome --version
57+
chromedriver --version

NodeChrome/wrap_chrome_binary

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
3+
set -e
24

35
WRAPPER_PATH=$(readlink -f /usr/bin/google-chrome)
46
BASE_PATH="$WRAPPER_PATH-base"

Standalone/start-selenium-standalone.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
#
33
# IMPORTANT: Change this file only in directory Standalone!
44

5+
# Check if Chrome components update is enabled
6+
if [ "${SE_UPDATE_CHROME_COMPONENTS}" = "true" ] && [ -f /opt/bin/update-chrome-components.sh ]; then
7+
echo "Chrome components update enabled, checking for updates..."
8+
echo "Note that after the container gets restarted, updated binaries will be lost unless you call the update script within the build container process."
9+
/opt/bin/update-chrome-components.sh
10+
fi
11+
512
# Start the pulseaudio server
613
pulseaudio -D --exit-idle-time=-1
714

scripts/generate_list_env_vars/description.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,8 @@
468468
- name: SE_NODE_DELETE_SESSION_ON_UI
469469
description: Enable capability to support deleting session on Grid UI
470470
cli: --delete-session-on-ui
471+
- name: SE_UPDATE_CHROME_COMPONENTS
472+
description: 'Applicable for node-chrome, standalone-chrome (arch linux/amd64).
473+
Update the latest version of Chrome and ChromeDriver at the beginning of the container
474+
startup. Read more: [#2872](https://github.com/SeleniumHQ/docker-selenium/pull/2872)'
475+
cli: ''

scripts/generate_list_env_vars/value.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@
252252
default: '5'
253253
- name: SE_SUPERVISORD_UNIX_SERVER_PASSWORD
254254
default: secret
255+
- name: SE_UPDATE_CHROME_COMPONENTS
256+
default: ''
255257
- name: SE_UPLOAD_COMMAND
256258
default: ''
257259
- name: SE_UPLOAD_DESTINATION_PREFIX

0 commit comments

Comments
 (0)