Search in sources :

Example 41 with ContainerBuildPlan

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

the class JibQuarkusExtensionTest method testExtendContainerBuildPlan_entrypoint.

@Test
public void testExtendContainerBuildPlan_entrypoint() throws JibPluginExtensionException {
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    ContainerBuildPlan newPlan = new JibQuarkusExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), gradleData, logger);
    assertEquals(Arrays.asList("java", "-verbose:gc", "-Dmy.property=value", "-jar", "/new/appRoot/app.jar"), newPlan.getEntrypoint());
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 42 with ContainerBuildPlan

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

the class JibNativeImageExtensionTest method testEntrypoint_setByJib.

@Test
public void testEntrypoint_setByJib() throws JibPluginExtensionException, IOException {
    Map<String, String> properties = Collections.singletonMap("imageName", "theExecutable");
    tempFolder.newFile("theExecutable");
    when(project.getPlugin("com.google.cloud.tools:jib-maven-plugin")).thenReturn(plugin);
    Xpp3Dom configuration = buildDom(Arrays.asList("configuration", "container", "entrypoint"), "non-empty");
    when(plugin.getConfiguration()).thenReturn(configuration);
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().setEntrypoint(Arrays.asList("set by Jib")).build();
    ContainerBuildPlan newPlan = new JibNativeImageExtension().extendContainerBuildPlan(buildPlan, properties, Optional.empty(), mavenData, logger);
    assertEquals(Arrays.asList("set by Jib"), newPlan.getEntrypoint());
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 43 with ContainerBuildPlan

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

the class JibNativeImageExtensionTest method testNoExecutableNameDetected.

@Test
public void testNoExecutableNameDetected() {
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    try {
        new JibNativeImageExtension().extendContainerBuildPlan(buildPlan, Collections.emptyMap(), Optional.empty(), mavenData, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals("cannot auto-detect native-image executable name; consider setting 'imageName' property", ex.getMessage());
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 44 with ContainerBuildPlan

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

the class JibOwnershipExtensionTest method testExtendContainerBuildPlan.

@Test
public void testExtendContainerBuildPlan() throws JibPluginExtensionException {
    FileEntriesLayer layer1 = FileEntriesLayer.builder().addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/file")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/another")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/sub/dir/file")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/sub/dir/another")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/untouched/file")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/untouched/another")).build();
    FileEntriesLayer layer2 = FileEntriesLayer.builder().addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/foo")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/bar")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/sub/dir/foo")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/sub/dir/bar")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/untouched/foo")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/untouched/bar")).build();
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer1).addLayer(layer2).build();
    Configuration.Rule rule1 = mockRule("/target/**", "10:20");
    Configuration.Rule rule2 = mockRule("**/bar", "999:777");
    when(config.getRules()).thenReturn(Arrays.asList(rule1, rule2));
    ContainerBuildPlan newPlan = new JibOwnershipExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
    FileEntriesLayer newLayer1 = (FileEntriesLayer) newPlan.getLayers().get(0);
    FileEntriesLayer newLayer2 = (FileEntriesLayer) newPlan.getLayers().get(1);
    assertEquals(Arrays.asList(AbsoluteUnixPath.get("/target/file"), AbsoluteUnixPath.get("/target/another"), AbsoluteUnixPath.get("/target/sub/dir/file"), AbsoluteUnixPath.get("/target/sub/dir/another"), AbsoluteUnixPath.get("/untouched/file"), AbsoluteUnixPath.get("/untouched/another")), mapLayerEntries(newLayer1, FileEntry::getExtractionPath));
    assertEquals(Arrays.asList("10:20", "10:20", "10:20", "10:20", "", ""), mapLayerEntries(newLayer1, FileEntry::getOwnership));
    assertEquals(Arrays.asList(AbsoluteUnixPath.get("/target/foo"), AbsoluteUnixPath.get("/target/bar"), AbsoluteUnixPath.get("/target/sub/dir/foo"), AbsoluteUnixPath.get("/target/sub/dir/bar"), AbsoluteUnixPath.get("/untouched/foo"), AbsoluteUnixPath.get("/untouched/bar")), mapLayerEntries(newLayer2, FileEntry::getExtractionPath));
    assertEquals(Arrays.asList("10:20", "999:777", "10:20", "999:777", "", "999:777"), mapLayerEntries(newLayer2, FileEntry::getOwnership));
}
Also used : FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 45 with ContainerBuildPlan

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

the class JibOwnershipExtensionTest method testExtendContainerBuildPlan_noConfiguration.

@Test
public void testExtendContainerBuildPlan_noConfiguration() throws JibPluginExtensionException {
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    ContainerBuildPlan newPlan = new JibOwnershipExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), null, logger);
    assertSame(buildPlan, newPlan);
    verify(logger).log(LogLevel.WARN, "Nothing configured for Jib Ownership Extension");
}
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