public static JibContainerBuilder toJibContainerBuilder(
      Path projectRoot,
      Path buildFilePath,
      Build buildCommandOptions,
      CommonCliOptions commonCliOptions,
      ConsoleLogger logger)
      throws InvalidImageReferenceException, IOException {
    BuildFileSpec buildFile =
        toBuildFileSpec(buildFilePath, buildCommandOptions.getTemplateParameters());
    Optional<BaseImageSpec> baseImageSpec = buildFile.getFrom();
    JibContainerBuilder containerBuilder =
        baseImageSpec.isPresent()
            ? createJibContainerBuilder(baseImageSpec.get(), commonCliOptions, logger)
            : Jib.fromScratch();

    buildFile.getCreationTime().ifPresent(containerBuilder::setCreationTime);
    buildFile.getFormat().ifPresent(containerBuilder::setFormat);
    containerBuilder.setEnvironment(buildFile.getEnvironment());
    containerBuilder.setLabels(buildFile.getLabels());
    containerBuilder.setVolumes(buildFile.getVolumes());
    containerBuilder.setExposedPorts(buildFile.getExposedPorts());
    buildFile.getUser().ifPresent(containerBuilder::setUser);
    buildFile.getWorkingDirectory().ifPresent(containerBuilder::setWorkingDirectory);
    buildFile.getEntrypoint().ifPresent(containerBuilder::setEntrypoint);
    buildFile.getCmd().ifPresent(containerBuilder::setProgramArguments);

    Optional<LayersSpec> layersSpec = buildFile.getLayers();
    if (layersSpec.isPresent()) {
      containerBuilder.setFileEntriesLayers(Layers.toLayers(projectRoot, layersSpec.get()));
    }
    return containerBuilder;
  }
Read a buildfile from disk and generate a JibContainerBuilder instance. All parsing of files
considers the directory the buildfile is located in as the working directory.

@param projectRoot the root context directory of this build
@param buildFilePath a file containing the build definition
@param buildCommandOptions the build configuration from the command line
@param commonCliOptions common cli options
@param logger a logger to inject into various objects that do logging
@return a {@link JibContainerBuilder} generated from the contents of {@code buildFilePath}
@throws IOException if an I/O error occurs opening the file, or an error occurs while
    traversing files on the filesystem
@throws InvalidImageReferenceException if the baseImage reference can not be parsed
jib-cli/src/main/java/com/google/cloud/tools/jib/cli/buildfile/BuildFiles.java