Skip to content

Commit

Permalink
feat(export): export images concurrently(#6395)
Browse files Browse the repository at this point in the history
Signed-off-by: Yaroslav Pershin <62902094+iapershin@users.noreply.github.com>
  • Loading branch information
iapershin authored Nov 7, 2024
1 parent 2da1c0f commit de2f4a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/build/export_phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/werf/werf/v2/pkg/image"
"github.com/werf/werf/v2/pkg/storage"
"github.com/werf/werf/v2/pkg/util"
"github.com/werf/werf/v2/pkg/util/parallel"
)

type Exporter struct {
Expand All @@ -39,10 +40,16 @@ func (e *Exporter) Run(ctx context.Context) error {
return nil
}

for _, desc := range e.Conveyor.imagesTree.GetImagesByName(true) {
name, images := desc.Unpair()
if !slices.Contains(e.ExportImageNameList, name) {
continue
imageList := util.SliceToMapWithValue(e.ExportImageNameList, struct{}{})
images := e.Conveyor.imagesTree.GetImagesByName(true)

if err := parallel.DoTasks(ctx, len(e.ExportImageNameList), parallel.DoTasksOptions{
MaxNumberOfWorkers: int(e.Conveyor.ParallelTasksLimit),
}, func(ctx context.Context, taskId int) error {
pair := images[taskId]
name, images := pair.Unpair()
if _, ok := imageList[name]; !ok {
return nil
}

targetPlatforms := util.MapFuncToSlice(images, func(img *build_image.Image) string { return img.TargetPlatform })
Expand All @@ -64,6 +71,9 @@ func (e *Exporter) Run(ctx context.Context) error {
return fmt.Errorf("unable to export multiplatform image %q: %w", img.Name, err)
}
}
return nil
}); err != nil {
return fmt.Errorf("export failed: %w", err)
}

return nil
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ func MapFuncToSlice[T, RT any, FT func(T) RT](arr []T, f FT) (res []RT) {
}
return
}

func SliceToMapWithValue[K comparable, V any](keys []K, value V) map[K]V {
resultMap := make(map[K]V)
for _, key := range keys {
resultMap[key] = value
}
return resultMap
}

0 comments on commit de2f4a3

Please sign in to comment.