Skip to content

Commit

Permalink
Export cache image and app image in parallel
Browse files Browse the repository at this point in the history
Signed-off-by: Woa <[email protected]>
  • Loading branch information
ESWZY committed Aug 15, 2023
1 parent f8b3419 commit b217dbb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
2 changes: 2 additions & 0 deletions acceptance/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ func testExporterFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
)
h.AssertStringContains(t, output, "Saving "+exportedImageName)

// To detect whether the export of cacheImage and exportedImage is successful
h.Run(t, exec.Command("docker", "pull", cacheImageName))
h.Run(t, exec.Command("docker", "pull", exportedImageName))
assertImageOSAndArchAndCreatedAt(t, exportedImageName, exportTest, imgutil.NormalizedDateTime)
})
Expand Down
56 changes: 36 additions & 20 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,
})
if err != nil {
return cmd.FailErrCode(err, e.CodeFor(platform.ExportError), "export")
var exportWaitGroup sync.WaitGroup
var report files.Report
var appErr error

exportWaitGroup.Add(1)
go func() {
defer exportWaitGroup.Done()
report, appErr = 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,
})
}()

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

exportWaitGroup.Wait()
if appErr != nil {
return cmd.FailErrCode(appErr, 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 b217dbb

Please sign in to comment.