MCPcopy Create free account
hub / github.com/buildpacks/pack / addExplodedModules

Method addExplodedModules

internal/builder/builder.go:663–727  ·  view source on GitHub ↗

Helpers

(kind string, logger logging.Logger, tmpDir string, image imgutil.Image, additionalModules []buildpack.BuildModule, layers dist.ModuleLayers)

Source from the content-addressed store, hash-verified

661// Helpers
662
663func (b *Builder) addExplodedModules(kind string, logger logging.Logger, tmpDir string, image imgutil.Image, additionalModules []buildpack.BuildModule, layers dist.ModuleLayers) error {
664 collectionToAdd := map[string]moduleWithDiffID{}
665 toAdd, errs := explodeModules(kind, tmpDir, additionalModules, logger)
666 if len(errs) > 0 {
667 return e.Join(errs...)
668 }
669
670 for i, additionalModule := range toAdd {
671 info, diffID, layerTar, module := additionalModule.module.Descriptor().Info(), additionalModule.diffID, additionalModule.tarPath, additionalModule.module
672
673 // check against builder layers
674 if existingInfo, ok := layers[info.ID][info.Version]; ok {
675 if existingInfo.LayerDiffID == diffID {
676 logger.Debugf("%s %s already exists on builder with same contents, skipping...", istrings.Title(kind), style.Symbol(info.FullName()))
677 continue
678 } else {
679 whiteoutsTar, err := b.whiteoutLayer(tmpDir, i, info)
680 if err != nil {
681 return err
682 }
683
684 if err := image.AddLayer(whiteoutsTar); err != nil {
685 return errors.Wrap(err, "adding whiteout layer tar")
686 }
687 }
688
689 logger.Debugf(ModuleOnBuilderMessage, kind, style.Symbol(info.FullName()), style.Symbol(existingInfo.LayerDiffID), style.Symbol(diffID))
690 }
691
692 // check against other modules to be added
693 if otherAdditionalMod, ok := collectionToAdd[info.FullName()]; ok {
694 if otherAdditionalMod.diffID == diffID {
695 logger.Debugf("%s %s with same contents is already being added, skipping...", istrings.Title(kind), style.Symbol(info.FullName()))
696 continue
697 }
698
699 logger.Debugf(ModulePreviouslyDefinedMessage, kind, style.Symbol(info.FullName()), style.Symbol(otherAdditionalMod.diffID), style.Symbol(diffID))
700 }
701
702 // note: if same id@version is in additionalModules, last one wins (see warnings above)
703 collectionToAdd[info.FullName()] = moduleWithDiffID{
704 tarPath: layerTar,
705 diffID: diffID,
706 module: module,
707 }
708 }
709
710 // Fixes 1453
711 keys := sortKeys(collectionToAdd)
712 for _, k := range keys {
713 module := collectionToAdd[k]
714 logger.Debugf("Adding %s %s (diffID=%s)", kind, style.Symbol(module.module.Descriptor().Info().FullName()), module.diffID)
715 if err := image.AddLayerWithDiffID(module.tarPath, module.diffID); err != nil {
716 return errors.Wrapf(err,
717 "adding layer tar for %s %s",
718 kind,
719 style.Symbol(module.module.Descriptor().Info().FullName()),
720 )

Callers 1

SaveMethod · 0.95

Calls 8

whiteoutLayerMethod · 0.95
explodeModulesFunction · 0.85
sortKeysFunction · 0.85
InfoMethod · 0.65
DescriptorMethod · 0.65
DebugfMethod · 0.65
FullNameMethod · 0.65
AddLayerWithDiffIDMethod · 0.65

Tested by

no test coverage detected