Search in sources :

Example 96 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testUser.

@Test
public void testUser() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getUser()).thenReturn(Optional.of("customUser"));
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getUser()).isEqualTo("customUser");
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 97 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testPluginConfigurationProcessor_defaults.

@Test
public void testPluginConfigurationProcessor_defaults() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "/app/resources:/app/classes:/app/libs/*", "java.lang.Object").inOrder();
    verify(containerizer).setBaseImageLayersCache(Containerizer.DEFAULT_BASE_CACHE_DIRECTORY);
    verify(containerizer).setApplicationLayersCache(appCacheDirectory);
    ArgumentMatcher<LogEvent> isLogWarn = logEvent -> logEvent.getLevel() == LogEvent.Level.WARN;
    verify(logger, never()).accept(argThat(isLogWarn));
}
Also used : CredHelperConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.CredHelperConfiguration) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) URISyntaxException(java.net.URISyntaxException) FileTime(java.nio.file.attribute.FileTime) PlatformConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) ExtraDirectoriesConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArgumentMatcher(org.mockito.ArgumentMatcher) JUnitParamsRunner(junitparams.JUnitParamsRunner) Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) JibContainerBuilderTestHelper(com.google.cloud.tools.jib.api.JibContainerBuilderTestHelper) FilePermissions(com.google.cloud.tools.jib.api.buildplan.FilePermissions) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) Instant(java.time.Instant) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Optional(java.util.Optional) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Parameters(junitparams.Parameters) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) RunWith(org.junit.runner.RunWith) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Jib(com.google.cloud.tools.jib.api.Jib) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) ImmutableList(com.google.common.collect.ImmutableList) MockitoJUnit(org.mockito.junit.MockitoJUnit) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Answers(org.mockito.Answers) Resources(com.google.common.io.Resources) Files(java.nio.file.Files) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) ModificationTimeProvider(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Correspondence(com.google.common.truth.Correspondence) Consumer(java.util.function.Consumer) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) RestoreSystemProperties(org.junit.contrib.java.lang.system.RestoreSystemProperties) MockitoRule(org.mockito.junit.MockitoRule) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) LogEvent(com.google.cloud.tools.jib.api.LogEvent) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 98 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testPluginConfigurationProcessor_extraDirectory.

@Test
public void testPluginConfigurationProcessor_extraDirectory() throws URISyntaxException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, IOException, IncompatibleBaseImageJavaVersionException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidImageReferenceException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    Path extraDirectory = Paths.get(Resources.getResource("core/layer").toURI());
    Mockito.<List<?>>when(rawConfiguration.getExtraDirectories()).thenReturn(Arrays.asList(new TestExtraDirectoriesConfiguration(extraDirectory)));
    when(rawConfiguration.getExtraDirectoryPermissions()).thenReturn(ImmutableMap.of("/target/dir/foo", FilePermissions.fromOctalString("123")));
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    List<FileEntry> extraFiles = getLayerEntries(buildPlan, "extra files");
    assertThat(extraFiles).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(extraDirectory.resolve("a"), extraDirectory.resolve("a/b"), extraDirectory.resolve("a/b/bar"), extraDirectory.resolve("c"), extraDirectory.resolve("c/cat"), extraDirectory.resolve("foo"));
    assertThat(extraFiles).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/target/dir/a", "/target/dir/a/b", "/target/dir/a/b/bar", "/target/dir/c", "/target/dir/c/cat", "/target/dir/foo");
    Optional<FileEntry> fooEntry = extraFiles.stream().filter(layerEntry -> layerEntry.getExtractionPath().equals(AbsoluteUnixPath.get("/target/dir/foo"))).findFirst();
    assertThat(fooEntry).isPresent();
    assertThat(fooEntry.get().getPermissions().toOctalString()).isEqualTo("123");
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) CredHelperConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.CredHelperConfiguration) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) URISyntaxException(java.net.URISyntaxException) FileTime(java.nio.file.attribute.FileTime) PlatformConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) ExtraDirectoriesConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArgumentMatcher(org.mockito.ArgumentMatcher) JUnitParamsRunner(junitparams.JUnitParamsRunner) Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) JibContainerBuilderTestHelper(com.google.cloud.tools.jib.api.JibContainerBuilderTestHelper) FilePermissions(com.google.cloud.tools.jib.api.buildplan.FilePermissions) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) Instant(java.time.Instant) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Optional(java.util.Optional) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Parameters(junitparams.Parameters) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) RunWith(org.junit.runner.RunWith) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Jib(com.google.cloud.tools.jib.api.Jib) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) ImmutableList(com.google.common.collect.ImmutableList) MockitoJUnit(org.mockito.junit.MockitoJUnit) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Answers(org.mockito.Answers) Resources(com.google.common.io.Resources) Files(java.nio.file.Files) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) ModificationTimeProvider(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Correspondence(com.google.common.truth.Correspondence) Consumer(java.util.function.Consumer) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) RestoreSystemProperties(org.junit.contrib.java.lang.system.RestoreSystemProperties) MockitoRule(org.mockito.junit.MockitoRule) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 99 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testEntrypoint.

@Test
public void testEntrypoint() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getEntrypoint()).thenReturn(Optional.of(Arrays.asList("custom", "entrypoint")));
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("custom", "entrypoint").inOrder();
    verifyNoInteractions(logger);
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 100 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testUser_null.

@Test
public void testUser_null() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getUser()).isNull();
}
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