Skip to content

Commit

Permalink
--all-platforms: make order deterministic
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vrothberg committed Jan 18, 2023
1 parent 3f805bc commit a7bb771
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions imagebuildah/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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)
}
}
Expand Down

0 comments on commit a7bb771

Please sign in to comment.