Search in sources :

Example 71 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by google.

the class BuildFilesTest method testToBuildFileSpec_templateMultiLineBehavior.

@Test
public void testToBuildFileSpec_templateMultiLineBehavior() throws URISyntaxException, InvalidImageReferenceException, IOException {
    Path buildfile = Paths.get(Resources.getResource("buildfiles/projects/templating/multiLine.yaml").toURI());
    Mockito.when(buildCli.getTemplateParameters()).thenReturn(ImmutableMap.of("replace" + System.lineSeparator() + "this", "creationTime: 1234"));
    JibContainerBuilder jibContainerBuilder = BuildFiles.toJibContainerBuilder(buildfile.getParent(), buildfile, buildCli, commonCliOptions, consoleLogger);
    ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
    Assert.assertEquals(Instant.ofEpochMilli(1234), resolved.getCreationTime());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 72 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by google.

the class BuildFilesTest method testToBuildFileSpec_alternativeRootContext.

@Test
public void testToBuildFileSpec_alternativeRootContext() throws URISyntaxException, InvalidImageReferenceException, IOException {
    Path buildfile = Paths.get(Resources.getResource("buildfiles/projects/allProperties/altYamls/alt-jib.yaml").toURI());
    Path projectRoot = buildfile.getParent().getParent();
    JibContainerBuilder jibContainerBuilder = BuildFiles.toJibContainerBuilder(projectRoot, buildfile, buildCli, commonCliOptions, consoleLogger);
    ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
    Assert.assertEquals(FileEntriesLayer.builder().addEntry(projectRoot.resolve("project/script.sh"), AbsoluteUnixPath.get("/home/script.sh")).build().getEntries(), ((FileEntriesLayer) resolved.getLayers().get(0)).getEntries());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 73 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by google.

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnMainclassForWar.

@Test
public void testEntrypoint_warningOnMainclassForWar() throws IOException, InvalidCreationTimeException, InvalidImageReferenceException, IncompatibleBaseImageJavaVersionException, InvalidPlatformException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidFilesModificationTimeException, InvalidContainerizingModeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getMainClass()).thenReturn(Optional.of("java.util.Object"));
    when(projectProperties.isWarProject()).thenReturn(true);
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-jar", "/usr/local/jetty/start.jar").inOrder();
    verify(projectProperties).log(LogEvent.warn("mainClass, extraClasspath, jvmFlags, and expandClasspathDependencies " + "are ignored for WAR projects"));
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 74 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by google.

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnExpandClasspathDependenciesForWar.

@Test
public void testEntrypoint_warningOnExpandClasspathDependenciesForWar() throws IOException, InvalidCreationTimeException, InvalidImageReferenceException, IncompatibleBaseImageJavaVersionException, InvalidPlatformException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidFilesModificationTimeException, InvalidContainerizingModeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getExpandClasspathDependencies()).thenReturn(true);
    when(projectProperties.isWarProject()).thenReturn(true);
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-jar", "/usr/local/jetty/start.jar").inOrder();
    verify(projectProperties).log(LogEvent.warn("mainClass, extraClasspath, jvmFlags, and expandClasspathDependencies " + "are ignored for WAR projects"));
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 75 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by google.

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnJvmFlags.

@Test
public void testEntrypoint_warningOnJvmFlags() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getEntrypoint()).thenReturn(Optional.of(Arrays.asList("custom", "entrypoint")));
    when(rawConfiguration.getJvmFlags()).thenReturn(Collections.singletonList("jvmFlag"));
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("custom", "entrypoint").inOrder();
    verify(projectProperties).log(LogEvent.warn("mainClass, extraClasspath, jvmFlags, and expandClasspathDependencies are ignored " + "when entrypoint is specified"));
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Aggregations

ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)130 Test (org.junit.Test)120 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)61 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)38 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)26 Path (java.nio.file.Path)24 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)22 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)21 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)20 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)14 Collections (java.util.Collections)14 Optional (java.util.Optional)14 Paths (java.nio.file.Paths)13 List (java.util.List)13 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)12 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)11 Files (java.nio.file.Files)11 File (java.io.File)10 IOException (java.io.IOException)10 Parameters (junitparams.Parameters)10