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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions cnb_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/google/go-containerregistry/pkg/v1/validate"
)

// CNBImageCore wraps a v1.Image and provides most of the methods necessary for the image to satisfy the Image interface.
Expand Down Expand Up @@ -184,11 +183,6 @@ func (i *CNBImageCore) UnderlyingImage() v1.Image {
return i.Image
}

func (i *CNBImageCore) Valid() bool {
err := validate.Image(i.Image)
return err == nil
}

// TBD Deprecated: Variant
func (i *CNBImageCore) Variant() (string, error) {
configFile, err := getConfigFile(i.Image)
Expand Down
5 changes: 5 additions & 0 deletions layout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func (i *Image) Identifier() (imgutil.Identifier, error) {
return newLayoutIdentifier(i.repoPath, hash)
}

func (i *Image) Valid() bool {
// layout images may be invalid if they are missing layer data
return true
}

func (i *Image) Delete() error {
return os.RemoveAll(i.repoPath)
}
5 changes: 5 additions & 0 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

return true
}

// GetLayer returns an io.ReadCloser with uncompressed layer data.
// The layer will always have data, even if that means downloading ALL the image layers from the daemon.
func (i *Image) GetLayer(diffID string) (io.ReadCloser, error) {
Expand Down
19 changes: 6 additions & 13 deletions local/v1_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var _ v1.Layer = &v1LayerFacade{}
type v1LayerFacade struct {
diffID v1.Hash
uncompressed func() (io.ReadCloser, error)
size func() (int64, error)
sentinelSize func() (int64, error)
}

func newEmptyLayer(diffID v1.Hash, store *Store) *v1LayerFacade {
Expand All @@ -197,7 +197,7 @@ func newEmptyLayer(diffID v1.Hash, store *Store) *v1LayerFacade {
}
return io.NopCloser(bytes.NewReader([]byte{})), nil
},
size: func() (int64, error) {
sentinelSize: func() (int64, error) {
layer, err := store.LayerByDiffID(diffID)
if err == nil {
return layer.Size()
Expand All @@ -224,19 +224,12 @@ func newDownloadableEmptyLayer(diffID v1.Hash, store *Store, imageID string) *v1
}
return nil, err
},
size: func() (int64, error) {
sentinelSize: func() (int64, error) {
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".

return -1, err
}
layer, err = store.LayerByDiffID(diffID)
if err == nil {
return layer.Size()
}
return -1, err
return -1, nil
},
}
}
Expand All @@ -251,7 +244,7 @@ func newPopulatedLayer(diffID v1.Hash, fromPath string, sentinelSize int64) *v1L
}
return f, nil
},
size: func() (int64, error) {
sentinelSize: func() (int64, error) {
return sentinelSize, nil
},
}
Expand Down Expand Up @@ -287,7 +280,7 @@ func (l *v1LayerFacade) Uncompressed() (io.ReadCloser, error) {

// Size returns a sentinel value indicating if the layer has data.
func (l *v1LayerFacade) Size() (int64, error) {
return l.size()
return l.sentinelSize()
}

func (l *v1LayerFacade) MediaType() (v1types.MediaType, error) {
Expand Down
4 changes: 0 additions & 4 deletions remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ func (i *Image) Identifier() (imgutil.Identifier, error) {
}

// Valid returns true if the (saved) image is valid.
// It differs from CNBImageCore.Valid() in that the latter validates the current working image (not what is already saved).
// Additionally, when the repoName for the image is a manifest list, this method validates the entire index.
// Finally, this method uses validate.Fast, whereas CNBImageCore.Valid() does not.
// FIXME: see if this can be combined with CNBImageCore.Valid()
func (i *Image) Valid() bool {
return i.valid() == nil
}
Expand Down
Loading