private static void configureBuilderWithContainerConfiguration(
      Image.Builder imageBuilder, ContainerConfigurationTemplate containerConfigurationTemplate)
      throws BadContainerConfigurationFormatException {

    containerConfigurationTemplate.getHistory().forEach(imageBuilder::addHistory);

    if (containerConfigurationTemplate.getCreated() != null) {
      try {
        imageBuilder.setCreated(Instant.parse(containerConfigurationTemplate.getCreated()));
      } catch (DateTimeParseException ex) {
        try {
          // TODO: remove when using Java >= 12.
          // See https://github.com/GoogleContainerTools/jib/issues/2428
          imageBuilder.setCreated(
              DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(
                  containerConfigurationTemplate.getCreated(), Instant::from));
        } catch (DateTimeParseException ignored) {
          throw new BadContainerConfigurationFormatException(
              "Invalid image creation time: " + containerConfigurationTemplate.getCreated(), ex);
        }
      }
    }

    if (containerConfigurationTemplate.getArchitecture() != null) {
      imageBuilder.setArchitecture(containerConfigurationTemplate.getArchitecture());
    }
    if (containerConfigurationTemplate.getOs() != null) {
      imageBuilder.setOs(containerConfigurationTemplate.getOs());
    }

    imageBuilder.setEntrypoint(containerConfigurationTemplate.getContainerEntrypoint());
    imageBuilder.setProgramArguments(containerConfigurationTemplate.getContainerCmd());

    List<String> baseHealthCheckCommand = containerConfigurationTemplate.getContainerHealthTest();
    if (baseHealthCheckCommand != null) {
      DockerHealthCheck.Builder builder = DockerHealthCheck.fromCommand(baseHealthCheckCommand);
      if (containerConfigurationTemplate.getContainerHealthInterval() != null) {
        builder.setInterval(
            Duration.ofNanos(containerConfigurationTemplate.getContainerHealthInterval()));
      }
      if (containerConfigurationTemplate.getContainerHealthTimeout() != null) {
        builder.setTimeout(
            Duration.ofNanos(containerConfigurationTemplate.getContainerHealthTimeout()));
      }
      if (containerConfigurationTemplate.getContainerHealthStartPeriod() != null) {
        builder.setStartPeriod(
            Duration.ofNanos(containerConfigurationTemplate.getContainerHealthStartPeriod()));
      }
      if (containerConfigurationTemplate.getContainerHealthRetries() != null) {
        builder.setRetries(containerConfigurationTemplate.getContainerHealthRetries());
      }
      imageBuilder.setHealthCheck(builder.build());
    }

    if (containerConfigurationTemplate.getContainerExposedPorts() != null) {
      imageBuilder.addExposedPorts(
          portMapToSet(containerConfigurationTemplate.getContainerExposedPorts()));
    }

    if (containerConfigurationTemplate.getContainerVolumes() != null) {
      imageBuilder.addVolumes(volumeMapToSet(containerConfigurationTemplate.getContainerVolumes()));
    }

    if (containerConfigurationTemplate.getContainerEnvironment() != null) {
      for (String environmentVariable : containerConfigurationTemplate.getContainerEnvironment()) {
        Matcher matcher = ENVIRONMENT_PATTERN.matcher(environmentVariable);
        if (!matcher.matches()) {
          throw new BadContainerConfigurationFormatException(
              "Invalid environment variable definition: " + environmentVariable);
        }
        imageBuilder.addEnvironmentVariable(matcher.group("name"), matcher.group("value"));
      }
    }

    imageBuilder.addLabels(containerConfigurationTemplate.getContainerLabels());
    imageBuilder.setWorkingDirectory(containerConfigurationTemplate.getContainerWorkingDir());
    imageBuilder.setUser(containerConfigurationTemplate.getContainerUser());
  }
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