gitlab-build-images/scripts/install-chrome

58 lines
1.9 KiB
Bash
Executable file

#!/bin/bash
set -xeuo pipefail
IFS=$'\n\t'
function build_debian() {
CHROME_VERSION=${1:-103.0.5060.134-1}
ARCH=${TARGETARCH:-amd64}
if [ "${ARCH}" == "amd64" ]; then
PKG=google-chrome-stable
else
# TODO: We do not yet have all packages required for platform other than amd64
apt install -y chromium chromium-driver
return
fi
# We hard code the URL rather than using $CI_API_V4_URL $CI_PROJECT_ID,
# because we would need to forward those variables
DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/${PKG}"
BROWSER_DEB="${PKG}_${CHROME_VERSION}_${ARCH}.deb"
BROWSER_URL="${DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${BROWSER_DEB}"
echo "Installing browser"
curl --silent --show-error --fail -O "$BROWSER_URL"
apt install -y "$PWD/$BROWSER_DEB"
rm -f "$BROWSER_DEB"
echo "Installing webdriver"
if [ "${ARCH}" == "amd64" ]; then
CHROME_VERSION_BASE=$(echo $CHROME_VERSION | awk -F "." '{print $1 "." $2 "." $3}')
CHROME_DRIVER_VERSION=$(curl -q https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION_BASE)
wget -q https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin
rm -f chromedriver_linux64.zip
else
DRIVER_DEB="${PKG}-driver_${CHROME_VERSION}_${ARCH}.deb"
DRIVER_URL="${DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${DRIVER_DEB}"
curl --silent --show-error --fail -O "$DRIVER_URL"
apt install -y "$PWD/$DRIVER_DEB"
rm -f "$DRIVER_DEB"
fi
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/google*.list
}
BUILD_OS=${BUILD_OS:-debian}
if [[ $BUILD_OS =~ debian ]]; then
build_debian "$@"
elif [[ $BUILD_OS =~ ubi ]]; then
build_ubi "$@"
fi