public static Image toImage(
      BuildableManifestTemplate manifestTemplate,
      ContainerConfigurationTemplate containerConfigurationTemplate)
      throws LayerCountMismatchException, LayerPropertyNotFoundException,
          BadContainerConfigurationFormatException {
    List<ReferenceNoDiffIdLayer> layers = new ArrayList<>();
    for (BuildableManifestTemplate.ContentDescriptorTemplate layerObjectTemplate :
        manifestTemplate.getLayers()) {
      if (layerObjectTemplate.getDigest() == null) {
        throw new IllegalArgumentException(
            "All layers in the manifest template must have digest set");
      }

      layers.add(
          new ReferenceNoDiffIdLayer(
              new BlobDescriptor(layerObjectTemplate.getSize(), layerObjectTemplate.getDigest())));
    }

    List<DescriptorDigest> diffIds = containerConfigurationTemplate.getDiffIds();
    if (layers.size() != diffIds.size()) {
      throw new LayerCountMismatchException(
          "Mismatch between image manifest and container configuration");
    }

    Image.Builder imageBuilder = Image.builder(manifestTemplate.getClass());

    for (int layerIndex = 0; layerIndex < layers.size(); layerIndex++) {
      ReferenceNoDiffIdLayer noDiffIdLayer = layers.get(layerIndex);
      DescriptorDigest diffId = diffIds.get(layerIndex);

      imageBuilder.addLayer(new ReferenceLayer(noDiffIdLayer.getBlobDescriptor(), diffId));
    }

    configureBuilderWithContainerConfiguration(imageBuilder, containerConfigurationTemplate);
    return imageBuilder.build();
  }
Translates {@link BuildableManifestTemplate} to {@link Image}. Uses the corresponding {@link
ContainerConfigurationTemplate} to get the layer diff IDs.

@param manifestTemplate the template containing the image layers.
@param containerConfigurationTemplate the template containing the diff IDs and container
    configuration properties.
@return the translated {@link Image}.
@throws LayerCountMismatchException if the manifest and configuration contain conflicting layer
    information.
@throws LayerPropertyNotFoundException if adding image layers fails.
@throws BadContainerConfigurationFormatException if the container configuration is in a bad
    format
jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java