Skip to content

Commit

Permalink
Fix resolver for chromedriver
Browse files Browse the repository at this point in the history
  • Loading branch information
yacchin1205 committed Oct 19, 2023
1 parent 6e86eb4 commit 527199a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ RUN sh -c 'wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub |
&& apt-get update && apt-get install -y xvfb google-chrome-stable \
&& rm -rf /var/lib/apt/lists/*

COPY . /tmp/resource

# ChromeDriver
RUN cd /usr/local/sbin/ && \
export CHROME_MAJOR_VERSION=$(dpkg -s google-chrome-stable | grep Version | sed -r 's/Version: ([0-9]+)\.[0-9\.]+-[0-9]*/\1/') && \
export CHROMEDRIVER_VERSION=$(curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION}) && \
wget https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip && \
chmod +x chromedriver && \
rm chromedriver_linux64.zip
dpkg -s google-chrome-stable | grep Version && \
export CHROME_MAJOR_VERSION=$(dpkg -s google-chrome-stable | grep Version | sed -r 's/Version: ([0-9]+\.[0-9\.]+)-[0-9]*/\1/') && \
echo CHROME_MAJOR_VERSION=${CHROME_MAJOR_VERSION} && \
wget -O /tmp/resource/chromedriver-linux64.zip $(python3 /tmp/resource/util/resolve-chromedriver-url.py --chrome-version ${CHROME_MAJOR_VERSION} --platform linux64) && \
unzip /tmp/resource/chromedriver-linux64.zip && \
chmod +x chromedriver-linux64/chromedriver && \
ln -s /usr/local/sbin/chromedriver-linux64/chromedriver /usr/local/sbin/chromedriver && \
rm /tmp/resource/chromedriver-linux64.zip

RUN pip --no-cache-dir install selenium

# AWSCLI
RUN mamba install --quiet --yes awscli passlib && mamba clean --all -f -y

COPY . /tmp/resource

# Scripts for Jenkins/Supervisor
RUN mkdir -p /usr/local/bin/before-notebook.d && \
cp /tmp/resource/conf/onboot/* /usr/local/bin/before-notebook.d/ && \
Expand Down
48 changes: 48 additions & 0 deletions util/resolve-chromedriver-url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
import argparse
import logging
import requests

def search_versions(versions, chrome_version, exact=True):
for version in versions:
if exact and version['version'] == chrome_version:
return version
if not exact and version['version'].startswith(f'{chrome_version}.'):
return version
return None

def search_binary_by_platform(downloads, platform):
for download in downloads:
if download['platform'] == platform:
return download
return None

argparser = argparse.ArgumentParser()
argparser.add_argument('--chrome-version', required=True,
help='Chrome version to resolve ChromeDriver version for')
argparser.add_argument('--platform', required=True, help='Platform for ChromeDriver binary')
argparser.add_argument('--debug', action='store_true', help='Print debug information')

args = argparser.parse_args()

if args.debug:
logging.basicConfig(level=logging.DEBUG)

# convenient JSON endpoints for specific ChromeDriver version downloading
# https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
resp = requests.get('https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json')
versions = resp.json()['versions']
target_version = search_versions(versions, args.chrome_version)
chrome_version = args.chrome_version
while not target_version and '.' in chrome_version:
chrome_version = '.'.join(chrome_version.split('.')[:-1])
target_version = search_versions(versions, chrome_version, exact=False)
if not target_version:
print(f'Could not find ChromeDriver version for Chrome version {args.chrome_version}')
exit(1)
logging.debug(f'Downloads(for {chrome_version}): {target_version}')
binary = search_binary_by_platform(target_version['downloads']['chromedriver'], args.platform)
if not binary:
print(f'Could not find ChromeDriver binary for platform {args.platform}')
exit(1)
print(binary['url'])

0 comments on commit 527199a

Please sign in to comment.