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

Fixes for imgutil from recent refactor #267

Merged
merged 3 commits into from
Apr 16, 2024
Merged

Fixes for imgutil from recent refactor #267

merged 3 commits into from
Apr 16, 2024

Conversation

natalieparellano
Copy link
Member

As surfaced in buildpacks/lifecycle#1335

@@ -46,6 +46,11 @@ func (i *Image) Identifier() (imgutil.Identifier, error) {
}, nil
}

func (i *Image) Valid() bool {
// local images are actually always invalid, because they are missing a manifest, but let's ignore that for now
Copy link
Member Author

Choose a reason for hiding this comment

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

This was causing the analyzer not to ever find the previous image

layer, err := store.LayerByDiffID(diffID)
if err == nil {
return layer.Size()
}
if err = store.downloadLayersFor(imageID); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops! We may ask a layer for its size just to construct a (missing stuff but good enough for our purposes) manifest. I didn't catch this in my earlier performance testing because the tests for WithPreviousImage (where this is relevant) use a hard-coded image, not the "runnable base image".

Previously, we forced the layer to be downloaded by asking for its size.
But, this has performance implications when you only need the size to construct a manifest.
Now, we force the layer to be downloaded by opening a ReadCloser to the layer,
and size only reports if the layer is present on disk, it doesn't cause the layer to be downloaded.

Signed-off-by: Natalie Arellano <[email protected]>
Comment on lines -224 to -230
if size == -1 { // layer facade fronting empty layer
layerName = fmt.Sprintf("blank_%d", blankIdx)
blankIdx++
hdr := &tar.Header{Name: layerName, Mode: 0644, Size: 0}
if err := tw.WriteHeader(hdr); err != nil {
return err
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to s.addLayerToTar

func (s *Store) addLayerToTar(tw *tar.Writer, layer v1.Layer, blankIdx *int) (string, error) {
// If the layer is a previous image layer that hasn't been downloaded yet,
// cause ALL the previous image layers to be downloaded by grabbing the ReadCloser.
layerReader, err := layer.Uncompressed()
Copy link
Member Author

@natalieparellano natalieparellano Apr 15, 2024

Choose a reason for hiding this comment

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

Previously, we forced the layer to be downloaded by asking for its size.
But, this has performance implications when you only need the size to construct a manifest.
Now, we force the layer to be downloaded by opening a ReadCloser to the layer,
and size only reports if the layer is present on disk, it doesn't cause the layer to be downloaded.

I'm not sure how this ever worked

Signed-off-by: Natalie Arellano <[email protected]>
@natalieparellano natalieparellano marked this pull request as ready for review April 15, 2024 20:28
@natalieparellano natalieparellano requested a review from a team as a code owner April 15, 2024 20:28
@natalieparellano
Copy link
Member Author

@jabrown85 @jjbustamante one more... 🤦🏼‍♀️

@natalieparellano natalieparellano merged commit bef4977 into main Apr 16, 2024
3 checks passed
@natalieparellano natalieparellano deleted the fixes branch April 16, 2024 15:10
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