mirror of
https://ops.gitlab.net/gitlab-org/gitlab-build-images.git
synced 2025-12-09 18:12:55 +01:00
Merge branch 'acunskis-cache-chromium' into 'master'
Cache chromium for arm64 builds See merge request https://gitlab.com/gitlab-org/gitlab-build-images/-/merge_requests/578 Merged-by: Rémy Coutable <remy@rymai.me> Approved-by: Stan Hu <stanhu@gmail.com> Approved-by: Rémy Coutable <remy@rymai.me> Co-authored-by: Andrejs Cunskis <acunskis@gitlab.com>
This commit is contained in:
commit
b93b5c7d0b
7 changed files with 156 additions and 90 deletions
|
|
@ -1,8 +1,12 @@
|
||||||
# we support merge request workflow only
|
# we support merge request workflow only
|
||||||
include:
|
include:
|
||||||
- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
|
|
||||||
- local: '.gitlab/ci/*.yml'
|
- local: '.gitlab/ci/*.yml'
|
||||||
|
|
||||||
|
workflow:
|
||||||
|
rules:
|
||||||
|
- if: $CI_MERGE_REQUEST_IID
|
||||||
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||||
|
|
||||||
default:
|
default:
|
||||||
image: ${BASE_BUILD_REGISTRY_IMAGE}/debian-bullseye-slim:docker-20.10.14-buildx-0.8
|
image: ${BASE_BUILD_REGISTRY_IMAGE}/debian-bullseye-slim:docker-20.10.14-buildx-0.8
|
||||||
services:
|
services:
|
||||||
|
|
@ -22,14 +26,7 @@ stages:
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
DOCKER_HOST: tcp://docker:2375
|
DOCKER_HOST: tcp://docker:2375
|
||||||
|
BASE_BUILD_REGISTRY_IMAGE: registry.gitlab.com/gitlab-org/gitlab-build-images
|
||||||
|
|
||||||
cache-google-chrome:
|
cache-chrome-chromium:
|
||||||
image: debian:bullseye-slim
|
extends: .cache-google-chrome
|
||||||
stage: automation
|
|
||||||
# Starts the job immediately
|
|
||||||
needs: []
|
|
||||||
script:
|
|
||||||
- bash ./scripts/cache-google-chrome
|
|
||||||
# disable DinD
|
|
||||||
before_script: []
|
|
||||||
services: []
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,60 @@
|
||||||
.build_and_push:
|
.install-qemu:
|
||||||
stage: custom
|
timeout: 2 hours # builds with emulation can take a long time to complete
|
||||||
needs: []
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- high-cpu
|
- high-cpu
|
||||||
variables:
|
variables:
|
||||||
QEMU_IMAGE: tonistiigi/binfmt:qemu-v6.2.0
|
QEMU_IMAGE: tonistiigi/binfmt:qemu-v6.2.0
|
||||||
timeout: 2 hours
|
|
||||||
before_script:
|
before_script:
|
||||||
- echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
|
|
||||||
- |
|
- |
|
||||||
if [ "${ARCH:-amd64}" != "amd64" ]; then
|
if [ "$PUSH_CUSTOM_IMAGE" == "true" ]; then
|
||||||
|
echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
|
||||||
|
fi
|
||||||
|
- |
|
||||||
|
if [[ "${ARCH:-amd64}" =~ arm64 ]]; then
|
||||||
echo -e "\033[1;33mInstalling latest qemu emulators\033[0m"
|
echo -e "\033[1;33mInstalling latest qemu emulators\033[0m"
|
||||||
docker pull -q ${QEMU_IMAGE};
|
docker pull -q ${QEMU_IMAGE};
|
||||||
docker run --rm --privileged ${QEMU_IMAGE} --uninstall qemu-*;
|
docker run --rm --privileged ${QEMU_IMAGE} --uninstall qemu-*;
|
||||||
docker run --rm --privileged ${QEMU_IMAGE} --install all;
|
docker run --rm --privileged ${QEMU_IMAGE} --install all;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
.build_and_push:
|
||||||
|
stage: custom
|
||||||
|
extends: .install-qemu
|
||||||
|
needs: []
|
||||||
script:
|
script:
|
||||||
- ./scripts/lib/custom-docker-build
|
- ./scripts/lib/custom-docker-build
|
||||||
rules:
|
rules:
|
||||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_SERVER_HOST == "gitlab.com"'
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_SERVER_HOST == "gitlab.com"'
|
||||||
variables:
|
|
||||||
BASE_BUILD_REGISTRY_IMAGE: registry.gitlab.com/gitlab-org/gitlab-build-images
|
|
||||||
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_SERVER_HOST == "gitlab.com"'
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_SERVER_HOST == "gitlab.com"'
|
||||||
variables:
|
variables:
|
||||||
PUSH_CUSTOM_IMAGE: "true"
|
PUSH_CUSTOM_IMAGE: "true"
|
||||||
BASE_BUILD_REGISTRY_IMAGE: registry.gitlab.com/gitlab-org/gitlab-build-images
|
|
||||||
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && ($CI_SERVER_HOST == "ops.gitlab.net" || $CI_SERVER_HOST == "dev.gitlab.org")'
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && ($CI_SERVER_HOST == "ops.gitlab.net" || $CI_SERVER_HOST == "dev.gitlab.org")'
|
||||||
variables:
|
variables:
|
||||||
PUSH_CUSTOM_IMAGE: "true"
|
PUSH_CUSTOM_IMAGE: "true"
|
||||||
BASE_BUILD_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE
|
BASE_BUILD_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE
|
||||||
|
|
||||||
|
.cache-google-chrome:
|
||||||
|
stage: automation
|
||||||
|
extends: .install-qemu
|
||||||
|
needs: []
|
||||||
|
variables:
|
||||||
|
ARCH: linux/amd64,linux/arm64
|
||||||
|
before_script:
|
||||||
|
- !reference [.install-qemu, before_script]
|
||||||
|
- docker buildx create --use # creates context that's capable of building multiple architectures in parallel
|
||||||
|
script:
|
||||||
|
- |
|
||||||
|
docker buildx build \
|
||||||
|
--build-arg CI_API_V4_URL=$CI_API_V4_URL \
|
||||||
|
--build-arg CI_PROJECT_ID=$CI_PROJECT_ID \
|
||||||
|
--build-arg CI_JOB_TOKEN=$CI_JOB_TOKEN \
|
||||||
|
--platform $ARCH \
|
||||||
|
-f "Dockerfile.cache-chrome" \
|
||||||
|
.
|
||||||
|
rules:
|
||||||
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_SERVER_HOST == "gitlab.com"'
|
||||||
|
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_SERVER_HOST == "gitlab.com"'
|
||||||
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_SERVER_HOST == "gitlab.com"'
|
||||||
|
when: manual
|
||||||
|
allow_failure: true
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ e2e-chrome:
|
||||||
extends:
|
extends:
|
||||||
- e2e-docker
|
- e2e-docker
|
||||||
variables:
|
variables:
|
||||||
CHROME: '103'
|
CHROME: '104'
|
||||||
parallel:
|
parallel:
|
||||||
matrix:
|
matrix:
|
||||||
- RUBY: ['2.7', '3.0']
|
- RUBY: ['2.7', '3.0']
|
||||||
|
|
|
||||||
11
Dockerfile.cache-chrome
Normal file
11
Dockerfile.cache-chrome
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Save amd64 chrome and arm64 .deb files to package registry
|
||||||
|
FROM debian:latest
|
||||||
|
|
||||||
|
ARG TARGETARCH
|
||||||
|
ARG CI_API_V4_URL
|
||||||
|
ARG CI_PROJECT_ID
|
||||||
|
ARG CI_JOB_TOKEN
|
||||||
|
|
||||||
|
ADD scripts/cache-google-chrome /cache-google-chrome
|
||||||
|
|
||||||
|
RUN /cache-google-chrome
|
||||||
|
|
@ -1,47 +1,86 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# This script attempts to copy the latest version of the Google Chrome Debian
|
# This script attempts to copy the latest version of the Google Chrome Debian
|
||||||
# package into our own package registry. Google yanks old versions regularly,
|
# package into our own package registry. Google yanks old versions regularly,
|
||||||
# making it hard to keep up with all the new versions.
|
# making it hard to keep up with all the new versions.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
PKG=google-chrome-stable
|
|
||||||
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
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 -
|
function save-package() {
|
||||||
echo "deb [arch=$(dpkg --print-architecture)] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
|
local PKG=$1
|
||||||
|
local DEB=$2
|
||||||
|
local LATEST_VERSION=$3
|
||||||
|
local REGISTRY_PACKAGE=${4:-$PKG}
|
||||||
|
local SOURCE_DEB=${5:-$DEB}
|
||||||
|
|
||||||
echo "Updating apt to get Google Chrome packages..."
|
local URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${REGISTRY_PACKAGE}/${LATEST_VERSION}/${DEB}"
|
||||||
|
|
||||||
apt-get -y -q update
|
echo "Checking if ${PKG} v${LATEST_VERSION} is already cached"
|
||||||
|
local FILE_CHECK=$(curl --silent --location --head --output /dev/null --write "%{http_code}\\n" "$URL")
|
||||||
|
|
||||||
echo "Checking for latest Chrome version in apt repository..."
|
if [ "$FILE_CHECK" -eq "200" ]; then
|
||||||
|
echo "${PKG} v${LATEST_VERSION} is already cached!"
|
||||||
|
else
|
||||||
|
echo "Downloading latest ${PKG} version (${LATEST_VERSION}) from apt repository..."
|
||||||
|
cd /tmp
|
||||||
|
apt-get download "$PKG"
|
||||||
|
|
||||||
LATEST_VERSION=$(apt-cache show $PKG | grep Version | sort | tail -1 | sed -e "s/Version: //")
|
if ! [ -f "${SOURCE_DEB}" ]; then
|
||||||
CHROME_DEB="google-chrome-stable_${LATEST_VERSION}_$(dpkg --print-architecture).deb"
|
echo "Downloaded file didn't have expected name: ${SOURCE_DEB}"
|
||||||
CHROME_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PKG}/${LATEST_VERSION}/${CHROME_DEB}"
|
ls
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Checking if cache has $CHROME_DEB"
|
if [ "$SOURCE_DEB" != "$DEB" ]; then
|
||||||
FILE_CHECK=$(curl --silent --location --head --output /dev/null --write "%{http_code}\\n" "$CHROME_URL")
|
mv "$SOURCE_DEB" "$DEB"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$FILE_CHECK" -eq "200" ]; then
|
echo "Transferring ${PKG} v${LATEST_VERSION} to GitLab packages"
|
||||||
echo "Latest version $LATEST_VERSION is already cached!"
|
curl --fail --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
|
||||||
else
|
--upload-file "./{$DEB}" \
|
||||||
echo "Downloading latest Chrome version ($LATEST_VERSION) in apt repository..."
|
"$URL"
|
||||||
cd /tmp
|
|
||||||
apt-get download $PKG
|
|
||||||
|
|
||||||
if ! [ -f "$CHROME_DEB" ]; then
|
|
||||||
echo "Downloaded file didn't have expected name: $CHROME_DEB"
|
|
||||||
ls
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
echo "Transferring $CHROME_DEB to GitLab packages"
|
function cache-chrome() {
|
||||||
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
|
PKG=google-chrome-stable
|
||||||
--upload-file "./{$CHROME_DEB}" \
|
|
||||||
"$CHROME_URL"
|
echo "Updating apt to get Google Chrome packages..."
|
||||||
|
curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
|
||||||
|
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >/etc/apt/sources.list.d/google.list
|
||||||
|
apt-get -y -qq update
|
||||||
|
|
||||||
|
echo "Checking for latest '${PKG}' version in apt repository..."
|
||||||
|
LATEST_VERSION=$(apt-cache show $PKG | grep Version | sort | tail -1 | sed -e "s/Version: //")
|
||||||
|
CHROME_DEB="google-chrome-stable_${LATEST_VERSION}_amd64.deb"
|
||||||
|
|
||||||
|
save-package "$PKG" "$CHROME_DEB" "$LATEST_VERSION"
|
||||||
|
}
|
||||||
|
|
||||||
|
function cache-chromium() {
|
||||||
|
PKG=chromium
|
||||||
|
PKG_DRIVER=chromium-driver
|
||||||
|
|
||||||
|
echo "Checking for latest '${PKG}' version in apt repository..."
|
||||||
|
LATEST_VERSION=$(apt-cache show $PKG | grep Version | sort | tail -1 | sed -e "s/Version: //")
|
||||||
|
VERSION_NUMBER=$(echo $LATEST_VERSION | sed -e "s/~deb.*//") # remove debian version part to have chrome and chromium compatible version numbers
|
||||||
|
CHROMIUM_DEB="${PKG}_${VERSION_NUMBER}_${TARGETARCH}.deb"
|
||||||
|
CHROMIUM_DRIVER_DEB="${PKG_DRIVER}_${VERSION_NUMBER}_${TARGETARCH}.deb"
|
||||||
|
|
||||||
|
# Save both chromium and chromium-driver under the same package
|
||||||
|
save-package "$PKG" "$CHROMIUM_DEB" "$VERSION_NUMBER" "${PKG}" "${PKG}_${LATEST_VERSION}_${TARGETARCH}.deb"
|
||||||
|
save-package "$PKG_DRIVER" "$CHROMIUM_DRIVER_DEB" "$VERSION_NUMBER" "${PKG}" "${PKG_DRIVER}_${LATEST_VERSION}_${TARGETARCH}.deb"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Updating system utils"
|
||||||
|
apt-get -y -qq update
|
||||||
|
apt-get -y install apt-utils curl gnupg2 >/dev/null
|
||||||
|
|
||||||
|
if [ "$TARGETARCH" == "amd64" ]; then
|
||||||
|
cache-chrome
|
||||||
|
cache-chromium
|
||||||
|
else
|
||||||
|
cache-chromium
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -4,57 +4,45 @@ set -xeuo pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
function build_debian() {
|
function build_debian() {
|
||||||
ARCH="${TARGETARCH:-amd64}"
|
CHROME_VERSION=${1:-103.0.5060.134-1}
|
||||||
|
ARCH=${TARGETARCH:-amd64}
|
||||||
|
|
||||||
if [[ "${ARCH}" == "arm64" ]]; then
|
if [ "${ARCH}" == "amd64" ]; then
|
||||||
echo "The arm64 does not have prebuilt chrome. Using chromium instead."
|
PKG=google-chrome-stable
|
||||||
apt-get update -q -y
|
else
|
||||||
apt-get install -y chromium chromium-driver
|
PKG=chromium
|
||||||
apt-get autoremove -yq
|
|
||||||
apt-get clean -yqq
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CHROME_VERSION=${1:-99.0.4844.74-1}
|
|
||||||
# We hard code the URL rather than using $CI_API_V4_URL $CI_PROJECT_ID,
|
# We hard code the URL rather than using $CI_API_V4_URL $CI_PROJECT_ID,
|
||||||
# because we would need to forward those variables
|
# because we would need to forward those variables
|
||||||
CHROME_DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/google-chrome-stable"
|
DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/${PKG}"
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
BROWSER_DEB="${PKG}_${CHROME_VERSION}_${ARCH}.deb"
|
||||||
|
BROWSER_URL="${DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${BROWSER_DEB}"
|
||||||
|
|
||||||
curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
|
echo "Installing browser"
|
||||||
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >/etc/apt/sources.list.d/google.list
|
curl --silent --show-error --fail -O "$BROWSER_URL"
|
||||||
|
dpkg -i "./${BROWSER_DEB}" || true
|
||||||
|
apt-get install -f -y
|
||||||
|
rm -f "$BROWSER_DEB"
|
||||||
|
|
||||||
apt-get update -q -y
|
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)
|
||||||
|
|
||||||
# Download from our package registry if we can't find the package in the apt repository
|
wget -q https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
|
||||||
echo "Searching for $CHROME_VERSION in apt repository"
|
unzip chromedriver_linux64.zip -d /usr/local/bin
|
||||||
CHECK_VERSION=$(apt-cache show google-chrome-stable | grep Version | grep "$CHROME_VERSION") || true
|
rm -f chromedriver_linux64.zip
|
||||||
|
|
||||||
apt-cache policy google-chrome-stable
|
|
||||||
|
|
||||||
if [[ -z $CHECK_VERSION ]]; then
|
|
||||||
CHROME_DEB="google-chrome-stable_${CHROME_VERSION}_${ARCH}.deb"
|
|
||||||
CHROME_URL="${CHROME_DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${CHROME_DEB}"
|
|
||||||
echo "Downloading from our Package registry: $CHROME_URL"
|
|
||||||
curl --silent --show-error --fail -O $CHROME_URL
|
|
||||||
dpkg -i ./$CHROME_DEB || true
|
|
||||||
apt-get install -f -y
|
|
||||||
rm -f $CHROME_DEB
|
|
||||||
else
|
else
|
||||||
echo "Installing via apt-get"
|
DRIVER_DEB="${PKG}-driver_${CHROME_VERSION}_${ARCH}.deb"
|
||||||
apt-get install -y google-chrome-stable=$CHROME_VERSION
|
DRIVER_URL="${DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${DRIVER_DEB}"
|
||||||
|
|
||||||
|
curl --silent --show-error --fail -O "$DRIVER_URL"
|
||||||
|
dpkg -i "./${DRIVER_DEB}" || true
|
||||||
|
apt-get install -f -y
|
||||||
|
rm -f "$DRIVER_DEB"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
apt-get autoremove -yq
|
apt-get autoremove -yq
|
||||||
apt-get clean -yqq
|
apt-get clean -yqq
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,9 @@ function print_chrome_args() {
|
||||||
103|103.0)
|
103|103.0)
|
||||||
CHROME_VERSION=103.0.5060.114-1
|
CHROME_VERSION=103.0.5060.114-1
|
||||||
;;
|
;;
|
||||||
|
104|104.0)
|
||||||
|
CHROME_VERSION=104.0.5112.101-1
|
||||||
|
;;
|
||||||
*) echo "Unknown chrome version $1"; exit 1;
|
*) echo "Unknown chrome version $1"; exit 1;
|
||||||
esac
|
esac
|
||||||
printf -- "--build-arg CHROME_VERSION=%s " "$CHROME_VERSION"
|
printf -- "--build-arg CHROME_VERSION=%s " "$CHROME_VERSION"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue