baseManifest pointer not cleanup properly in writeOutput during join_layer causing loadForeignLayers failed
π bug report
Affected Rule
The issue is caused by the rule: container_bundleIs this a regression?
Not sure, but the part related to join_layer last update is 12 months ago https://github.com/bazelbuild/rules_docker/pull/1934
Description
A clear and concise description of the problem...During join_layer, some of images without baseManifest string provided will somehow used other image's base manifest which causing error in if len(r.config.RootFS.DiffIDs) < len(r.baseManifest.Layers) because r.baseManifest == nil is not empty. However this behavior is not deterministic as sometime the r.baseManifest pointer does get cleanup (although I couldn't find by which part of code).
π¬ Minimal Reproduction
π₯ Exception or Error
π Your Environment
Operating System:
5.18.16-1rodete1-amd64
Output of bazel version:
bazel 5.2.0
Rules_docker version:
v0.23.0
Anything else relevant?
Suggesting modifiction, reset baseManifest and config to nil should avoid reused other base manifest and config. It would be fine by resetting them because loadMetadata should get config and base manifest back if string arguments are provided
// ReadImage loads a v1.Image from the ImageParts section in the reader.
func (r *Reader) ReadImage() (v1.Image, error) {
// Special case: if we only have a tarball, we can instantiate the image
// directly from that. Otherwise, we'll process the image layers
// individually as specified in the config.
if r.Parts.ImageTarball != "" && r.Parts.Config == "" {
return tarball.ImageFromPath(r.Parts.ImageTarball, nil)
}
if r.Parts.BaseManifest == "" {
r.baseManifest = nil
}
if r.Parts.Config == "" {
r.config = nil
}
if r.layerLookup == nil {
r.layerLookup = make(map[v1.Hash]v1.Layer)
}
if r.loadedImageCache == nil {
r.loadedImageCache = make(map[v1.Hash]bool)
}
if err := r.loadMetadata(); err != nil {
return nil, errors.Wrap(err, "unable to load image metadata")
}
if err := r.loadForeignLayers(); err != nil {
return nil, errors.Wrap(err, "unable to load foreign layers specified in the base manifest")
}
if err := r.loadImages(r.Parts.Images); err != nil {
return nil, errors.Wrap(err, "unable to load layers from the images in the given image parts")
}
if err := r.loadImgTarball(); err != nil {
return nil, errors.Wrap(err, "unable to load layers from image tarball")
}
if err := r.loadLayers(); err != nil {
return nil, errors.Wrap(err, "unable to load layers from the given parts")
}
layers := []v1.Layer{}
for _, diffID := range r.config.RootFS.DiffIDs {
layer, ok := r.layerLookup[diffID]
if !ok {
return nil, errors.Errorf("unable to locate layer with diffID %v as indicated in image config %s", diffID, r.Parts.Config)
}
layers = append(layers, layer)
}
img := &legacyImage{
configPath: r.Parts.Config,
layers: layers,
}
if err := img.init(); err != nil {
return nil, errors.Wrap(err, "unable to initialize image from parts")
}
return img, nil
}
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!
This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"