Support building google-chrome in UBI

Signed-off-by: Balasankar "Balu" C <balasankar@gitlab.com>
This commit is contained in:
Balasankar "Balu" C 2022-08-05 10:54:52 +05:30
parent f28d358e24
commit 7bb4094eb2
No known key found for this signature in database
GPG key ID: B77D2E2E23735427

View file

@ -3,6 +3,12 @@
set -xeuo pipefail
IFS=$'\n\t'
CHROME_VERSION=${1:-99.0.4844.74-1}
# We hard code the URL rather than using $CI_API_V4_URL $CI_PROJECT_ID,
# because we would need to forward those variables
CHROME_DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/google-chrome-stable"
function build_debian() {
if [[ $(dpkg --print-architecture) == arm64 ]]; then
echo "The arm64 does not have prebuilt chrome. Using chromium instead."
@ -14,10 +20,6 @@ function build_debian() {
exit 0
fi
CHROME_VERSION=${1:-99.0.4844.74-1}
# We hard code the URL rather than using $CI_API_V4_URL $CI_PROJECT_ID,
# because we would need to forward those variables
CHROME_DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/google-chrome-stable"
export DEBIAN_FRONTEND=noninteractive
curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
@ -59,6 +61,88 @@ function build_debian() {
rm -rf /etc/apt/sources.list.d/google*.list
}
function build_ubi() {
UBI_VERSION=$(lsb_release -a | awk '/Release/ { print $2 }')
UBI_MAJOR_VERSION=${UBI_VERSION%.*} # strip last component
# Dependencies are spread across epel and CentOS 8 repos. So we temporarily
# enable them.
# The awk is below to strip leading and trailing spaces in the
# repo file which can cause yum to blow up
{ awk '{$1=$1};1' | tee -a /etc/yum.repos.d/centos.repo; } <<- EOM
[centos-appstream]
name=CentOS-${UBI_MAJOR_VERSION}- AppStream
baseurl=http://vault.centos.org/centos/8/AppStream/x86_64/os/
gpgcheck=0
enabled=1
[centos-baseos]
name=CentOS-${UBI_MAJOR_VERSION}- BaseOS
baseurl=http://vault.centos.org/centos/8/BaseOS/x86_64/os
gpgcheck=0
enabled=1
EOM
yum -y install "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${UBI_MAJOR_VERSION}.noarch.rpm"
if [[ ${BUILD_ARCH} == "arm64" ]]; then
echo "The arm64 does not have prebuilt chrome. Using chromium instead."
yum update -y
yum install -y chromium chromedriver
yum autoremove -y
yum clean -y all
rm -rf /etc/yum.repos.d/centos.repo
yum remove -y epel-release
exit 0
fi
{ awk '{$1=$1};1' | tee -a /etc/yum.repos.d/google-chrome.repo; } <<- EOM
[google-chrome]
name=Google Chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$(arch)
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
EOM
yum update -y
LATEST_VERSION_STRING=$(yum info google-chrome-stable | awk '/Version/ { print $NF}')
LATEST_RELEASE_STRING=$(yum info google-chrome-stable | awk '/Release/ { print $NF}')
LATEST_VERSION="${LATEST_VERSION_STRING}-${LATEST_RELEASE_STRING}"
# Download from our package registry if we can't find the package in the apt repository
echo "Searching for $CHROME_VERSION in apt repository"
if [[ $LATEST_VERSION != ${CHROME_VERSION} ]]; then
CHROME_RPM="google-chrome-stable-${CHROME_VERSION}.$(arch).rpm"
CHROME_URL="${CHROME_DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${CHROME_RPM}"
echo "Downloading from our Package registry: $CHROME_URL"
curl --silent --show-error --fail -O $CHROME_URL
yum install -y ./${CHROME_RPM} || true
rm -f $CHROME_RPM
else
echo "Installing via apt-get"
yum install -y google-chrome-stable-$CHROME_VERSION
fi
# Install ChromeDriver
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
yum autoremove -y
yum clean -y all
rm -rf /etc/yum.repos.d/centos.repo
rm -rf /etc/yum.repos.d/google-chrome.repo
yum remove -y epel-release
yum update -y --nobest
}
BUILD_OS=${BUILD_OS:-debian}
BUILD_ARCH=${BUILD_ARCH:-amd64}