Repository: GoogleContainerTools/jib
File: jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/PushImageStep.java (Java)

Code before:
    Set<String> tags = buildContext.getAllTargetImageTags();
    int numPushers = singlePlatform ? tags.size() : 1;

    EventHandlers eventHandlers = buildContext.getEventHandlers();
    try (TimerEventDispatcher ignored =
            new TimerEventDispatcher(eventHandlers, "Preparing manifest pushers");
        ProgressEventDispatcher progressDispatcher =
            progressEventDispatcherFactory.create("launching manifest pushers", numPushers)) {

      if (JibSystemProperties.skipExistingImages() && manifestAlreadyExists) {
        eventHandlers.dispatch(LogEvent.info("Skipping pushing manifest; already exists."));
        return ImmutableList.of();
      }

      // Gets the image manifest to push.
      BuildableManifestTemplate manifestTemplate =
          new ImageToJsonTranslator(builtImage)
              .getManifestTemplate(
                  buildContext.getTargetFormat(), containerConfigurationDigestAndSize);

      DescriptorDigest manifestDigest = Digests.computeJsonDigest(manifestTemplate);

      Set<String> imageQualifiers =
          singlePlatform
              ? tags
              : getChildTags(builtImage, tags, manifestDigest, buildContext.isEnablePlatformTags());

      return imageQualifiers.stream()
          .map(
              qualifier ->
                  new PushImageStep(
                      buildContext,
                      progressDispatcher.newChildProducer(),
                      registryClient,
                      manifestTemplate,
                      qualifier,
                      manifestDigest,
                      containerConfigurationDigestAndSize.getDigest()))
          .collect(ImmutableList.toImmutableList());
    }
  }

  private static Set<String> getChildTags(
      Image builtImage,
      Set<String> tags,
      DescriptorDigest manifestDigest,
      boolean newTagFeatureEnabled) {
    if (newTagFeatureEnabled) {
      String architecture = builtImage.getArchitecture();
      return tags.stream().map(tag -> tag + "-" + architecture).collect(Collectors.toSet());
    }

Review comment (refactor):
Maybe we can put the entire `singlePlatform ? tags : ...` logic into `getChildTags()`. And not sure I like the word "child." Maybe just `getImageQualifiers()`.  And actually I think it's better to move this computation to line 61 so that it looks like

```diff
     Set<String> tags = buildContext.getAllTargetImageTags();
-    int numPushers = singlePlatform ? tags.size() : 1;
+    Set<String> imageQualifiers = getImageQualifiers(...);
...
-            progressEventDispatcherFactory.create("launching manifest pushers", numPushers)) {
+            progressEventDispatcherFactory.create("launching manifest pushers", imageQualifiers.size())) {
```

Code after:
    BuildableManifestTemplate manifestTemplate =
        new ImageToJsonTranslator(builtImage)
            .getManifestTemplate(
                buildContext.getTargetFormat(), containerConfigurationDigestAndSize);
    DescriptorDigest manifestDigest = Digests.computeJsonDigest(manifestTemplate);
    Set<String> imageQualifiers = getImageQualifiers(buildContext, builtImage, manifestDigest);

    EventHandlers eventHandlers = buildContext.getEventHandlers();
    try (TimerEventDispatcher ignored =
            new TimerEventDispatcher(eventHandlers, "Preparing manifest pushers");
        ProgressEventDispatcher progressDispatcher =
            progressEventDispatcherFactory.create(
                "launching manifest pushers", imageQualifiers.size())) {

      if (JibSystemProperties.skipExistingImages() && manifestAlreadyExists) {
        eventHandlers.dispatch(LogEvent.info("Skipping pushing manifest; already exists."));
        return ImmutableList.of();
      }

      return imageQualifiers.stream()
          .map(
              qualifier ->
                  new PushImageStep(
                      buildContext,
                      progressDispatcher.newChildProducer(),
                      registryClient,
                      manifestTemplate,
                      qualifier,
                      manifestDigest,
                      containerConfigurationDigestAndSize.getDigest()))
          .collect(ImmutableList.toImmutableList());
    }
  }

  private static Set<String> getImageQualifiers(
      BuildContext buildContext, Image builtImage, DescriptorDigest manifestDigest) {
    boolean singlePlatform = buildContext.getContainerConfiguration().getPlatforms().size() == 1;
    Set<String> tags = buildContext.getAllTargetImageTags();
    if (singlePlatform) {
      return tags;
    }
    if (buildContext.getEnablePlatformTags()) {
      String architecture = builtImage.getArchitecture();
      return tags.stream().map(tag -> tag + "-" + architecture).collect(Collectors.toSet());
    }
    return Collections.singleton(manifestDigest.toString());
  }

  static ImmutableList<PushImageStep> makeListForManifestList(
      BuildContext buildContext,
      ProgressEventDispatcher.Factory progressEventDispatcherFactory,