Skip to content

Commit

Permalink
WIP - trying to find the concurrency issue
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante committed Jun 13, 2023
1 parent 18a1235 commit 285b0dc
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,13 +1166,19 @@ func explodeBuildModules(kind, tmpDir string, additionalModules []buildpack.Buil
// create directory
modTmpDir := filepath.Join(tmpDir, fmt.Sprintf("%s-%s", kind, strconv.Itoa(i)))
if err := os.MkdirAll(modTmpDir, os.ModePerm); err != nil {
lids[i] <- modInfo{err: errors.Wrapf(err, "creating %s temp dir", kind)}
moduleTar := &errModuleTar{
module: module,
}
lids[i] <- modInfo{moduleTars: []buildpack.ModuleTar{moduleTar}, err: errors.Wrapf(err, "creating %s temp dir", kind)}
}
moduleTars, err := buildpack.ToNLayerTar(kind, modTmpDir, module, logger)
if err != nil {
err = errors.Wrapf(err, "creating %s tar file", module.Descriptor().Info().FullName())
moduleTar := &errModuleTar{
module: module,
}
lids[i] <- modInfo{moduleTars: []buildpack.ModuleTar{moduleTar}, err: errors.Wrapf(err, "creating %s tar file", module.Descriptor().Info().FullName())}
}
lids[i] <- modInfo{moduleTars: moduleTars, err: err}
lids[i] <- modInfo{moduleTars: moduleTars}
}(i, module)
}

Expand All @@ -1182,32 +1188,34 @@ func explodeBuildModules(kind, tmpDir string, additionalModules []buildpack.Buil
for i := 0; i < len(lids); i++ {
mi := <-lids[i]
if mi.err != nil {
eBM := explodedBuildModule{err: mi.err}
result = append(result, eBM)
}
for _, moduleTar := range mi.moduleTars {
// it could be an individual buildpack or flattened buildpack that writes an empty tar on disk
eBM := explodedBuildModule{moduleTar: moduleTar}
diffID, err := dist.LayerDiffID(moduleTar.Path())
if err != nil {
eBM.err = err
// it means an individual or flattened Buildpack throw an error
eBM := explodedBuildModule{
moduleTar: mi.moduleTars[0], // we know it is associated with just one
err: mi.err,
}
if diffID.String() == "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" {
logger.Debugf("%s %s is a component of a flattened buildpack that will be added elsewhere, skipping...", istrings.Title(kind), style.Symbol(moduleTar.Info().FullName()))
continue // we don't need to keep empty tars
}
// it is an individual buildpack
eBM.diffIDs = diffID
result = append(result, eBM)
} else {
for _, moduleTar := range mi.moduleTars {
// it could be an individual Buildpack or flattened Buildpack that writes an empty tar on disk
eBM := explodedBuildModule{moduleTar: moduleTar}
diffID, err := dist.LayerDiffID(moduleTar.Path())
if err != nil {
eBM.err = err
}
if diffID.String() == "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" {
logger.Debugf("%s %s is a component of a flattened buildpack that will be added elsewhere, skipping...", istrings.Title(kind), style.Symbol(moduleTar.Info().FullName()))
continue // we don't need to keep empty tars
}
// it is an individual buildpack
eBM.diffIDs = diffID
result = append(result, eBM)
}
}
}

// we need to match the exploded modules with its corresponding BuildModule.
// this is important when flattened modules where included
for i, eBM := range result {
if eBM.err != nil {
continue
}
for _, module := range additionalModules {
if eBM.moduleTar.Info().FullName() == fmt.Sprintf("%s@%s", module.Descriptor().EscapedID(), module.Descriptor().Info().Version) ||
eBM.moduleTar.Info().FullName() == module.Descriptor().Info().FullName() {
Expand All @@ -1228,3 +1236,15 @@ func explodeBuildModules(kind, tmpDir string, additionalModules []buildpack.Buil

return result
}

type errModuleTar struct {
module buildpack.BuildModule
}

func (e *errModuleTar) Info() dist.ModuleInfo {
return e.module.Descriptor().Info()
}

func (e *errModuleTar) Path() string {
return ""
}

0 comments on commit 285b0dc

Please sign in to comment.