From b7f276c003aea42575b52247bdb2183e355fca2f Mon Sep 17 00:00:00 2001 From: Nikita Bykov <49442273+nikita-bykov@users.noreply.github.com> Date: Fri, 2 Apr 2021 19:21:33 +0300 Subject: [PATCH] =?UTF-8?q?[Ubuntu]=20Rework=20=D0=A1hromium=20installatio?= =?UTF-8?q?n=20to=20avoid=20using=20snap=20(#3029)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * rework chromium installation * added GetChromiumRevision function * changed getting chrome version * fixed GetChromiumRevision function * fixed CHROME_VERSION variable * move chromium installation to google-chrome.sh * added -qq for unzip * added comments to GetChromiumRevision function * updated tests and sofware report Co-authored-by: Nikita Bykov --- .../SoftwareReport.Generator.ps1 | 6 +-- images/linux/scripts/installers/basic.sh | 3 +- .../linux/scripts/installers/google-chrome.sh | 52 +++++++++++++++++-- images/linux/scripts/tests/Browsers.Tests.ps1 | 4 +- images/linux/toolsets/toolset-2004.json | 1 - 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index 1af99554..cc4a74a0 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -215,11 +215,9 @@ $browsersAndDriversList = @( (Get-ChromeVersion), (Get-ChromeDriverVersion), (Get-FirefoxVersion), - (Get-GeckodriverVersion) + (Get-GeckodriverVersion), + (Get-ChromiumVersion) ) -if (Test-IsUbuntu20) { - $browsersAndDriversList = @(Get-ChromiumVersion) + $browsersAndDriversList -} $markdown += New-MDList -Style Unordered -Lines $browsersAndDriversList $markdown += New-MDHeader "Environment variables" -Level 4 diff --git a/images/linux/scripts/installers/basic.sh b/images/linux/scripts/installers/basic.sh index efac5bd4..270cc75c 100644 --- a/images/linux/scripts/installers/basic.sh +++ b/images/linux/scripts/installers/basic.sh @@ -12,5 +12,4 @@ for package in $common_packages $cmd_packages; do apt-get install -y --no-install-recommends $package done -invoke_tests "Apt" -invoke_tests "Browsers" "Chromium" \ No newline at end of file +invoke_tests "Apt" \ No newline at end of file diff --git a/images/linux/scripts/installers/google-chrome.sh b/images/linux/scripts/installers/google-chrome.sh index 0cc638f4..569f490c 100644 --- a/images/linux/scripts/installers/google-chrome.sh +++ b/images/linux/scripts/installers/google-chrome.sh @@ -1,12 +1,40 @@ #!/bin/bash -e ################################################################################ ## File: google-chrome.sh -## Desc: Installs google-chrome and chromedriver +## Desc: Installs google-chrome, chromedriver and chromium ################################################################################ # Source the helpers for use with the script source $HELPER_SCRIPTS/install.sh +function GetChromiumRevision { + CHROME_VERSION=$1 + + # Get the required Chromium revision corresponding to the Chrome version + URL="https://omahaproxy.appspot.com/deps.json?version=${CHROME_VERSION}" + REVISION=$(curl -s $URL | jq -r '.chromium_base_position') + + # Take the first part of the revision variable to search not only for a specific version, + # but also for similar ones, so that we can get a previous one if the required revision is not found + FIRST_PART_OF_REVISION=${REVISION:0:${#REVISION}/2} + URL="https://www.googleapis.com/storage/v1/b/chromium-browser-snapshots/o?delimiter=/&prefix=Linux_x64/${FIRST_PART_OF_REVISION}" + VERSIONS=$(curl -s $URL | jq -r '.prefixes[]' | cut -d "/" -f 2 | sort --version-sort) + + # If required Chromium revision is not found in the list + # we should have to decrement the revision number until we find one. + # This is mentioned in the documentation we use for this installation: + # https://www.chromium.org/getting-involved/download-chromium + RIGHT_REVISION=$(echo $VERSIONS | cut -f 1 -d " ") + for version in $VERSIONS; do + if [ $REVISION -lt $version ]; then + echo $RIGHT_REVISION + return + fi + RIGHT_REVISION=$version + done + echo $RIGHT_REVISION +} + # Download and install Google Chrome CHROME_DEB_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" CHROME_DEB_NAME="google-chrome-stable_current_amd64.deb" @@ -15,8 +43,8 @@ apt install "/tmp/${CHROME_DEB_NAME}" -f echo "CHROME_BIN=/usr/bin/google-chrome" | tee -a /etc/environment # Parse Google Chrome version -CHROME_VERSION=$(google-chrome --product-version) -CHROME_VERSION=${CHROME_VERSION%.*} +FULL_CHROME_VERSION=$(google-chrome --product-version) +CHROME_VERSION=${FULL_CHROME_VERSION%.*} # Determine the latest release of chromedriver # Compatibility of Google Chrome and Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/downloads/version-selection @@ -35,4 +63,22 @@ chmod +x $CHROMEDRIVER_BIN ln -s "$CHROMEDRIVER_BIN" /usr/bin/ echo "CHROMEWEBDRIVER=$CHROMEDRIVER_DIR" | tee -a /etc/environment +# Download and unpack Chromium +# Get Chromium version corresponding to the Google Chrome version +REVISION=$(GetChromiumRevision $FULL_CHROME_VERSION) + +ZIP_URL="https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${REVISION}%2Fchrome-linux.zip?alt=media" +ZIP_FILE="${REVISION}-chromium-linux.zip" + +CHROMIUM_DIR="/usr/local/share/chromium" +CHROMIUM_BIN="$CHROMIUM_DIR/chrome-linux/chrome" + +# Download and unzip Chromium archive +download_with_retries $ZIP_URL "/tmp" $ZIP_FILE +mkdir $CHROMIUM_DIR +unzip -qq /tmp/${ZIP_FILE} -d $CHROMIUM_DIR + +ln -s $CHROMIUM_BIN /usr/bin/chromium + invoke_tests "Browsers" "Chrome" +invoke_tests "Browsers" "Chromium" \ No newline at end of file diff --git a/images/linux/scripts/tests/Browsers.Tests.ps1 b/images/linux/scripts/tests/Browsers.Tests.ps1 index 1efd1634..40296ec8 100644 --- a/images/linux/scripts/tests/Browsers.Tests.ps1 +++ b/images/linux/scripts/tests/Browsers.Tests.ps1 @@ -18,8 +18,8 @@ Describe "Chrome" { } } -Describe "Chromium" -Skip:(-not (Test-IsUbuntu20)) { +Describe "Chromium" { It "Chromium" { "chromium --version" | Should -ReturnZeroExitCode } -} \ No newline at end of file +} diff --git a/images/linux/toolsets/toolset-2004.json b/images/linux/toolsets/toolset-2004.json index 238a2191..4b8f127d 100644 --- a/images/linux/toolsets/toolset-2004.json +++ b/images/linux/toolsets/toolset-2004.json @@ -116,7 +116,6 @@ "apt": { "common_packages": [ "build-essential", - "chromium-browser", "dbus", "dnsutils", "dpkg",