ci: fail over unavailable Ubuntu package mirrors (#41174)

* ci: fail over unavailable Ubuntu package mirrors

* fix(ci): recover package retries across headless jobs

* fix(ci): allow complete fallback package index downloads

* fix(ci): recover dpkg locks and bound WebKit setup retries

* fix(ci): run apt deadlines inside sudo sessions

* fix(ci): invoke installed Playwright without root pnpm

* fix(ci): allow large fallback dependency downloads to finish
This commit is contained in:
Neil
2026-11-11 08:30:55 -08:00
committed by GitHub
parent 0184d8187d
commit f820fdf8d4
5 changed files with 74 additions and 12 deletions
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -eq 0 ]; then
echo 'Usage: install-ubuntu-apt-packages.sh <package>...' >&2
exit 2
fi
bash "$(dirname "${BASH_SOURCE[0]}")/prepare-ubuntu-apt.sh"
# Bound both routes while allowing large fallback downloads.
# Run deadlines as root so sudo cannot leave apt in a separate session.
if sudo timeout --kill-after=10s 45 apt-get update -o Acquire::Languages=none && sudo timeout --kill-after=10s 120 apt-get install -y "$@"; then
exit 0
fi
echo 'Ubuntu package setup failed; trying the same packages through the MIT mirror.' >&2
for host in archive.ubuntu.com ports.ubuntu.com mirrors.mit.edu; do
timeout 5 getent ahosts "$host" || true
done
bash "$(dirname "${BASH_SOURCE[0]}")/use-ubuntu-apt-mirror.sh"
bash "$(dirname "${BASH_SOURCE[0]}")/recover-ubuntu-dpkg.sh" || true
# Unrelated repositories may fail refresh; apt still verifies the requested packages.
if ! sudo timeout --kill-after=10s 120 apt-get update -o Acquire::Languages=none; then
echo 'Index refresh incomplete; attempting the requested packages with available authenticated indexes.' >&2
fi
sudo timeout --kill-after=10s 600 apt-get install -y "$@"
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
# A timed-out apt frontend can leave dpkg running in a separate session.
sudo timeout --kill-after=10s 30 bash -euo pipefail -c '
while lslocks --noheadings --raw --notruncate --output PATH | grep -E "^/var/lib/dpkg/lock(-frontend)?$" >/dev/null; do
sleep 1
done
dpkg --configure -a
'
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
# Change repository locations while retaining suites, architectures and signing keys.
for source in /etc/apt/apt-mirrors.txt /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do
if [ -f "$source" ]; then
sudo sed -i -E \
-e 's#https?://(azure\.archive|archive|security)\.ubuntu\.com/ubuntu#https://mirrors.mit.edu/ubuntu#g' \
-e 's#https?://ports\.ubuntu\.com/ubuntu-ports#https://mirrors.mit.edu/ubuntu-ports#g' \
"$source"
fi
done