Search in sources :

Example 61 with FileEntriesLayer

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

the class JarFilesTest method testToJibContainerBuilder_packagedStandard_basicInfo.

@Test
public void testToJibContainerBuilder_packagedStandard_basicInfo() throws IOException, InvalidImageReferenceException {
    when(mockStandardPackagedProcessor.getJavaVersion()).thenReturn(8);
    FileEntriesLayer layer = FileEntriesLayer.builder().setName("jar").addEntry(Paths.get("path/to/standardJar.jar"), AbsoluteUnixPath.get("/app/standardJar.jar")).build();
    when(mockStandardPackagedProcessor.createLayers()).thenReturn(Arrays.asList(layer));
    when(mockStandardPackagedProcessor.computeEntrypoint(anyList())).thenReturn(ImmutableList.of("java", "-jar", "/app/standardJar.jar"));
    when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.empty());
    JibContainerBuilder containerBuilder = JarFiles.toJibContainerBuilder(mockStandardPackagedProcessor, mockJarCommand, mockCommonCliOptions, mockCommonContainerConfigCliOptions, mockLogger);
    ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
    assertThat(buildPlan.getBaseImage()).isEqualTo("eclipse-temurin:8-jre");
    assertThat(buildPlan.getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("amd64", "linux")));
    assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.EPOCH);
    assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.Docker);
    assertThat(buildPlan.getEnvironment()).isEmpty();
    assertThat(buildPlan.getLabels()).isEmpty();
    assertThat(buildPlan.getVolumes()).isEmpty();
    assertThat(buildPlan.getExposedPorts()).isEmpty();
    assertThat(buildPlan.getUser()).isNull();
    assertThat(buildPlan.getWorkingDirectory()).isNull();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-jar", "/app/standardJar.jar").inOrder();
    assertThat(buildPlan.getLayers().get(0).getName()).isEqualTo("jar");
    assertThat(((FileEntriesLayer) buildPlan.getLayers().get(0)).getEntries()).isEqualTo(FileEntriesLayer.builder().addEntry(Paths.get("path/to/standardJar.jar"), AbsoluteUnixPath.get("/app/standardJar.jar")).build().getEntries());
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 62 with FileEntriesLayer

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

the class SpringBootExplodedProcessorTest method testCreateLayers_layered_singleEmptyLayerListed.

@Test
public void testCreateLayers_layered_singleEmptyLayerListed() throws IOException, URISyntaxException {
    // BOOT-INF/layers.idx for this spring-boot jar is as follows:
    // - "dependencies":
    // - "BOOT-INF/lib/dependency1.jar"
    // - "BOOT-INF/lib/dependency2.jar"
    // - "spring-boot-loader":
    // - "org/"
    // - "snapshot-dependencies":
    // - "application":
    // - "BOOT-INF/classes/"
    // - "META-INF/"
    Path springBootJar = Paths.get(Resources.getResource(SPRING_BOOT_LAYERED_WITH_EMPTY_LAYER).toURI());
    Path destDir = temporaryFolder.newFolder().toPath();
    SpringBootExplodedProcessor springBootExplodedModeProcessor = new SpringBootExplodedProcessor(springBootJar, destDir, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = springBootExplodedModeProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(3);
    FileEntriesLayer nonSnapshotLayer = layers.get(0);
    FileEntriesLayer loaderLayer = layers.get(1);
    FileEntriesLayer applicationLayer = layers.get(2);
    assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
    assertThat(nonSnapshotLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).containsExactly(AbsoluteUnixPath.get("/app/BOOT-INF/lib/dependency1.jar"), AbsoluteUnixPath.get("/app/BOOT-INF/lib/dependency2.jar"));
    assertThat(loaderLayer.getName()).isEqualTo("spring-boot-loader");
    assertThat(loaderLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).containsExactly(AbsoluteUnixPath.get("/app/org/springframework/boot/loader/data/data1.class"), AbsoluteUnixPath.get("/app/org/springframework/boot/loader/launcher1.class"));
    assertThat(applicationLayer.getName()).isEqualTo("application");
    assertThat(applicationLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).containsExactly(AbsoluteUnixPath.get("/app/BOOT-INF/classes/class1.class"), AbsoluteUnixPath.get("/app/BOOT-INF/classes/classDirectory/class2.class"), AbsoluteUnixPath.get("/app/META-INF/MANIFEST.MF"));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 63 with FileEntriesLayer

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

the class SpringBootExplodedProcessorTest method testCreateLayers_layered_allListed.

@Test
public void testCreateLayers_layered_allListed() throws IOException, URISyntaxException {
    // BOOT-INF/layers.idx for this spring-boot jar is as follows:
    // - "dependencies":
    // - "BOOT-INF/lib/dependency1.jar"
    // - "BOOT-INF/lib/dependency2.jar"
    // - "spring-boot-loader":
    // - "org/"
    // - "snapshot-dependencies":
    // - "BOOT-INF/lib/dependency-SNAPSHOT-3.jar"
    // - "application":
    // - "BOOT-INF/classes/"
    // - "META-INF/"
    Path springBootJar = Paths.get(Resources.getResource(SPRING_BOOT_LAYERED).toURI());
    Path destDir = temporaryFolder.newFolder().toPath();
    SpringBootExplodedProcessor springBootExplodedModeProcessor = new SpringBootExplodedProcessor(springBootJar, destDir, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = springBootExplodedModeProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(4);
    FileEntriesLayer nonSnapshotLayer = layers.get(0);
    FileEntriesLayer loaderLayer = layers.get(1);
    FileEntriesLayer snapshotLayer = layers.get(2);
    FileEntriesLayer applicationLayer = layers.get(3);
    assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
    assertThat(nonSnapshotLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).containsExactly(AbsoluteUnixPath.get("/app/BOOT-INF/lib/dependency1.jar"), AbsoluteUnixPath.get("/app/BOOT-INF/lib/dependency2.jar"));
    assertThat(loaderLayer.getName()).isEqualTo("spring-boot-loader");
    assertThat(loaderLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).containsExactly(AbsoluteUnixPath.get("/app/org/springframework/boot/loader/data/data1.class"), AbsoluteUnixPath.get("/app/org/springframework/boot/loader/launcher1.class"));
    assertThat(snapshotLayer.getName()).isEqualTo("snapshot-dependencies");
    assertThat(snapshotLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).containsExactly(AbsoluteUnixPath.get("/app/BOOT-INF/lib/dependency3-SNAPSHOT.jar"));
    assertThat(applicationLayer.getName()).isEqualTo("application");
    assertThat(applicationLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).containsExactly(AbsoluteUnixPath.get("/app/BOOT-INF/classes/class1.class"), AbsoluteUnixPath.get("/app/BOOT-INF/classes/classDirectory/class2.class"), AbsoluteUnixPath.get("/app/META-INF/MANIFEST.MF"));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 64 with FileEntriesLayer

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

the class SpringBootPackagedProcessorTest method testCreateLayers.

@Test
public void testCreateLayers() throws URISyntaxException {
    Path springBootJar = Paths.get(Resources.getResource(SPRING_BOOT_JAR).toURI());
    SpringBootPackagedProcessor springBootProcessor = new SpringBootPackagedProcessor(springBootJar, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = springBootProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(1);
    FileEntriesLayer jarLayer = layers.get(0);
    assertThat(jarLayer.getName()).isEqualTo("jar");
    assertThat(jarLayer.getEntries().size()).isEqualTo(1);
    assertThat(jarLayer.getEntries().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/springboot_sample.jar"));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 65 with FileEntriesLayer

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

the class StandardExplodedProcessorTest method testCreateLayers_withClassPathInManifest.

@Test
public void testCreateLayers_withClassPathInManifest() throws IOException, URISyntaxException {
    Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_WITH_CLASS_PATH_MANIFEST).toURI());
    Path destDir = temporaryFolder.newFolder().toPath();
    StandardExplodedProcessor standardExplodedModeProcessor = new StandardExplodedProcessor(standardJar, destDir, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = standardExplodedModeProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(4);
    FileEntriesLayer nonSnapshotLayer = layers.get(0);
    FileEntriesLayer snapshotLayer = layers.get(1);
    FileEntriesLayer resourcesLayer = layers.get(2);
    FileEntriesLayer classesLayer = layers.get(3);
    // Validate dependencies layers.
    assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
    assertThat(nonSnapshotLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).isEqualTo(ImmutableList.of(AbsoluteUnixPath.get("/app/dependencies/dependency1"), AbsoluteUnixPath.get("/app/dependencies/dependency2"), AbsoluteUnixPath.get("/app/dependencies/dependency4")));
    assertThat(snapshotLayer.getName()).isEqualTo("snapshot dependencies");
    assertThat(snapshotLayer.getEntries().size()).isEqualTo(1);
    assertThat(snapshotLayer.getEntries().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/dependencies/dependency3-SNAPSHOT-1.jar"));
    // Validate resources layer.
    assertThat(resourcesLayer.getName()).isEqualTo("resources");
    List<AbsoluteUnixPath> actualResourcesPaths = resourcesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
    assertThat(actualResourcesPaths).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/META-INF/MANIFEST.MF"), AbsoluteUnixPath.get("/app/explodedJar/directory1/resource1.txt"), AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/resource2.sql"), AbsoluteUnixPath.get("/app/explodedJar/directory4/resource3.txt"), AbsoluteUnixPath.get("/app/explodedJar/resource4.sql"));
    // Validate classes layer.
    assertThat(classesLayer.getName()).isEqualTo("classes");
    List<AbsoluteUnixPath> actualClassesPaths = classesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
    assertThat(actualClassesPaths).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/class5.class"), AbsoluteUnixPath.get("/app/explodedJar/directory1/class1.class"), AbsoluteUnixPath.get("/app/explodedJar/directory1/class2.class"), AbsoluteUnixPath.get("/app/explodedJar/directory2/class4.class"), AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/class3.class"));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Aggregations

FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)154 Test (org.junit.Test)111 Path (java.nio.file.Path)92 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)85 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)55 List (java.util.List)29 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)26 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)24 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)23 Map (java.util.Map)23 Files (java.nio.file.Files)21 Predicate (java.util.function.Predicate)20 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)16 Collectors (java.util.stream.Collectors)16 FilePermissions (com.google.cloud.tools.jib.api.buildplan.FilePermissions)13 Paths (java.nio.file.Paths)13 Optional (java.util.Optional)13 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)12 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)12