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;
  }
@Test
  public void testToJibContainerBuilder_allProperties()
      throws URISyntaxException, IOException, InvalidImageReferenceException {
    Path buildfile =
        Paths.get(Resources.getResource("buildfiles/projects/allProperties/jib.yaml").toURI());
    Path projectRoot = buildfile.getParent();
    JibContainerBuilder jibContainerBuilder =
        BuildFiles.toJibContainerBuilder(
            projectRoot, buildfile, buildCli, commonCliOptions, consoleLogger);

    ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
    Assert.assertEquals("ubuntu", resolved.getBaseImage());
    Assert.assertEquals(Instant.ofEpochMilli(2000), resolved.getCreationTime());
    Assert.assertEquals(ImageFormat.OCI, resolved.getFormat());
    Assert.assertEquals(
        ImmutableSet.of(new Platform("arm", "linux"), new Platform("amd64", "darwin")),
        resolved.getPlatforms());
    Assert.assertEquals(ImmutableMap.of("KEY1", "v1", "KEY2", "v2"), resolved.getEnvironment());
    Assert.assertEquals(
        ImmutableSet.of(AbsoluteUnixPath.get("/volume1"), AbsoluteUnixPath.get("/volume2")),
        resolved.getVolumes());
    Assert.assertEquals(ImmutableMap.of("label1", "l1", "label2", "l2"), resolved.getLabels());
    Assert.assertEquals(
        ImmutableSet.of(Port.udp(123), Port.tcp(456), Port.tcp(789)), resolved.getExposedPorts());
    Assert.assertEquals("customUser", resolved.getUser());
    Assert.assertEquals(AbsoluteUnixPath.get("/home"), resolved.getWorkingDirectory());
    Assert.assertEquals(ImmutableList.of("sh", "script.sh"), resolved.getEntrypoint());
    Assert.assertEquals(ImmutableList.of("--param", "param"), resolved.getCmd());

    Assert.assertEquals(1, resolved.getLayers().size());
    FileEntriesLayer resolvedLayer = (FileEntriesLayer) resolved.getLayers().get(0);
    Assert.assertEquals("scripts", resolvedLayer.getName());
    Assert.assertEquals(
        FileEntriesLayer.builder()
            .addEntry(
                projectRoot.resolve("project/script.sh"), AbsoluteUnixPath.get("/home/script.sh"))
            .build()
            .getEntries(),
        resolvedLayer.getEntries());
    Assert.assertEquals(LayerObject.Type.FILE_ENTRIES, resolvedLayer.getType());
  }