mirror of
https://ops.gitlab.net/gitlab-org/gitlab-build-images.git
synced 2025-12-11 02:52:56 +01:00
Support caching rpm of google-chrome also
Signed-off-by: Balasankar "Balu" C <balasankar@gitlab.com>
This commit is contained in:
parent
25a4531f59
commit
fbcb5bfbea
2 changed files with 91 additions and 29 deletions
|
|
@ -27,7 +27,7 @@ variables:
|
||||||
DOCKER_TLS_VERIFY: 1
|
DOCKER_TLS_VERIFY: 1
|
||||||
|
|
||||||
cache-google-chrome:
|
cache-google-chrome:
|
||||||
image: debian:bullseye-slim
|
image: ${BASE_IMAGE}
|
||||||
stage: automation
|
stage: automation
|
||||||
# Starts the job immediately
|
# Starts the job immediately
|
||||||
needs: []
|
needs: []
|
||||||
|
|
@ -36,3 +36,6 @@ cache-google-chrome:
|
||||||
# disable DinD
|
# disable DinD
|
||||||
before_script: []
|
before_script: []
|
||||||
services: []
|
services: []
|
||||||
|
parallel:
|
||||||
|
matrix:
|
||||||
|
- BASE_IMAGE: ['debian:bullseye-slim', 'registry.access.redhat.com/ubi8/ubi:8.6']
|
||||||
|
|
|
||||||
|
|
@ -7,41 +7,100 @@ set -e
|
||||||
|
|
||||||
PKG=google-chrome-stable
|
PKG=google-chrome-stable
|
||||||
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
function build_debian() {
|
||||||
apt-get -y update
|
echo "Handling deb package"
|
||||||
apt-get -y install apt-utils curl bash gnupg2
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
apt-get -y update
|
||||||
|
apt-get -y install apt-utils curl bash gnupg2
|
||||||
|
|
||||||
curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
|
curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
|
||||||
echo "deb [arch=$(dpkg --print-architecture)] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
|
echo "deb [arch=$(dpkg --print-architecture)] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
|
||||||
|
|
||||||
echo "Updating apt to get Google Chrome packages..."
|
echo "Updating apt to get Google Chrome packages..."
|
||||||
|
|
||||||
apt-get -y -q update
|
apt-get -y -q update
|
||||||
|
|
||||||
echo "Checking for latest Chrome version in apt repository..."
|
echo "Checking for latest Chrome version in apt repository..."
|
||||||
|
|
||||||
LATEST_VERSION=$(apt-cache show $PKG | grep Version | sort | tail -1 | sed -e "s/Version: //")
|
LATEST_VERSION=$(apt-cache show $PKG | grep Version | sort | tail -1 | sed -e "s/Version: //")
|
||||||
CHROME_DEB="google-chrome-stable_${LATEST_VERSION}_$(dpkg --print-architecture).deb"
|
CHROME_DEB="google-chrome-stable_${LATEST_VERSION}_$(dpkg --print-architecture).deb"
|
||||||
CHROME_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PKG}/${LATEST_VERSION}/${CHROME_DEB}"
|
CHROME_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PKG}/${LATEST_VERSION}/${CHROME_DEB}"
|
||||||
|
|
||||||
echo "Checking if cache has $CHROME_DEB"
|
echo "Checking if cache has $CHROME_DEB"
|
||||||
FILE_CHECK=$(curl --silent --location --head --output /dev/null --write "%{http_code}\\n" "$CHROME_URL")
|
FILE_CHECK=$(curl --silent --location --head --output /dev/null --write "%{http_code}\\n" "$CHROME_URL")
|
||||||
|
|
||||||
if [ "$FILE_CHECK" -eq "200" ]; then
|
if [ "$FILE_CHECK" -eq "200" ]; then
|
||||||
echo "Latest version $LATEST_VERSION is already cached!"
|
echo "Latest version $LATEST_VERSION is already cached!"
|
||||||
else
|
else
|
||||||
echo "Downloading latest Chrome version ($LATEST_VERSION) in apt repository..."
|
echo "Downloading latest Chrome version ($LATEST_VERSION) in apt repository..."
|
||||||
cd /tmp
|
cd /tmp
|
||||||
apt-get download $PKG
|
apt-get download $PKG
|
||||||
|
|
||||||
if ! [ -f "$CHROME_DEB" ]; then
|
if ! [ -f "$CHROME_DEB" ]; then
|
||||||
echo "Downloaded file didn't have expected name: $CHROME_DEB"
|
echo "Downloaded file didn't have expected name: $CHROME_DEB"
|
||||||
ls
|
ls
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Transferring $CHROME_DEB to GitLab packages"
|
echo "Transferring $CHROME_DEB to GitLab packages"
|
||||||
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
|
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
|
||||||
--upload-file "./{$CHROME_DEB}" \
|
--upload-file "./{$CHROME_DEB}" \
|
||||||
"$CHROME_URL"
|
"$CHROME_URL"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_ubi() {
|
||||||
|
{ 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
|
||||||
|
|
||||||
|
# To download rpm file
|
||||||
|
yum install -y yum-utils
|
||||||
|
|
||||||
|
echo "Checking for latest Chrome version in yum repository..."
|
||||||
|
|
||||||
|
LATEST_VERSION_STRING=$(yum info $PKG | awk '/Version/ { print $NF}')
|
||||||
|
LATEST_RELEASE_STRING=$(yum info $PKG | awk '/Release/ { print $NF}')
|
||||||
|
LATEST_VERSION="${LATEST_VERSION_STRING}-${LATEST_RELEASE_STRING}"
|
||||||
|
|
||||||
|
CHROME_RPM="google-chrome-stable-${LATEST_VERSION}.$(arch).rpm"
|
||||||
|
CHROME_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PKG}/${LATEST_VERSION}/${CHROME_RPM}"
|
||||||
|
|
||||||
|
echo "Checking if cache has $CHROME_RPM"
|
||||||
|
FILE_CHECK=$(curl --silent --location --head --output /dev/null --write "%{http_code}\\n" "$CHROME_URL")
|
||||||
|
|
||||||
|
if [ "$FILE_CHECK" -eq "200" ]; then
|
||||||
|
echo "Latest version $LATEST_VERSION is already cached!"
|
||||||
|
else
|
||||||
|
echo "Downloading latest Chrome version ($LATEST_VERSION) in yum repository..."
|
||||||
|
cd /tmp
|
||||||
|
yumdownloader $PKG
|
||||||
|
|
||||||
|
if ! [ -f "$CHROME_RPM" ]; then
|
||||||
|
echo "Downloaded file didn't have expected name: $CHROME_RPM"
|
||||||
|
ls
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Transferring $CHROME_RPM to GitLab packages"
|
||||||
|
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
|
||||||
|
--upload-file "./{$CHROME_RPM}" \
|
||||||
|
"$CHROME_URL"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
BASE_IMAGE=${BASE_IMAGE:-debian:bullseye-slim}
|
||||||
|
|
||||||
|
if [[ $BASE_IMAGE =~ debian ]]; then
|
||||||
|
build_debian "$@"
|
||||||
|
elif [[ $BASE_IMAGE =~ ubi ]]; then
|
||||||
|
build_ubi "$@"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue