Skip to content

Commit ddd804f

Browse files
iapershinalexey-igrychev
authored andcommitted
feat(export): export images concurrently(#6395)
Signed-off-by: Yaroslav Pershin <62902094+iapershin@users.noreply.github.com>
1 parent 1752e91 commit ddd804f

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

pkg/build/build_phase.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/werf/werf/pkg/storage"
3333
"github.com/werf/werf/pkg/storage/manager"
3434
"github.com/werf/werf/pkg/util"
35+
"github.com/werf/werf/pkg/util/parallel"
3536
"github.com/werf/werf/pkg/werf"
3637
)
3738

@@ -156,7 +157,7 @@ func GenerateImageEnv(werfImageName, imageName string) string {
156157
imageEnvName = "WERF_DOCKER_IMAGE_NAME"
157158
} else {
158159
werfImageName := strings.ToUpper(werfImageName)
159-
for _, l := range []string{"/", "-"} {
160+
for _, l := range []string{"/", "-", "."} {
160161
werfImageName = strings.ReplaceAll(werfImageName, l, "_")
161162
}
162163

@@ -285,6 +286,10 @@ func (phase *BuildPhase) AfterImages(ctx context.Context) error {
285286
}
286287
}
287288
}
289+
290+
return nil
291+
}); err != nil {
292+
return err
288293
}
289294

290295
return phase.createReport(ctx)

pkg/build/export_phase.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/werf/werf/pkg/image"
1515
"github.com/werf/werf/pkg/storage"
1616
"github.com/werf/werf/pkg/util"
17+
"github.com/werf/werf/pkg/util/parallel"
1718
)
1819

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

42-
for _, desc := range e.Conveyor.imagesTree.GetImagesByName(true) {
43-
name, images := desc.Unpair()
44-
if !slices.Contains(e.ExportImageNameList, name) {
45-
continue
43+
imageList := util.SliceToMapWithValue(e.ExportImageNameList, struct{}{})
44+
images := e.Conveyor.imagesTree.GetImagesByName(true)
45+
46+
if err := parallel.DoTasks(ctx, len(e.ExportImageNameList), parallel.DoTasksOptions{
47+
MaxNumberOfWorkers: int(e.Conveyor.ParallelTasksLimit),
48+
}, func(ctx context.Context, taskId int) error {
49+
pair := images[taskId]
50+
name, images := pair.Unpair()
51+
if _, ok := imageList[name]; !ok {
52+
return nil
4653
}
4754

4855
targetPlatforms := util.MapFuncToSlice(images, func(img *build_image.Image) string { return img.TargetPlatform })
@@ -55,7 +62,7 @@ func (e *Exporter) Run(ctx context.Context) error {
5562
// FIXME(multiarch): Support multiplatform manifest by pushing local images to repo first, then create manifest list.
5663
// FIXME(multiarch): Also support multiplatform manifest in werf build command in local mode with enabled final-repo.
5764
if _, isLocal := e.Conveyor.StorageManager.GetStagesStorage().(*storage.LocalStagesStorage); isLocal {
58-
return fmt.Errorf("export command is not supported in multiplatform mode")
65+
return fmt.Errorf("export command in multiplatform mode should be used with remote stages storage")
5966
}
6067

6168
// multiplatform mode
@@ -64,6 +71,9 @@ func (e *Exporter) Run(ctx context.Context) error {
6471
return fmt.Errorf("unable to export multiplatform image %q: %w", img.Name, err)
6572
}
6673
}
74+
return nil
75+
}); err != nil {
76+
return fmt.Errorf("export failed: %w", err)
6777
}
6878

6979
return nil

pkg/util/slice.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ func MapFuncToSlice[T, RT any, FT func(T) RT](arr []T, f FT) (res []RT) {
66
}
77
return
88
}
9+
10+
func SliceToMapWithValue[K comparable, V any](keys []K, value V) map[K]V {
11+
resultMap := make(map[K]V)
12+
for _, key := range keys {
13+
resultMap[key] = value
14+
}
15+
return resultMap
16+
}

0 commit comments

Comments
 (0)