Search in sources :

Example 6 with FileEntry

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

the class ReproducibleLayerBuilderTest method testBuild_ownership.

@Test
public void testBuild_ownership() throws IOException {
    Path testRoot = temporaryFolder.getRoot().toPath();
    Path someFile = createFile(testRoot, "someFile", "content", 54321);
    Blob blob = new ReproducibleLayerBuilder(ImmutableList.of(defaultLayerEntry(someFile, AbsoluteUnixPath.get("/file1")), new FileEntry(someFile, AbsoluteUnixPath.get("/file2"), FilePermissions.fromOctalString("123"), Instant.EPOCH, ""), new FileEntry(someFile, AbsoluteUnixPath.get("/file3"), FilePermissions.fromOctalString("123"), Instant.EPOCH, ":"), new FileEntry(someFile, AbsoluteUnixPath.get("/file4"), FilePermissions.fromOctalString("123"), Instant.EPOCH, "333:"), new FileEntry(someFile, AbsoluteUnixPath.get("/file5"), FilePermissions.fromOctalString("123"), Instant.EPOCH, ":555"), new FileEntry(someFile, AbsoluteUnixPath.get("/file6"), FilePermissions.fromOctalString("123"), Instant.EPOCH, "333:555"), new FileEntry(someFile, AbsoluteUnixPath.get("/file7"), FilePermissions.fromOctalString("123"), Instant.EPOCH, "user:"), new FileEntry(someFile, AbsoluteUnixPath.get("/file8"), FilePermissions.fromOctalString("123"), Instant.EPOCH, ":group"), new FileEntry(someFile, AbsoluteUnixPath.get("/file9"), FilePermissions.fromOctalString("123"), Instant.EPOCH, "user:group"))).build();
    Path tarFile = temporaryFolder.newFile().toPath();
    try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(tarFile))) {
        blob.writeTo(out);
    }
    try (TarArchiveInputStream in = new TarArchiveInputStream(Files.newInputStream(tarFile))) {
        TarArchiveEntry entry1 = in.getNextTarEntry();
        assertThat(entry1.getLongUserId()).isEqualTo(0);
        assertThat(entry1.getLongGroupId()).isEqualTo(0);
        assertThat(entry1.getUserName()).isEmpty();
        assertThat(entry1.getGroupName()).isEmpty();
        TarArchiveEntry entry2 = in.getNextTarEntry();
        assertThat(entry2.getLongUserId()).isEqualTo(0);
        assertThat(entry2.getLongGroupId()).isEqualTo(0);
        assertThat(entry2.getUserName()).isEmpty();
        assertThat(entry2.getGroupName()).isEmpty();
        TarArchiveEntry entry3 = in.getNextTarEntry();
        assertThat(entry3.getLongUserId()).isEqualTo(0);
        assertThat(entry3.getLongGroupId()).isEqualTo(0);
        assertThat(entry3.getUserName()).isEmpty();
        assertThat(entry3.getGroupName()).isEmpty();
        TarArchiveEntry entry4 = in.getNextTarEntry();
        assertThat(entry4.getLongUserId()).isEqualTo(333);
        assertThat(entry4.getLongGroupId()).isEqualTo(0);
        assertThat(entry4.getUserName()).isEmpty();
        assertThat(entry4.getGroupName()).isEmpty();
        TarArchiveEntry entry5 = in.getNextTarEntry();
        assertThat(entry5.getLongUserId()).isEqualTo(0);
        assertThat(entry5.getLongGroupId()).isEqualTo(555);
        assertThat(entry5.getUserName()).isEmpty();
        assertThat(entry5.getGroupName()).isEmpty();
        TarArchiveEntry entry6 = in.getNextTarEntry();
        assertThat(entry6.getLongUserId()).isEqualTo(333);
        assertThat(entry6.getLongGroupId()).isEqualTo(555);
        assertThat(entry6.getUserName()).isEmpty();
        assertThat(entry6.getGroupName()).isEmpty();
        TarArchiveEntry entry7 = in.getNextTarEntry();
        assertThat(entry7.getLongUserId()).isEqualTo(0);
        assertThat(entry7.getLongGroupId()).isEqualTo(0);
        assertThat(entry7.getUserName()).isEqualTo("user");
        assertThat(entry7.getGroupName()).isEmpty();
        TarArchiveEntry entry8 = in.getNextTarEntry();
        assertThat(entry8.getLongUserId()).isEqualTo(0);
        assertThat(entry8.getLongGroupId()).isEqualTo(0);
        assertThat(entry8.getUserName()).isEmpty();
        assertThat(entry8.getGroupName()).isEqualTo("group");
        TarArchiveEntry entry9 = in.getNextTarEntry();
        assertThat(entry9.getLongUserId()).isEqualTo(0);
        assertThat(entry9.getLongGroupId()).isEqualTo(0);
        assertThat(entry9.getUserName()).isEqualTo("user");
        assertThat(entry9.getGroupName()).isEqualTo("group");
    }
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Blob(com.google.cloud.tools.jib.blob.Blob) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) BufferedOutputStream(java.io.BufferedOutputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) Test(org.junit.Test)

Example 7 with FileEntry

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

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 8 with FileEntry

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

the class PluginConfigurationProcessorTest method testClasspathArgumentFile.

@Test
public void testClasspathArgumentFile() throws NumberFormatException, InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getExtraClasspath()).thenReturn(Collections.singletonList("/foo"));
    when(projectProperties.getMajorJavaVersion()).thenReturn(9);
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "@/app/jib-classpath-file", "java.lang.Object").inOrder();
    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("/foo:/app/resources:/app/classes:/app/libs/foo-1.jar:/app/libs/bar-2.jar");
    String mainClass = new String(Files.readAllBytes(appCacheDirectory.resolve("jib-main-class-file")), StandardCharsets.UTF_8);
    assertThat(mainClass).isEqualTo("java.lang.Object");
}
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 9 with FileEntry

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

the class PluginConfigurationProcessorTest method testAddJvmArgFilesLayer.

@Test
public void testAddJvmArgFilesLayer() throws IOException, InvalidAppRootException {
    String classpath = "/extra:/app/classes:/app/libs/dep.jar";
    String mainClass = "com.example.Main";
    PluginConfigurationProcessor.addJvmArgFilesLayer(rawConfiguration, projectProperties, jibContainerBuilder, classpath, mainClass);
    Path classpathFile = appCacheDirectory.resolve("jib-classpath-file");
    Path mainClassFile = appCacheDirectory.resolve("jib-main-class-file");
    String classpathRead = new String(Files.readAllBytes(classpathFile), StandardCharsets.UTF_8);
    String mainClassRead = new String(Files.readAllBytes(mainClassFile), StandardCharsets.UTF_8);
    assertThat(classpathRead).isEqualTo(classpath);
    assertThat(mainClassRead).isEqualTo(mainClass);
    List<FileEntry> layerEntries = getLayerEntries(jibContainerBuilder.toContainerBuildPlan(), "jvm arg files");
    assertThat(layerEntries).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(appCacheDirectory.resolve("jib-classpath-file"), appCacheDirectory.resolve("jib-main-class-file"));
    assertThat(layerEntries).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/app/jib-classpath-file", "/app/jib-main-class-file");
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Test(org.junit.Test)

Example 10 with FileEntry

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

the class SkaffoldSyncMapTemplateTest method testGetJsonString_emptyGenerated.

@Test
public void testGetJsonString_emptyGenerated() throws IOException {
    SkaffoldSyncMapTemplate ssmt = new SkaffoldSyncMapTemplate();
    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_EMPTY_GENERATED, ssmt.getJsonString());
}
Also used : FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Test(org.junit.Test)

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