Search in sources :

Example 21 with FileEntry

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

the class PluginConfigurationProcessorTest method testClasspathArgumentFile_mainClassInferenceFailureWithCustomEntrypoint.

@Test
public void testClasspathArgumentFile_mainClassInferenceFailureWithCustomEntrypoint() throws NumberFormatException, InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getMainClass()).thenReturn(Optional.of("invalid main class"));
    when(rawConfiguration.getEntrypoint()).thenReturn(Optional.of(Arrays.asList("bash")));
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("bash");
    List<FileEntry> jvmArgFiles = getLayerEntries(buildPlan, "jvm arg files");
    assertThat(jvmArgFiles).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(appCacheDirectory.resolve("jib-classpath-file"), appCacheDirectory.resolve("jib-main-class-file"));
    assertThat(jvmArgFiles).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/app/jib-classpath-file", "/app/jib-main-class-file");
    String classpath = new String(Files.readAllBytes(appCacheDirectory.resolve("jib-classpath-file")), StandardCharsets.UTF_8);
    assertThat(classpath).isEqualTo("/app/resources:/app/classes:/app/libs/*");
    String mainClass = new String(Files.readAllBytes(appCacheDirectory.resolve("jib-main-class-file")), StandardCharsets.UTF_8);
    assertThat(mainClass).isEqualTo("could-not-infer-a-main-class");
}
Also used : FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 22 with FileEntry

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

the class SkaffoldSyncMapTemplateTest method testGetJsonString.

@Test
public void testGetJsonString() throws IOException {
    SkaffoldSyncMapTemplate ssmt = new SkaffoldSyncMapTemplate();
    ssmt.addGenerated(new FileEntry(GEN_SRC, AbsoluteUnixPath.get("/genDest"), FilePermissions.DEFAULT_FILE_PERMISSIONS, FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    ssmt.addDirect(new FileEntry(DIR_SRC_1, AbsoluteUnixPath.get("/dirDest1"), FilePermissions.DEFAULT_FILE_PERMISSIONS, FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    ssmt.addDirect(new FileEntry(DIR_SRC_2, AbsoluteUnixPath.get("/dirDest2"), FilePermissions.DEFAULT_FILE_PERMISSIONS, FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    Assert.assertEquals(TEST_JSON, ssmt.getJsonString());
}
Also used : FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Test(org.junit.Test)

Example 23 with FileEntry

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

the class JavaContainerBuilderHelperTest method testExtraDirectoryLayerConfiguration_overlappingPermissions.

@Test
public void testExtraDirectoryLayerConfiguration_overlappingPermissions() throws URISyntaxException, IOException {
    Path extraFilesDirectory = Paths.get(Resources.getResource("core/layer").toURI());
    Map<String, FilePermissions> permissionsMap = ImmutableMap.of("/a**", FilePermissions.fromOctalString("123"), // Should be ignored, since first match takes priority
    "/a/b**", FilePermissions.fromOctalString("000"), // Should override first match since explicit path is used instead of glob
    "/a/b/bar", FilePermissions.fromOctalString("765"));
    FileEntriesLayer fileEntriesLayer = JavaContainerBuilderHelper.extraDirectoryLayerConfiguration(extraFilesDirectory, AbsoluteUnixPath.get("/"), Collections.emptyList(), Collections.emptyList(), permissionsMap, (ignored1, ignored2) -> Instant.EPOCH);
    assertThat(fileEntriesLayer.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/a", "/a/b", "/a/b/bar", "/c", "/c/cat", "/foo");
    Map<AbsoluteUnixPath, FilePermissions> expectedPermissions = ImmutableMap.<AbsoluteUnixPath, FilePermissions>builder().put(AbsoluteUnixPath.get("/a"), FilePermissions.fromOctalString("123")).put(AbsoluteUnixPath.get("/a/b"), FilePermissions.fromOctalString("123")).put(AbsoluteUnixPath.get("/a/b/bar"), FilePermissions.fromOctalString("765")).put(AbsoluteUnixPath.get("/c"), FilePermissions.DEFAULT_FOLDER_PERMISSIONS).put(AbsoluteUnixPath.get("/c/cat"), FilePermissions.DEFAULT_FILE_PERMISSIONS).put(AbsoluteUnixPath.get("/foo"), FilePermissions.DEFAULT_FILE_PERMISSIONS).build();
    for (FileEntry entry : fileEntriesLayer.getEntries()) {
        assertThat(entry.getPermissions()).isEqualTo(expectedPermissions.get(entry.getExtractionPath()));
    }
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) FilePermissions(com.google.cloud.tools.jib.api.buildplan.FilePermissions) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Test(org.junit.Test)

Example 24 with FileEntry

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

the class MavenProjectPropertiesTest method testCreateContainerBuilder_correctFiles.

@Test
public void testCreateContainerBuilder_correctFiles() throws URISyntaxException, IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
    ContainerBuilderLayers layers = new ContainerBuilderLayers(setUpBuildContext());
    Path dependenciesPath = getResource("maven/application/dependencies");
    Path applicationDirectory = getResource("maven/application");
    assertThat(layers.dependenciesLayer.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(testRepository.artifactPathOnDisk("com.test", "dependency", "1.0.0"), dependenciesPath.resolve("more/dependency-1.0.0.jar"), dependenciesPath.resolve("another/one/dependency-1.0.0.jar"), dependenciesPath.resolve("libraryA.jar"), dependenciesPath.resolve("libraryB.jar"), dependenciesPath.resolve("library.jarC.jar"));
    assertThat(layers.snapshotsLayer.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(testRepository.artifactPathOnDisk("com.test", "dependencyX", "1.0.0-SNAPSHOT"));
    assertThat(layers.resourcesLayer.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(applicationDirectory.resolve("output/directory"), applicationDirectory.resolve("output/directory/somefile"), applicationDirectory.resolve("output/package"), applicationDirectory.resolve("output/resourceA"), applicationDirectory.resolve("output/resourceB"), applicationDirectory.resolve("output/world"));
    assertThat(layers.classesLayer.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(applicationDirectory.resolve("output/HelloWorld.class"), applicationDirectory.resolve("output/directory"), applicationDirectory.resolve("output/package"), applicationDirectory.resolve("output/package/some.class"), applicationDirectory.resolve("output/some.class"));
    List<FileEntry> allFileEntries = new ArrayList<>();
    allFileEntries.addAll(layers.dependenciesLayer.getEntries());
    allFileEntries.addAll(layers.snapshotsLayer.getEntries());
    allFileEntries.addAll(layers.resourcesLayer.getEntries());
    allFileEntries.addAll(layers.classesLayer.getEntries());
    Set<Instant> modificationTimes = allFileEntries.stream().map(FileEntry::getModificationTime).collect(Collectors.toSet());
    assertThat(modificationTimes).containsExactly(EPOCH_PLUS_32);
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Instant(java.time.Instant) ArrayList(java.util.ArrayList) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Test(org.junit.Test)

Example 25 with FileEntry

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

the class LayerEntriesSelectorTest method setUp.

@Before
public void setUp() throws IOException {
    Path folder = temporaryFolder.newFolder().toPath();
    Path file1 = Files.createDirectory(folder.resolve("files"));
    Path file2 = Files.createFile(folder.resolve("files").resolve("two"));
    Path file3 = Files.createFile(folder.resolve("gile"));
    FileEntry testLayerEntry1 = defaultLayerEntry(file1, AbsoluteUnixPath.get("/extraction/path"));
    FileEntry testLayerEntry2 = defaultLayerEntry(file2, AbsoluteUnixPath.get("/extraction/path"));
    FileEntry testLayerEntry3 = defaultLayerEntry(file3, AbsoluteUnixPath.get("/extraction/path"));
    FileEntry testLayerEntry4 = new FileEntry(file3, AbsoluteUnixPath.get("/extraction/path"), FilePermissions.fromOctalString("755"), FileEntriesLayer.DEFAULT_MODIFICATION_TIME);
    FileEntry testLayerEntry5 = defaultLayerEntry(file3, AbsoluteUnixPath.get("/extraction/patha"));
    FileEntry testLayerEntry6 = new FileEntry(file3, AbsoluteUnixPath.get("/extraction/patha"), FilePermissions.fromOctalString("755"), FileEntriesLayer.DEFAULT_MODIFICATION_TIME);
    outOfOrderLayerEntries = ImmutableList.of(testLayerEntry4, testLayerEntry2, testLayerEntry6, testLayerEntry3, testLayerEntry1, testLayerEntry5);
    inOrderLayerEntries = ImmutableList.of(testLayerEntry1, testLayerEntry2, testLayerEntry3, testLayerEntry4, testLayerEntry5, testLayerEntry6);
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Before(org.junit.Before)

Aggregations

FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)64 Test (org.junit.Test)45 Path (java.nio.file.Path)39 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)34 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)24 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)16 ArrayList (java.util.ArrayList)13 FilePermissions (com.google.cloud.tools.jib.api.buildplan.FilePermissions)10 Blob (com.google.cloud.tools.jib.blob.Blob)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)9 List (java.util.List)9 BufferedOutputStream (java.io.BufferedOutputStream)8 OutputStream (java.io.OutputStream)8 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)8 PathMatcher (java.nio.file.PathMatcher)7 Instant (java.time.Instant)7 Optional (java.util.Optional)7 Collectors (java.util.stream.Collectors)7 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)6 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)6