[actions] retry apt package installs through Ubuntu mirror outages
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Mirror outages have outlasted the existing retries, which covered only `apt-get update` (and not the WSL `additional-packages` install). Installs now go through `.github/scripts/apt-install.sh`, which retries each request within apt and retries the whole update+install with backoff for about 10 minutes.
authored by Jordan Harband · committed by Jordan Harband · parent ed1b96f · Browse files · 7 files·+91 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+91 added−39 removed
- other:+91 added−39 removed
Provenance
- Commit
50e73c4- Tree
cb049fd- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
ed1b96f
7 files changed+91 added−39 removed
added:.github/scripts/apt-install.sh+49 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#!/bin/sh
# Install apt packages, riding out Ubuntu/Debian mirror outages: apt itself# retries each request, and the whole update+install is retried with backoff# for about 10 minutes, since outages have lasted longer than apt's own retries.## usage: sh .github/scripts/apt-install.sh <package>...# Runs apt-get through sudo when not root.
set -u
if [ "$#" -eq 0 ]; then echo 'usage: apt-install.sh <package>...' >&2 exit 2fi
SUDO=''if [ "$(id -u)" != '0' ]; then SUDO='sudo'fi
apt_get() { $SUDO env DEBIAN_FRONTEND=noninteractive apt-get \ -o Acquire::Retries=5 \ -o Acquire::http::Timeout=30 \ -o Acquire::https::Timeout=30 \ "$@"}
ATTEMPT=1MAX_ATTEMPTS=8DELAY=15while :; do apt_get update || echo "apt-get update failed (attempt ${ATTEMPT}/${MAX_ATTEMPTS})" >&2 if apt_get install -y "$@"; then exit 0 fi if [ "${ATTEMPT}" -ge "${MAX_ATTEMPTS}" ]; then echo "apt-get install failed after ${MAX_ATTEMPTS} attempts: $*" >&2 exit 1 fi echo "apt-get install failed (attempt ${ATTEMPT}/${MAX_ATTEMPTS}); retrying in ${DELAY}s" >&2 sleep "${DELAY}" ATTEMPT=$((ATTEMPT + 1)) DELAY=$((DELAY * 2)) if [ "${DELAY}" -gt 120 ]; then DELAY=120 fidonemodified:.github/workflows/tests-fast.yml+8 added-4 removed
58 unmodified lines59 git submodule sync --recursive60 git submodule update --init --recursive61 - name: Install zsh, additional shells, and awk variant62 run: |63- sudo apt-get update64- sudo apt-get install -y zsh ${{ matrix.awk }}63+ PACKAGES="zsh ${{ matrix.awk }}"64 if [ "${{ matrix.shell }}" != "sh" ] && [ "${{ matrix.shell }}" != "bash" ] && [ "${{ matrix.shell }}" != "zsh" ]; then66- sudo apt-get install -y ${{ matrix.shell }}65+ PACKAGES="${PACKAGES} ${{ matrix.shell }}"66 fi67+ sh .github/scripts/apt-install.sh ${PACKAGES}68 # Set the selected awk as the default69 sudo update-alternatives --set awk /usr/bin/${{ matrix.awk }}70 shell: bash71 - run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}121 unmodified lines193 - uses: actions/checkout@v6194 - uses: Vampire/setup-wsl@v7195 with:196 distribution: ${{ matrix.wsl-distrib }}197+ - name: Install packages with retries198+ # the Windows checkout has CRLF line endings199+ run: |200+ tr -d '\r' < "$(wslpath "${{ github.workspace }}")/.github/scripts/apt-install.sh" > /tmp/apt-install.sh197- additional-packages: git make zsh dash sudo curl wget ca-certificates nodejs npm201+ sh /tmp/apt-install.sh git make zsh dash sudo curl wget ca-certificates nodejs npm202 - name: 'Clone into the WSL filesystem as a non-root user'203 # the Windows checkout shows every file as executable, which urchin would run as tests204 run: |205 set -ex35 unmodified linesmodified:.github/workflows/tests-installation-iojs.yml+4 added-4 removed
50 unmodified lines5152535455565556585758596061626330 unmodified lines9495969798989910010110240 unmodified lines50 unmodified lines git submodule sync --recursive git submodule update --init --recursive - name: Install zsh and additional shells run: | sudo apt-get update sudo apt-get install -y zsh PACKAGES='zsh' if [ "${{ matrix.shell }}" != "sh" ] && [ "${{ matrix.shell }}" != "bash" ] && [ "${{ matrix.shell }}" != "zsh" ]; then sudo apt-get install -y ${{ matrix.shell }} PACKAGES="${PACKAGES} ${{ matrix.shell }}" fi sh .github/scripts/apt-install.sh ${PACKAGES} shell: bash - run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }} - run: wget --version - uses: ljharb/actions/node/install@main30 unmodified lines if [ -f /usr/local/bin/npx.bak ]; then sudo mv /usr/local/bin/npx.bak /usr/local/bin/npx; fi shell: bash - name: Restore curl if: always() run: sudo apt-get install curl -y run: sh .github/scripts/apt-install.sh curl shell: bash
installation_iojs_source_compile: permissions:40 unmodified linesmodified:.github/workflows/tests-installation-node.yml+2 added-14 removed
81 unmodified lines82 ubuntu:16.04 \83 bash -c '84 set -ex85 86- # Retry apt-get update up to 5 times due to flaky Ubuntu mirrors87- # apt-get update can return 0 even with partial failures, so check for warnings88- for i in 1 2 3 4 5; do89- if apt-get update 2>&1 | tee /tmp/apt-update.log | grep -qE "^(W:|E:|Err:)"; then90- echo "apt-get update had warnings/errors, attempt $i/5"91- cat /tmp/apt-update.log92- sleep $((i * 5))93- else94- break95- fi96- done97-98- apt-get install -y git curl wget make build-essential python zsh libssl-dev86+ sh /workspace/.github/scripts/apt-install.sh git curl wget make build-essential python zsh libssl-dev87 if [ "$TEST_SHELL" != "sh" ] && [ "$TEST_SHELL" != "bash" ]; then100- apt-get install -y $TEST_SHELL || true88+ sh /workspace/.github/scripts/apt-install.sh $TEST_SHELL || true89 fi90 91 # Use nvm to install Node.js for running urchin92 # Node 16 is the last version supporting GLIBC 2.23 (Ubuntu 16.04)34 unmodified linesmodified:.github/workflows/tests-xenial.yml+2 added-14 removed
77 unmodified lines78 ubuntu:16.04 \79 bash -c '80 set -ex81 82- # Retry apt-get update up to 5 times due to flaky Ubuntu mirrors83- # apt-get update can return 0 even with partial failures, so check for warnings84- for i in 1 2 3 4 5; do85- if apt-get update 2>&1 | tee /tmp/apt-update.log | grep -qE "^(W:|E:|Err:)"; then86- echo "apt-get update had warnings/errors, attempt $i/5"87- cat /tmp/apt-update.log88- sleep $((i * 5))89- else90- break91- fi92- done93-94- apt-get install -y git curl wget make build-essential python zsh libssl-dev82+ sh /workspace/.github/scripts/apt-install.sh git curl wget make build-essential python zsh libssl-dev83 if [ "$TEST_SHELL" != "sh" ] && [ "$TEST_SHELL" != "bash" ]; then96- apt-get install -y $TEST_SHELL || true84+ sh /workspace/.github/scripts/apt-install.sh $TEST_SHELL || true85 fi86 87 # Use nvm to install Node.js for running urchin88 # Node 16 is the last version supporting GLIBC 2.23 (Ubuntu 16.04)28 unmodified linesmodified:.github/workflows/tests.yml+1 added-1 removed
52 unmodified lines53 iojs.org:44354 azure.archive.ubuntu.com:8055 packages.microsoft.com:44356 - uses: actions/checkout@v657- - run: sudo apt-get update; sudo apt-get install ${{ matrix.shell }}57+ - run: sh .github/scripts/apt-install.sh ${{ matrix.shell }}58 if: matrix.shell == 'zsh' || matrix.shell == 'ksh'59 # zsh (https://github.com/actions/runner-images/issues/264) and ksh are not in the ubuntu image60 shell: bash61 - run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}32 unmodified linesmodified:.github/workflows/windows-nvm.yml+25 added-2 removed
143 unmodified lines144 method:145 - ''146 - 'script'147 steps:148- # For Ubuntu: install with packages directly148+ # For Ubuntu: `additional-packages` can't retry, so install in a separate step149 - if: ${{ !startsWith(matrix.wsl-distrib, 'Debian') }}150 uses: Vampire/setup-wsl@v7151 with:152 distribution: ${{ matrix.wsl-distrib }}153- additional-packages: bash git curl ca-certificates wget153+ # mirror outages can outlast apt's own retries, so retry update+install with154+ # backoff for about 10 minutes (as .github/scripts/apt-install.sh does; this155+ # job has no checkout)156+ - if: ${{ !startsWith(matrix.wsl-distrib, 'Debian') }}157+ name: 'Install packages with retries'158+ shell: 'wsl-bash {0}'159+ run: |160+ attempt=1161+ delay=15162+ while true; do163+ apt-get -o Acquire::Retries=5 update || true164+ if apt-get -o Acquire::Retries=5 install --yes bash git curl ca-certificates wget; then165+ break166+ fi167+ if [ "${attempt}" -ge 8 ]; then168+ echo "apt-get install failed after ${attempt} attempts" >&2169+ exit 1170+ fi171+ echo "apt-get install failed (attempt ${attempt}/8); retrying in ${delay}s" >&2172+ sleep "${delay}"173+ attempt=$((attempt + 1))174+ delay=$((delay * 2))175+ if [ "${delay}" -gt 120 ]; then delay=120; fi176+ done177 178 # For Debian, install without packages: `additional-packages` would run179 # `apt-get update` before we get to fix up sources.list180 # see https://github.com/Vampire/setup-wsl/issues/76124 unmodified lines