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")));
}
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());
}
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);
}
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"));
}
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"));
}
Aggregations