private Optional<Image> getBaseImageIfAllLayersCached(
      ManifestAndConfigTemplate manifestAndConfig, boolean isSingleManifest)
      throws BadContainerConfigurationFormatException, PlatformNotFoundInBaseImageException,
          LayerCountMismatchException {
    Cache baseImageLayersCache = buildContext.getBaseImageLayersCache();
    ManifestTemplate manifest = Verify.verifyNotNull(manifestAndConfig.getManifest());

    // Verify all layers described in manifest are present in cache
    if (!baseImageLayersCache.areAllLayersCached(manifest)) {
      return Optional.empty();
    }
    if (manifest instanceof V21ManifestTemplate) {
      return Optional.of(JsonToImageTranslator.toImage((V21ManifestTemplate) manifest));
    }
    ContainerConfigurationTemplate containerConfig =
        Verify.verifyNotNull(manifestAndConfig.getConfig());
    if (isSingleManifest) {
      // If base image is not a manifest list, check and warn misconfigured platforms.
      PlatformChecker.checkManifestPlatform(buildContext, containerConfig);
    }
    return Optional.of(
        JsonToImageTranslator.toImage((BuildableManifestTemplate) manifest, containerConfig));
  }
Helper method to retrieve a base image from cache given manifest and container config. Does not
return image if any layers of base image are missing in cache.

@param manifestAndConfig stores an image manifest and a container config
@param isSingleManifest true if base image is not a manifest list
@return the single cached {@link Image} found, or {@code Optional#empty()} if the base image
    not found in cache with all layers present.
@throws BadContainerConfigurationFormatException if the container configuration is in a bad
    format
@throws PlatformNotFoundInBaseImageException if build target platform is not found in the base
    image
@throws LayerCountMismatchException LayerCountMismatchException if the manifest and
    configuration contain conflicting layer information
jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/PullBaseImageStep.java