Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apt: fix potential issue from prior build errors in cache #466

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

cpuguy83
Copy link
Member

@cpuguy83 cpuguy83 commented Dec 9, 2024

In some cases, if apt update had an error, the content apt update
was trying to fetch will be stored in /var/lib/apt/lists/partial.
In Dalec, /var/lib/apt/lists is a persistent cache.
As a note: apt update does not exit non-zero here, but apt install
might... depending on if the package is already in the local package
cache, which can make finding this issue pretty difficult.

For certain errors this can make builds unrecoverable since there's no
real way to clean up this cache outside of blowing away the entire build
cache.

This change just clears out anything in /var/lib/apt/lists/partial
before calling apt update since it should not be needed anyway and is
potentially problematic to have.


The issue here is sometimes a user can provide bad input (like gpg keys with the wrong permissions) and the user cannot recover from this on their own even if they fix the perms.

In some cases, if `apt update` had an error, the content `apt update`
was trying to fetch will be stored in `/var/lib/apt/lists/partial`.
In Dalec, `/var/lib/apt/lists` is a persistent cache.
As a note: `apt update` does not exit non-zero here, but `apt install`
might... depending on if the package is already in the local package
cache, which can make finding this issue pretty difficult.

For certain errors this can make builds unrecoverable since there's no
real way to clean up this cache outside of blowing away the entire build
cache.

This change just clears out anything in `/var/lib/apt/lists/partial`
before calling `apt update` since it should not be needed anyway and is
potentially problematic to have.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This removes some extra copy operations required to use repo keys and
configs.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@cpuguy83 cpuguy83 requested a review from a team as a code owner December 9, 2024 20:33
@@ -507,7 +507,7 @@ func repoConfigAsMount(config PackageRepositoryConfig, platformCfg *RepoPlatform

for name, repoConfig := range config.Config {
// each of these sources represent a repo config file
repoConfigSt, err := repoConfig.AsState(name, sOpt, append(opts, ProgressGroup("Importing repo config: "+name))...)
repoConfigSt, err := repoConfig.AsMount(name, sOpt, append(opts, ProgressGroup("Importing repo config: "+name))...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between AsMount and AsState?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this in the second commit.
This is a minor optimization that avoids an extra copy operation.

The difference between AsState and AsMount is that AsMount expects that you are going to mount the returned state somewhere and can just use llb.SourcePath in that mount call rather than copying the data from the subpath into the root of a new llb.State

Basically, when using AsMount you need to create a mount that points at the requested subpath.
When using AsState, the state itself reflects that subpath but can require an extra copy (depending on the source type).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I see it now:

This removes some extra copy operations required to use repo keys and
configs.

Ok yeah that makes sense as an optimization. Thanks for clarifying!

@cpuguy83 cpuguy83 merged commit 5d1ba5a into Azure:main Dec 10, 2024
9 checks passed
@cpuguy83 cpuguy83 deleted the apt_corrupt_cache branch December 10, 2024 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants