Skip to content

core: APT/APK Mirror Fallback for CDN Failures#13316

Merged
tremor021 merged 2 commits intomainfrom
cdn_improvements
Mar 26, 2026
Merged

core: APT/APK Mirror Fallback for CDN Failures#13316
tremor021 merged 2 commits intomainfrom
cdn_improvements

Conversation

@MickLesk
Copy link
Copy Markdown
Member

✍️ Description

Container creation fails when Debian/Ubuntu/Alpine CDN mirrors are unreachable, serve corrupted data (hash mismatch), or lack valid SSL certificates — especially in Asia/India.

Solution
Three-phase mirror fallback: Global → Primary → Regional → Manual prompt. Scans TCP reachability first, picks 3 random working mirrors per phase. Detects Debian vs Ubuntu automatically and uses the correct mirror pool. Alpine gets its own 8-mirror fallback.

Key decisions:

  • HTTP instead of HTTPS (most country mirrors lack valid SSL certs)
  • Global-first order (regional CDN is usually the broken one)

Example:

💡  apt-get update failed (deb.debian.org), trying alternate mirrors...
💡  Attempting mirror: ftp.jp.debian.org
⚠️  Mirror ftp.jp.debian.org failed (SSL/certificate error)
💡  Attempting mirror: ftp.it.debian.org
✔️  CDN set to ftp.it.debian.org: tests passed
✔️  Customized LXC Container

🔗 Related Issue

https://discord.com/channels/1302816934508630047/1486700783343894619

✅ Prerequisites (X in brackets)

  • Self-review completed – Code follows project standards.
  • Tested thoroughly – Changes work as expected.
  • No security risks – No hardcoded secrets, unnecessary privilege escalations, or permission issues.

🛠️ Type of Change (X in brackets)

  • 🐞 Bug fix – Resolves an issue without breaking functionality.
  • New feature – Adds new, non-breaking functionality.
  • 💥 Breaking change – Alters existing functionality in a way that may require updates.
  • 🆕 New script – A fully functional and tested script or script set.
  • 🌍 Website update – Changes to website-related JSON files or metadata.
  • 🔧 Refactoring / Code Cleanup – Improves readability or maintainability without changing functionality.
  • 📝 Documentation update – Changes to README, AppName.md, CONTRIBUTING.md, or other docs.

Improve robustness of package updates and installs by adding CDN/mirror fallback logic for Alpine and Debian/Ubuntu workflows.

- misc/alpine-install.func: update_os() now attempts apk -U upgrade and, on failure, iterates a shuffled list of alternate Alpine mirrors, writes /etc/apk/repositories, tests the mirror and falls back with clear warnings/errors if none succeed.

- misc/build.func: when apk add inside an Alpine container fails, run an in-container mirror scan that rewrites /etc/apk/repositories and retries apk update/add against multiple mirrors. Added a check to inject public DNS (8.8.8.8/1.1.1.1) into containers when APT repo DNS resolution fails.

- misc/build.func (Debian/Ubuntu path): expanded apt-get failure handling to detect the failing mirror, then run a multi-phase mirror scanner (global → primary → regional), detect hash/SSL errors, and prompt the user for a custom mirror if automatic attempts fail.

- misc/install.func: added apt_update_safe() implementing the apt-get update fallback logic (mirror lists, regional selection by timezone, reachable scanning, hash/SSL detection, and user prompt), returning failure if all mirrors fail.

These changes aim to mitigate CDN outages, broken CDNs/mirrors, or DNS issues during container builds and OS updates, improving reliability and providing clear messages and fallbacks when automatic fixes are exhausted.
@MickLesk MickLesk requested a review from a team as a code owner March 26, 2026 15:25
@tremor021 tremor021 merged commit d4e2081 into main Mar 26, 2026
2 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants