From a7bb7719a65a7af32aac6538fa03b55ecd290811 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 18 Jan 2023 14:35:26 +0100 Subject: [PATCH] --all-platforms: make order deterministic A combination of yet-to-be-resolved containers/common/issues/1295 and a non-deterministic processing of the platforms on the Buildah side caused heavy flakes, so make it deterministic. [NO NEW TESTS NEEDED] - the expected absence of the flake will tell. Fixes: #4520 Signed-off-by: Valentin Rothberg --- imagebuildah/build.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/imagebuildah/build.go b/imagebuildah/build.go index ca45501c86d..adb94a980f3 100644 --- a/imagebuildah/build.go +++ b/imagebuildah/build.go @@ -527,7 +527,9 @@ func platformsForBaseImages(ctx context.Context, logger *logrus.Logger, dockerfi if len(baseImages) == 0 { return nil, fmt.Errorf("build uses no non-scratch base images: %w", err) } + targetPlatforms := make(map[string]struct{}) + var platformCandidates []string // Used to preserve a deterministic order of the targetPlatforms map var platformList []struct{ OS, Arch, Variant string } for baseImageIndex, baseImage := range baseImages { resolved, err := shortnames.Resolve(systemContext, baseImage) @@ -596,8 +598,12 @@ func platformsForBaseImages(ctx context.Context, logger *logrus.Logger, dockerfi continue } platform := internalUtil.NormalizePlatform(*instance.Platform) - targetPlatforms[platforms.Format(platform)] = struct{}{} - logger.Debugf("image %q supports %q", baseImage, platforms.Format(platform)) + formatted := platforms.Format(platform) + logger.Debugf("image %q supports %q", baseImage, formatted) + if _, ok := targetPlatforms[formatted]; !ok { + targetPlatforms[formatted] = struct{}{} + platformCandidates = append(platformCandidates, formatted) + } } } else { // prune the list of any normalized platforms this base image doesn't support @@ -623,8 +629,12 @@ func platformsForBaseImages(ctx context.Context, logger *logrus.Logger, dockerfi } if baseImageIndex == len(baseImages)-1 && len(targetPlatforms) > 0 { // extract the list - for platform := range targetPlatforms { - platform, err := platforms.Parse(platform) + for _, candidate := range platformCandidates { + if _, ok := targetPlatforms[candidate]; !ok { + // Has either been removed or already been processed + continue + } + platform, err := platforms.Parse(candidate) if err != nil { return nil, fmt.Errorf("parsing platform double/triple %q: %w", platform, err) } @@ -633,6 +643,7 @@ func platformsForBaseImages(ctx context.Context, logger *logrus.Logger, dockerfi Arch: platform.Architecture, Variant: platform.Variant, }) + delete(targetPlatforms, candidate) logger.Debugf("base images all support %q", platform) } }