fix: apt install with mirrors #1972
Merged
+156
−39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary: This commit adds mirror fallback support to apt-get install commands in the bootstrap script.
What was the problem?
The script already had apt_update_with_fallback for apt-get update, but apt-get install commands were still using direct calls without fallback. This meant if a package mirror
returned a 404, hash mismatch, or size mismatch error during installation, the build would fail even though another mirror might have the packages.
What changes were made?
- get_current_mirror() - extracts current mirror from sources.list
- switch_mirror() - changes the mirror in sources.list
- get_mirror_list() - returns ordered list of mirrors to try (regional CDN first, then global fallback)
- Wraps apt-get install with automatic mirror retry logic
- Detects 404, "Failed to fetch", hash mismatch, and size mismatch errors
- Re-runs apt-get update when switching mirrors to refresh package lists
- Cleans apt cache between retries to force re-download
- Uses progressive backoff between attempts
- Non-mirror errors (like dependency issues) fail immediately without retry
- Boot packages (linux-aws, grub-pc, e2fsprogs)
- Standard packages (sudo, wget, cloud-init, etc.)
- Universe packages (openssh-server, git, ufw, etc.)
- ARM64-specific packages
- AppArmor packages
- GRUB packages for ARM64