Dockerfile: retry add-apt-repository#22125
Conversation
Signed-off-by: Patrick Linnane <patrick@linnane.io>
There was a problem hiding this comment.
Pull request overview
This PR updates Homebrew’s Linux Docker image build to make repository setup more resilient during transient Launchpad failures. Specifically, it adds retry logic around the git-core PPA registration step in the Dockerfile, which supports the CI/container environments built from this image.
Changes:
- Wrap
add-apt-repository -y ppa:git-core/ppain a 5-attempt retry loop. - Keep the existing architecture guard so the PPA is still skipped on
aarch64. - Align the new retry behavior with the nearby
apt-get updateretry pattern already used in the Dockerfile.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Looks good when comment addressed!
When `apt-get update` fails to fetch from a repository due to a
transient network error, its default behavior is to issue a warning and
continue [^1]. When the git-core PPA is unavailable (which is currently
the case due to an ongoing DDoS incident), this causes `apt-get install`
to install an outdated version of `git` from the default Ubuntu
repositories.
To avoid this, let's set `--error-on=any` for `apt-get update`, which
causes it to error out on such transient network errors [^2]. This
option is available since Ubuntu 21.04 and is equivalent to the APT
option `APT::Update::Error-Mode=any` [^3].
See below how `--error-on=any` turns the warning into an error:
linuxbrew@c557e2acccfe:~$ sudo apt-get update
Hit:1 https://cli.github.com/packages stable InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease
Ign:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease
Ign:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease
Err:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease
Could not connect to ppa.launchpadcontent.net:443 (185.125.190.80), connection timed out
Reading package lists... Done
W: Failed to fetch https://ppa.launchpadcontent.net/git-core/ppa/ubuntu/dists/jammy/InRelease Could not connect to ppa.launchpadcontent.net:443 (185.125.190.80), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.
linuxbrew@c557e2acccfe:~$ sudo apt-get update --error-on=any
Hit:1 https://cli.github.com/packages stable InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease
Ign:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease
Ign:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease
Err:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease
Could not connect to ppa.launchpadcontent.net:443 (185.125.190.80), connection timed out
Reading package lists... Done
E: Failed to fetch https://ppa.launchpadcontent.net/git-core/ppa/ubuntu/dists/jammy/InRelease Could not connect to ppa.launchpadcontent.net:443 (185.125.190.80), connection timed out
E: Some index files failed to download. They have been ignored, or old ones used instead.
[^1]: https://github.com/Debian/apt/blob/6b128124271e94bdb0f4e7850d9286170d712b04/apt-pkg/update.cc#L136-L139
[^2]: https://manpages.debian.org/trixie/apt/apt-get.8.en.html
[^3]: https://lists.ubuntu.com/archives/ubuntu-devel/2021-February/041374.html
3633dbe to
520dc06
Compare
|
Sorry for hijacking the PR; I fixed Copilot's review comment in 2aece26 and added another fix in 520dc06 that prevents |
ShellCheck sees Dockerfile as a regular shell script, so it cannot understand it when the function definition `retry()` comes after the `RUN` command (it sees it as a single command `RUN retry() ...`). As this causes a parsing error, it cannot be worked around with a `# shellcheck disable` comment. Instead, let's add a no-op `:` command before the function definition, so that ShellCheck can happily parse the file.
90a8857 to
cbd36bc
Compare
brew lgtm(style, typechecking and tests) with your changes locally?Retry
add-apt-repositoryto work around intermittent 504s from Launchpad's API during the ongoing Canonical infrastructure DDoS (https://www.theregister.com/2026/05/01/canonical_confirms_ubuntu_infrastructure_under/).Mirrors the existing
apt-get updateretry on the line above.