Search in sources :

Example 16 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnExpandClasspathDependencies.

@Test
public void testEntrypoint_warningOnExpandClasspathDependencies() 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.getExpandClasspathDependencies()).thenReturn(true);
    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)

Example 17 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testEntrypoint_defaultWarPackaging.

@Test
public void testEntrypoint_defaultWarPackaging() throws IOException, InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(projectProperties.isWarProject()).thenReturn(true);
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-jar", "/usr/local/jetty/start.jar").inOrder();
    verifyNoInteractions(logger);
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 18 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnMainclass.

@Test
public void testEntrypoint_warningOnMainclass() 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.getMainClass()).thenReturn(Optional.of("java.util.Object"));
    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)

Example 19 with ContainerBuildPlan

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

the class MavenProjectProperties method runPluginExtensions.

@Override
public JibContainerBuilder runPluginExtensions(List<? extends ExtensionConfiguration> extensionConfigs, JibContainerBuilder jibContainerBuilder) throws JibPluginExtensionException {
    if (extensionConfigs.isEmpty()) {
        log(LogEvent.debug("No Jib plugin extensions configured to load"));
        return jibContainerBuilder;
    }
    // Add the injected extensions at first to prefer them over the ones from JDK service
    // loader.
    // Extensions might support both approaches (injection and JDK service loader) at the same
    // time for compatibility reasons.
    List<JibMavenPluginExtension<?>> loadedExtensions = new ArrayList<>(injectedExtensions);
    loadedExtensions.addAll(extensionLoader.get());
    JibMavenPluginExtension<?> extension = null;
    ContainerBuildPlan buildPlan = jibContainerBuilder.toContainerBuildPlan();
    try {
        for (ExtensionConfiguration config : extensionConfigs) {
            extension = findConfiguredExtension(loadedExtensions, config);
            log(LogEvent.lifecycle("Running extension: " + config.getExtensionClass()));
            buildPlan = runPluginExtension(extension.getExtraConfigType(), extension, config, buildPlan);
            // to validate image reference
            ImageReference.parse(buildPlan.getBaseImage());
        }
        return jibContainerBuilder.applyContainerBuildPlan(buildPlan);
    } catch (InvalidImageReferenceException ex) {
        throw new JibPluginExtensionException(Verify.verifyNotNull(extension).getClass(), "invalid base image reference: " + buildPlan.getBaseImage(), ex);
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) JibMavenPluginExtension(com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension) ExtensionConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration) ArrayList(java.util.ArrayList) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)

Example 20 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(), mavenData, 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)

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