Skip to content

Commit

Permalink
Export cache image and app image in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ESWZY committed Jul 30, 2023
1 parent f8b3419 commit ba3365c
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions cmd/lifecycle/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strconv"
"sync"
"time"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -205,31 +206,46 @@ func (e *exportCmd) export(group buildpack.Group, cacheStore lifecycle.Cache, an
return err
}

report, err := exporter.Export(lifecycle.ExportOptions{
AdditionalNames: e.AdditionalTags,
AppDir: e.AppDir,
DefaultProcessType: e.DefaultProcessType,
ExtendedDir: e.ExtendedDir,
LauncherConfig: launcherConfig(e.LauncherPath, e.LauncherSBOMDir),
LayersDir: e.LayersDir,
OrigMetadata: analyzedMD.LayersMetadata,
Project: projectMD,
RunImageRef: runImageID,
RunImageForExport: runImageForExport,
WorkingImage: appImage,
})
var wg sync.WaitGroup
var report files.Report
err = nil

wg.Add(1)
go func() {
report, err = exporter.Export(lifecycle.ExportOptions{
AdditionalNames: e.AdditionalTags,
AppDir: e.AppDir,
DefaultProcessType: e.DefaultProcessType,
ExtendedDir: e.ExtendedDir,
LauncherConfig: launcherConfig(e.LauncherPath, e.LauncherSBOMDir),
LayersDir: e.LayersDir,
OrigMetadata: analyzedMD.LayersMetadata,
Project: projectMD,
RunImageRef: runImageID,
RunImageForExport: runImageForExport,
WorkingImage: appImage,
})
wg.Done()
}()

wg.Add(1)
go func() {
if cacheStore != nil {
if cacheErr := exporter.Cache(e.LayersDir, cacheStore); cacheErr != nil {
cmd.DefaultLogger.Warnf("Failed to export cache: %v\n", cacheErr)
}
}
wg.Done()
}()

wg.Wait()
if err != nil {
return cmd.FailErrCode(err, e.CodeFor(platform.ExportError), "export")
}
if err = encoding.WriteTOML(e.ReportPath, &report); err != nil {
return cmd.FailErrCode(err, e.CodeFor(platform.ExportError), "write export report")
}

if cacheStore != nil {
if cacheErr := exporter.Cache(e.LayersDir, cacheStore); cacheErr != nil {
cmd.DefaultLogger.Warnf("Failed to export cache: %v\n", cacheErr)
}
}
return nil
}

Expand Down

0 comments on commit ba3365c

Please sign in to comment.