From ba3365cb2968702b0a2c8900c18574eb3f31d53e Mon Sep 17 00:00:00 2001 From: Woa Date: Sun, 30 Jul 2023 12:38:34 +0800 Subject: [PATCH] Export cache image and app image in parallel --- cmd/lifecycle/exporter.go | 52 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/cmd/lifecycle/exporter.go b/cmd/lifecycle/exporter.go index f45d2be8c..2d1629fd9 100644 --- a/cmd/lifecycle/exporter.go +++ b/cmd/lifecycle/exporter.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "strconv" + "sync" "time" "github.com/BurntSushi/toml" @@ -205,19 +206,39 @@ 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") } @@ -225,11 +246,6 @@ func (e *exportCmd) export(group buildpack.Group, cacheStore lifecycle.Cache, an 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 }