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

fix: prevent layer overwrites in image resulting in BLOB_UNKNOWN error #35

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
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
17 changes: 17 additions & 0 deletions pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,23 @@ func (s *stageBuilder) saveLayerToImage(layer v1.Layer, createdBy string) error
if err != nil {
return err
}

// Images in google/go-containerregistry don't support adding unique layers
// with duplicate diff IDs. For example, if the source image has an empty
// layer which has been compressed with Gzip level 3, and the layer we're
// adding is also an empty layer compressed with Gzip level 1, the diff IDs
// would match but the layer blobs would be different. This would cause an
// error when trying to upload the image to a registry as the manifest is
// referencing a blob that has been "overwritten".
diffID, err := layer.DiffID()
if err != nil {
return errors.Wrap(err, "checking layer diffID failed")
}
if el, err := s.image.LayerByDiffID(diffID); err == nil {
logrus.Debugf("Layer already exists in image, using existing layer: %s", diffID)
layer = el
}

s.image, err = mutate.Append(s.image,
mutate.Addendum{
Layer: layer,
Expand Down
Loading