From 8fd8a8d31d21374fc4b34e08e2318e09fce4a457 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 7 Feb 2020 13:07:41 +0500 Subject: [PATCH 1/6] Add Gecko webdriver to linux images --- images/linux/scripts/installers/firefox.sh | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/images/linux/scripts/installers/firefox.sh b/images/linux/scripts/installers/firefox.sh index e14df0c4..ac514248 100644 --- a/images/linux/scripts/installers/firefox.sh +++ b/images/linux/scripts/installers/firefox.sh @@ -23,3 +23,26 @@ echo "Lastly, documenting what we added to the metadata file" # ($HOME is /home/packer which is owned by packer.) HOME=/root DocumentInstalledItem "Firefox ($(firefox --version))" + +# Download and unpack latest release of geckodriver +URL=https:`curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest|grep 'browser_download_url.*linux64.tar.gz'|sed -e 's/^.*"https://'|sed -e 's/"//g'` +echo "Downloading geckodriver $URL..." +wget "$URL" -O geckodriver.tar.gz +tar -xzf geckodriver.tar.gz +rm geckodriver.tar.gz + +GECKODRIVER_BIN="/usr/bin/geckodriver" +mv "geckodriver" $GECKODRIVER_BIN +chown root:root $GECKODRIVER_BIN +chmod +x $GECKODRIVER_BIN +echo "GECKOWEBDRIVER=$GECKODRIVER_BIN" | tee -a /etc/environment + +# Run tests to determine that the geckodriver installed as expected +echo "Testing to make sure that script performed as expected, and basic scenarios work" +if ! command -v geckodriver; then + echo "geckodriver was not installed" + exit 1 +fi + +echo "Lastly, documenting what we added to the metadata file" +DocumentInstalledItem "Geckodriver ($(geckodriver --version)); Gecko Driver is available via GECKOWEBDRIVER environment variable" From 5a978501ecfc7fb1acd8624b588f7bf9c08bdb85 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 7 Feb 2020 13:08:26 +0500 Subject: [PATCH 2/6] Move selenium installation to its own script --- .../linux/scripts/installers/google-chrome.sh | 25 +-------------- images/linux/scripts/installers/selenium.sh | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 images/linux/scripts/installers/selenium.sh diff --git a/images/linux/scripts/installers/google-chrome.sh b/images/linux/scripts/installers/google-chrome.sh index 5d19a0f4..979e2b37 100644 --- a/images/linux/scripts/installers/google-chrome.sh +++ b/images/linux/scripts/installers/google-chrome.sh @@ -1,7 +1,7 @@ #!/bin/bash ################################################################################ ## File: google-chrome.sh -## Desc: Installs google-chrome, chromedriver and selenium server +## Desc: Installs google-chrome and chromedriver ################################################################################ # Source the helpers for use with the script @@ -57,26 +57,3 @@ fi echo "Lastly, documenting what we added to the metadata file" DocumentInstalledItem "Chromedriver ($(chromedriver --version)); Chrome Driver is available via CHROMEWEBDRIVER environment variable" - -# Determine latest selenium standalone server version -SELENIUM_LATEST_VERSION_URL=https://api.github.com/repos/SeleniumHQ/selenium/releases/latest -SELENIUM_VERSION=$(curl $SELENIUM_LATEST_VERSION_URL | jq '.name' | tr -d '"' | cut -d ' ' -f 2) -SELENIUM_VERSION_MAJOR_MINOR=$(echo $SELENIUM_VERSION | cut -d '.' -f 1,2) - -# Download selenium standalone server -echo "Downloading selenium-server-standalone v$SELENIUM_VERSION..." -SELENIUM_JAR_NAME="selenium-server-standalone-$SELENIUM_VERSION.jar" -wget https://selenium-release.storage.googleapis.com/$SELENIUM_VERSION_MAJOR_MINOR/$SELENIUM_JAR_NAME - -echo "Testing to make sure that script performed as expected, and basic scenarios work" -if [ ! -f "$SELENIUM_JAR_NAME" ]; then - echo "Selenium server was not installed" - exit 1 -fi - -SELENIUM_JAR_PATH="/usr/share/java/selenium-server-standalone.jar" -mv $SELENIUM_JAR_NAME $SELENIUM_JAR_PATH -echo "SELENIUM_JAR_PATH=$SELENIUM_JAR_PATH" | tee -a /etc/environment - -echo "Lastly, documenting what we added to the metadata file" -DocumentInstalledItem "Selenium server standalone (available via SELENIUM_JAR_PATH environment variable)" diff --git a/images/linux/scripts/installers/selenium.sh b/images/linux/scripts/installers/selenium.sh new file mode 100644 index 00000000..3cb7c315 --- /dev/null +++ b/images/linux/scripts/installers/selenium.sh @@ -0,0 +1,31 @@ +#!/bin/bash +################################################################################ +## File: selenium.sh +## Desc: Installs selenium server +################################################################################ + +# Source the helpers for use with the script +source $HELPER_SCRIPTS/document.sh + +# Determine latest selenium standalone server version +SELENIUM_LATEST_VERSION_URL=https://api.github.com/repos/SeleniumHQ/selenium/releases/latest +SELENIUM_VERSION=$(curl $SELENIUM_LATEST_VERSION_URL | jq '.name' | tr -d '"' | cut -d ' ' -f 2) +SELENIUM_VERSION_MAJOR_MINOR=$(echo $SELENIUM_VERSION | cut -d '.' -f 1,2) + +# Download selenium standalone server +echo "Downloading selenium-server-standalone v$SELENIUM_VERSION..." +SELENIUM_JAR_NAME="selenium-server-standalone-$SELENIUM_VERSION.jar" +wget https://selenium-release.storage.googleapis.com/$SELENIUM_VERSION_MAJOR_MINOR/$SELENIUM_JAR_NAME + +echo "Testing to make sure that script performed as expected, and basic scenarios work" +if [ ! -f "$SELENIUM_JAR_NAME" ]; then + echo "Selenium server was not installed" + exit 1 +fi + +SELENIUM_JAR_PATH="/usr/share/java/selenium-server-standalone.jar" +mv $SELENIUM_JAR_NAME $SELENIUM_JAR_PATH +echo "SELENIUM_JAR_PATH=$SELENIUM_JAR_PATH" | tee -a /etc/environment + +echo "Lastly, documenting what we added to the metadata file" +DocumentInstalledItem "Selenium server standalone (available via SELENIUM_JAR_PATH environment variable)" \ No newline at end of file From 1b799fea5f6f7d3151a20326c4ef70da395e1555 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 7 Feb 2020 13:12:35 +0500 Subject: [PATCH 3/6] Change template.json files --- images/linux/ubuntu1604.json | 1 + images/linux/ubuntu1804.json | 1 + 2 files changed, 2 insertions(+) diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index da22757a..bbbd088c 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -158,6 +158,7 @@ "{{template_dir}}/scripts/installers/ruby.sh", "{{template_dir}}/scripts/installers/rust.sh", "{{template_dir}}/scripts/installers/sbt.sh", + "{{template_dir}}/scripts/installers/selenium.sh", "{{template_dir}}/scripts/installers/sphinx.sh", "{{template_dir}}/scripts/installers/subversion.sh", "{{template_dir}}/scripts/installers/terraform.sh", diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index 55cd13c2..59107ba2 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -161,6 +161,7 @@ "{{template_dir}}/scripts/installers/ruby.sh", "{{template_dir}}/scripts/installers/rust.sh", "{{template_dir}}/scripts/installers/sbt.sh", + "{{template_dir}}/scripts/installers/selenium.sh", "{{template_dir}}/scripts/installers/sphinx.sh", "{{template_dir}}/scripts/installers/subversion.sh", "{{template_dir}}/scripts/installers/terraform.sh", From 1abfe68c563b02be9b6c4a983065847561cab86a Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 7 Feb 2020 15:05:49 +0500 Subject: [PATCH 4/6] Fix driver paths --- images/linux/scripts/installers/firefox.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/images/linux/scripts/installers/firefox.sh b/images/linux/scripts/installers/firefox.sh index ac514248..ceec1b14 100644 --- a/images/linux/scripts/installers/firefox.sh +++ b/images/linux/scripts/installers/firefox.sh @@ -31,11 +31,15 @@ wget "$URL" -O geckodriver.tar.gz tar -xzf geckodriver.tar.gz rm geckodriver.tar.gz -GECKODRIVER_BIN="/usr/bin/geckodriver" +GECKODRIVER_DIR="/usr/local/share/gecko_driver" +GECKODRIVER_BIN="$GECKODRIVER_DIR/geckodriver" + +mkdir -p $GECKODRIVER_DIR mv "geckodriver" $GECKODRIVER_BIN -chown root:root $GECKODRIVER_BIN + chmod +x $GECKODRIVER_BIN -echo "GECKOWEBDRIVER=$GECKODRIVER_BIN" | tee -a /etc/environment +ln -s "$GECKODRIVER_BIN" /usr/bin/ +echo "GECKOWEBDRIVER=$GECKODRIVER_DIR" | tee -a /etc/environment # Run tests to determine that the geckodriver installed as expected echo "Testing to make sure that script performed as expected, and basic scenarios work" From 0fef85bbb5cf71dbe8dbd0b008a242d1b1203e43 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Tue, 11 Feb 2020 13:57:40 +0500 Subject: [PATCH 5/6] Fix version output --- images/linux/scripts/installers/firefox.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/images/linux/scripts/installers/firefox.sh b/images/linux/scripts/installers/firefox.sh index ceec1b14..b591a26f 100644 --- a/images/linux/scripts/installers/firefox.sh +++ b/images/linux/scripts/installers/firefox.sh @@ -49,4 +49,5 @@ if ! command -v geckodriver; then fi echo "Lastly, documenting what we added to the metadata file" -DocumentInstalledItem "Geckodriver ($(geckodriver --version)); Gecko Driver is available via GECKOWEBDRIVER environment variable" +ver=`./geckodriver --version|head -1|awk '{print $2}'` +DocumentInstalledItem "Geckodriver (${ver}); Gecko Driver is available via GECKOWEBDRIVER environment variable" From fbbb2bedca4fb866ed634852e2d0c4de4aaaa12d Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Wed, 12 Feb 2020 12:38:43 +0500 Subject: [PATCH 6/6] Improve sed expression for evaluating of the download URL --- images/linux/scripts/installers/firefox.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/linux/scripts/installers/firefox.sh b/images/linux/scripts/installers/firefox.sh index b591a26f..aa920774 100644 --- a/images/linux/scripts/installers/firefox.sh +++ b/images/linux/scripts/installers/firefox.sh @@ -25,7 +25,7 @@ HOME=/root DocumentInstalledItem "Firefox ($(firefox --version))" # Download and unpack latest release of geckodriver -URL=https:`curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest|grep 'browser_download_url.*linux64.tar.gz'|sed -e 's/^.*"https://'|sed -e 's/"//g'` +URL=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest|grep 'browser_download_url.*linux64.tar.gz'|sed -E 's/^.*(https:.+)".*/\1/g') echo "Downloading geckodriver $URL..." wget "$URL" -O geckodriver.tar.gz tar -xzf geckodriver.tar.gz