Fix Docker build failure due to stale apt cache - #521
Conversation
Add apt-get update before adding deadsnakes PPA to ensure base Ubuntu package lists are refreshed. This prevents 404 errors for packages like libexpat1 that have been updated in Ubuntu's security repository. The build was failing because Docker cached the apt package index from the earlier layer, which referenced old package versions (libexpat1 2.4.7-1ubuntu0.7) that are no longer available on the mirrors. Authored-by: egg
There was a problem hiding this comment.
Review: Approve
The fix is correct and appropriate for the problem described.
Analysis
Root cause understanding is accurate. When a previous RUN layer has rm -rf /var/lib/apt/lists/* at the end (as lines 31 and 39 do), the next apt-get install requires a fresh apt-get update. The Python 3.11 block was missing this because it assumed add-apt-repository -y would refresh the cache. While add-apt-repository does call apt-get update, it only refreshes the newly-added PPA sources, not the base Ubuntu package lists.
The fix is correct. Adding apt-get update before add-apt-repository ensures:
- Base Ubuntu package lists are refreshed (fixing the stale libexpat1 issue)
- The subsequent
apt-get updateafteradd-apt-repositoryadds the deadsnakes PPA packages
The comment explains the reasoning well. Future maintainers will understand why there are two apt-get update calls.
Minor observations (not blocking)
-
Pre-existing: Missing apt cleanup. The Python 3.11 block (lines 46-53) and docker-setup block (lines 60-63) don't have
rm -rf /var/lib/apt/lists/*at the end, unlike the earlier RUN blocks. This slightly increases image size but doesn't affect correctness. Not introduced by this PR. -
Build caching behavior. This change will bust the cache for all subsequent layers since it modifies an earlier RUN instruction. This is expected and acceptable given the fix is necessary.
— Authored by egg
This comment has been minimized.
This comment has been minimized.
| egg is addressing review feedback... |
|
egg feedback addressed. View run logs 1 previous review(s) hidden. |
Summary
Fix Docker build failure caused by stale apt package cache, which resulted in 404 errors when trying to install
libexpat1andlibexpat1-dev.The build was failing with:
Root cause: Docker's layer caching preserved the apt package index from a previous layer, but Ubuntu's mirrors have since removed the old package versions that the cached index referenced.
Fix: Add
apt-get updatebefore adding the deadsnakes PPA to ensure base Ubuntu package lists are refreshed before any package installation.Issue: Fixes release build for #517
Test plan
Authored-by: egg