@@ -187,18 +187,41 @@ func (phase *BuildPhase) BeforeImages(ctx context.Context) error {
187187}
188188
189189func (phase * BuildPhase ) AfterImages (ctx context.Context ) error {
190- targetPlatforms , err := phase .Conveyor .GetTargetPlatforms ()
190+ forcedTargetPlatforms := phase .Conveyor .GetForcedTargetPlatforms ()
191+ commonTargetPlatforms , err := phase .Conveyor .GetTargetPlatforms ()
191192 if err != nil {
192- return fmt .Errorf ("unable to get target platforms: %w" , err )
193+ return fmt .Errorf ("invalid common target platforms: %w" , err )
193194 }
194- if len (targetPlatforms ) == 0 {
195- targetPlatforms = []string {phase .Conveyor .ContainerBackend .GetDefaultPlatform ()}
195+ if len (commonTargetPlatforms ) == 0 {
196+ commonTargetPlatforms = []string {phase .Conveyor .ContainerBackend .GetDefaultPlatform ()}
196197 }
197198
198199 for _ , desc := range phase .Conveyor .imagesTree .GetImagesByName (false ) {
199200 name , images := desc .Unpair ()
200201 platforms := util .MapFuncToSlice (images , func (img * image.Image ) string { return img .TargetPlatform })
201202
203+ // TODO: this target platforms assertion could be removed in future versions and now exists only as a additional self-testing code
204+ var targetPlatforms []string
205+ if len (forcedTargetPlatforms ) > 0 {
206+ targetPlatforms = forcedTargetPlatforms
207+ } else {
208+ targetName := name
209+ nameParts := strings .SplitN (name , "/" , 3 )
210+ if len (nameParts ) == 3 && nameParts [1 ] == "stage" {
211+ targetName = nameParts [0 ]
212+ }
213+
214+ imageTargetPlatforms , err := phase .Conveyor .GetImageTargetPlatforms (targetName )
215+ if err != nil {
216+ return fmt .Errorf ("invalid image %q target platforms: %w" , name , err )
217+ }
218+ if len (imageTargetPlatforms ) > 0 {
219+ targetPlatforms = imageTargetPlatforms
220+ } else {
221+ targetPlatforms = commonTargetPlatforms
222+ }
223+ }
224+
202225 AssertAllTargetPlatformsPresent:
203226 for _ , targetPlatform := range targetPlatforms {
204227 for _ , platform := range platforms {
@@ -426,49 +449,38 @@ func (phase *BuildPhase) publishMultiplatformImageMetadata(ctx context.Context,
426449}
427450
428451func (phase * BuildPhase ) createReport (ctx context.Context ) error {
429- targetPlatforms , err := phase .Conveyor .GetTargetPlatforms ()
430- if err != nil {
431- return fmt .Errorf ("invalid target platforms: %w" , err )
432- }
433- if len (targetPlatforms ) == 0 {
434- targetPlatforms = []string {phase .Conveyor .ContainerBackend .GetDefaultPlatform ()}
435- }
436-
437- for _ , img := range phase .Conveyor .imagesTree .GetImages () {
438- if ! img .IsFinal () {
439- continue
440- }
452+ for _ , desc := range phase .Conveyor .imagesTree .GetImagesByName (true ) {
453+ name , images := desc .Unpair ()
454+ targetPlatforms := util .MapFuncToSlice (images , func (img * image.Image ) string { return img .TargetPlatform })
441455
442- stageImage := img .GetLastNonEmptyStage ().GetStageImage ().Image
443- desc := stageImage .GetFinalStageDescription ()
444- if desc == nil {
445- desc = stageImage .GetStageDescription ()
446- }
456+ for _ , img := range images {
457+ stageImage := img .GetLastNonEmptyStage ().GetStageImage ().Image
458+ desc := stageImage .GetFinalStageDescription ()
459+ if desc == nil {
460+ desc = stageImage .GetStageDescription ()
461+ }
447462
448- record := ReportImageRecord {
449- WerfImageName : img .GetName (),
450- DockerRepo : desc .Info .Repository ,
451- DockerTag : desc .Info .Tag ,
452- DockerImageID : desc .Info .ID ,
453- DockerImageDigest : desc .Info .RepoDigest ,
454- DockerImageName : desc .Info .Name ,
455- Rebuilt : img .GetRebuilt (),
456- }
463+ record := ReportImageRecord {
464+ WerfImageName : img .GetName (),
465+ DockerRepo : desc .Info .Repository ,
466+ DockerTag : desc .Info .Tag ,
467+ DockerImageID : desc .Info .ID ,
468+ DockerImageDigest : desc .Info .RepoDigest ,
469+ DockerImageName : desc .Info .Name ,
470+ Rebuilt : img .GetRebuilt (),
471+ }
457472
458- if os .Getenv ("WERF_ENABLE_REPORT_BY_PLATFORM" ) == "1" {
459- phase .ImagesReport .SetImageByPlatformRecord (img .TargetPlatform , img .GetName (), record )
460- }
461- if len (targetPlatforms ) == 1 {
462- phase .ImagesReport .SetImageRecord (img .Name , record )
473+ if os .Getenv ("WERF_ENABLE_REPORT_BY_PLATFORM" ) == "1" {
474+ phase .ImagesReport .SetImageByPlatformRecord (img .TargetPlatform , img .GetName (), record )
475+ }
476+ if len (targetPlatforms ) == 1 {
477+ phase .ImagesReport .SetImageRecord (img .Name , record )
478+ }
463479 }
464- }
465480
466- if _ , isLocal := phase .Conveyor .StorageManager .GetStagesStorage ().(* storage.LocalStagesStorage ); ! isLocal {
467- if len (targetPlatforms ) > 1 {
468- for _ , img := range phase .Conveyor .imagesTree .GetMultiplatformImages () {
469- if ! img .IsFinal () {
470- continue
471- }
481+ if _ , isLocal := phase .Conveyor .StorageManager .GetStagesStorage ().(* storage.LocalStagesStorage ); ! isLocal {
482+ if len (targetPlatforms ) > 1 {
483+ img := phase .Conveyor .imagesTree .GetMultiplatformImage (name )
472484
473485 isRebuilt := false
474486 for _ , pImg := range img .Images {
0 commit comments