Search in sources :

Example 76 with FileEntriesLayer

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

the class LayersTest method testToLayers_file.

@Test
public void testToLayers_file() throws IOException, URISyntaxException {
    Path testRoot = getLayersTestRoot("fileTest/default");
    List<FileEntriesLayer> layers = parseLayers(testRoot, 1);
    checkLayer(layers.get(0), "default", ImmutableSet.of(newEntry(testRoot, "toFile.txt", "/target/toFile.txt", "644", 0, "0:0"), newEntry(testRoot, "toDir.txt", "/target/dir/toDir.txt", "644", 0, "0:0")));
}
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 77 with FileEntriesLayer

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

the class JarFilesTest method testToJibContainerBuilder_packagedSpringBoot_basicInfo.

@Test
public void testToJibContainerBuilder_packagedSpringBoot_basicInfo() throws IOException, InvalidImageReferenceException {
    when(mockSpringBootPackagedProcessor.getJavaVersion()).thenReturn(8);
    FileEntriesLayer layer = FileEntriesLayer.builder().setName("jar").addEntry(Paths.get("path/to/spring-boot.jar"), AbsoluteUnixPath.get("/app/spring-boot.jar")).build();
    when(mockSpringBootPackagedProcessor.createLayers()).thenReturn(Arrays.asList(layer));
    when(mockSpringBootPackagedProcessor.computeEntrypoint(anyList())).thenReturn(ImmutableList.of("java", "-jar", "/app/spring-boot.jar"));
    when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.empty());
    JibContainerBuilder containerBuilder = JarFiles.toJibContainerBuilder(mockSpringBootPackagedProcessor, 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/spring-boot.jar").inOrder();
    assertThat(buildPlan.getLayers()).hasSize(1);
    assertThat(buildPlan.getLayers().get(0).getName()).isEqualTo("jar");
    assertThat(((FileEntriesLayer) buildPlan.getLayers().get(0)).getEntries()).isEqualTo(FileEntriesLayer.builder().addEntry(Paths.get("path/to/spring-boot.jar"), AbsoluteUnixPath.get("/app/spring-boot.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 78 with FileEntriesLayer

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

the class SpringBootExplodedProcessorTest method testCreateLayers_layered_allEmptyLayersListed.

@Test
public void testCreateLayers_layered_allEmptyLayersListed() throws IOException, URISyntaxException {
    // BOOT-INF/layers.idx for this spring-boot jar is as follows:
    // - "dependencies":
    // - "spring-boot-loader":
    // - "snapshot-dependencies":
    // - "application":
    Path springBootJar = Paths.get(Resources.getResource(SPRING_BOOT_LAYERED_WITH_ALL_EMPTY_LAYERS_LISTED).toURI());
    Path destDir = temporaryFolder.newFolder().toPath();
    SpringBootExplodedProcessor springBootExplodedModeProcessor = new SpringBootExplodedProcessor(springBootJar, destDir, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = springBootExplodedModeProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(0);
}
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 79 with FileEntriesLayer

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

the class SpringBootExplodedProcessorTest method testCreateLayers_nonLayered.

@Test
public void testCreateLayers_nonLayered() throws IOException, URISyntaxException {
    Path springBootJar = Paths.get(Resources.getResource(SPRING_BOOT_NOT_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(5);
    FileEntriesLayer nonSnapshotLayer = layers.get(0);
    FileEntriesLayer loaderLayer = layers.get(1);
    FileEntriesLayer snapshotLayer = layers.get(2);
    FileEntriesLayer resourcesLayer = layers.get(3);
    FileEntriesLayer classesLayer = layers.get(4);
    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().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/BOOT-INF/lib/dependency3-SNAPSHOT.jar"));
    assertThat(resourcesLayer.getName()).isEqualTo("resources");
    assertThat(resourcesLayer.getEntries().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/META-INF/MANIFEST.MF"));
    assertThat(classesLayer.getName()).isEqualTo("classes");
    assertThat(classesLayer.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"));
}
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 80 with FileEntriesLayer

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

the class StandardExplodedProcessorTest method testCreateLayers_withoutClassPathInManifest_containsOnlyClasses.

@Test
public void testCreateLayers_withoutClassPathInManifest_containsOnlyClasses() throws IOException, URISyntaxException {
    Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_WITH_ONLY_CLASSES).toURI());
    Path destDir = temporaryFolder.newFolder().toPath();
    StandardExplodedProcessor standardExplodedModeProcessor = new StandardExplodedProcessor(standardJar, destDir, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = standardExplodedModeProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(2);
    FileEntriesLayer resourcesLayer = layers.get(0);
    FileEntriesLayer classesLayer = layers.get(1);
    // Validate resources layer.
    assertThat(resourcesLayer.getEntries().size()).isEqualTo(1);
    assertThat(resourcesLayer.getEntries().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/explodedJar/META-INF/MANIFEST.MF"));
    // Validate classes layer.
    List<AbsoluteUnixPath> actualClassesPath = classesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
    assertThat(actualClassesPath).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/class1.class"), AbsoluteUnixPath.get("/app/explodedJar/class2.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