Skip to content

Commit

Permalink
fix(export): resolve issue with exporting specific images (#6471)
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 and alexey-igrychev committed Dec 5, 2024
1 parent 41b76ca commit fd7a569
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
19 changes: 7 additions & 12 deletions pkg/build/export_phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,17 @@ func (e *Exporter) Run(ctx context.Context) error {
return nil
}

imageList := util.SliceToMapWithValue(e.ExportImageNameList, struct{}{})
images := e.Conveyor.imagesTree.GetImagesByName(true)

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

targetPlatforms := util.MapFuncToSlice(images, func(img *build_image.Image) string { return img.TargetPlatform })
targetPlatforms := util.MapFuncToSlice(imagesToExport, func(img *build_image.Image) string { return img.TargetPlatform })
if len(targetPlatforms) == 1 {
img := images[0]
img := imagesToExport[0]
if err := e.exportImage(ctx, img); err != nil {
return fmt.Errorf("unable to export image %q: %w", img.Name, err)
}
Expand All @@ -81,7 +76,7 @@ func (e *Exporter) Run(ctx context.Context) error {
}

func (e *Exporter) exportMultiplatformImage(ctx context.Context, img *build_image.MultiplatformImage) error {
return logboek.Context(ctx).Default().LogProcess("Exporting image...").
return logboek.Context(ctx).Default().LogProcess(fmt.Sprintf("Exporting image %s", img.Name)).
Options(func(options types.LogProcessOptionsInterface) {
options.Style(style.Highlight())
}).
Expand Down Expand Up @@ -113,7 +108,7 @@ func (e *Exporter) exportImage(ctx context.Context, img *build_image.Image) erro
return nil
}

return logboek.Context(ctx).Default().LogProcess("Exporting image...").
return logboek.Context(ctx).Default().LogProcess(fmt.Sprintf("Exporting image %s", img.Name)).
Options(func(options types.LogProcessOptionsInterface) {
options.Style(style.Highlight())
}).
Expand Down
27 changes: 26 additions & 1 deletion pkg/build/image/image_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,27 @@ func (tree *ImagesTree) Calculate(ctx context.Context) error {
return nil
}

func (tree *ImagesTree) GetImagesByName(onlyFinal bool) []util.Pair[string, []*Image] {
type GetImagesByNameOption func(*getImagesByNameConfig)

type getImagesByNameConfig struct {
compareWithImagesList bool
exportImageNameList map[string]struct{}
}

func WithExportImageNameList(l []string) GetImagesByNameOption {
return func(config *getImagesByNameConfig) {
config.exportImageNameList = util.SliceToMapWithValue(l, struct{}{})
config.compareWithImagesList = true
}
}

func (tree *ImagesTree) GetImagesByName(onlyFinal bool, opts ...GetImagesByNameOption) []util.Pair[string, []*Image] {
config := &getImagesByNameConfig{}

for _, opt := range opts {
opt(config)
}

images := make(map[string]map[string]*Image)
var names []string

Expand All @@ -145,6 +165,11 @@ func (tree *ImagesTree) GetImagesByName(onlyFinal bool) []util.Pair[string, []*I
if onlyFinal && !img.IsFinal {
continue
}
if config.compareWithImagesList {
if _, ok := config.exportImageNameList[img.Name]; !ok {
continue
}
}
appendImage(img)
}

Expand Down

0 comments on commit fd7a569

Please sign in to comment.