use of com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer in project geronimo-arthur by apache.
the class JibMojo method createOthersLayer.
private FileEntriesLayer createOthersLayer() {
final FileEntriesLayer.Builder builder = FileEntriesLayer.builder().setName("Others");
otherFiles.stream().map(File::toPath).forEach(f -> {
final AbsoluteUnixPath containerPath = AbsoluteUnixPath.get(project.getBasedir().toPath().relativize(f).toString());
if (containerPath.toString().contains("..")) {
throw new IllegalArgumentException("You can only include files included in basedir");
}
try {
if (Files.isDirectory(f)) {
builder.addEntryRecursive(f, containerPath, (l, c) -> FilePermissions.DEFAULT_FILE_PERMISSIONS, (l, c) -> {
try {
return getTimestamp(l);
} catch (final IOException e) {
throw new IllegalStateException(e);
}
});
} else {
builder.addEntry(f, containerPath, FilePermissions.DEFAULT_FILE_PERMISSIONS, getTimestamp(f));
}
} catch (final IOException e) {
throw new IllegalStateException(e);
}
});
return builder.build();
}
use of com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer in project jkube by eclipse.
the class JibServiceUtil method layers.
@Nonnull
public static List<FileEntriesLayer> layers(BuildDirs buildDirs, Map<Assembly, List<AssemblyFileEntry>> layers) {
final List<FileEntriesLayer> fileEntriesLayers = new ArrayList<>();
for (Map.Entry<Assembly, List<AssemblyFileEntry>> layer : layers.entrySet()) {
final FileEntriesLayer.Builder fel = FileEntriesLayer.builder();
final String layerId = layer.getKey().getId();
final Path outputPath;
if (StringUtils.isBlank(layerId)) {
outputPath = buildDirs.getOutputDirectory().toPath();
} else {
fel.setName(layerId);
outputPath = new File(buildDirs.getOutputDirectory(), layerId).toPath();
}
for (AssemblyFileEntry afe : layer.getValue()) {
final Path source = afe.getSource().toPath();
final AbsoluteUnixPath target = AbsoluteUnixPath.get(StringUtils.prependIfMissing(FilenameUtils.separatorsToUnix(outputPath.relativize(afe.getDest().toPath()).normalize().toString()), "/"));
final FilePermissions permissions = StringUtils.isNotBlank(afe.getFileMode()) ? FilePermissions.fromOctalString(StringUtils.right(afe.getFileMode(), 3)) : DEFAULT_FILE_PERMISSIONS_PROVIDER.get(source, target);
fel.addEntry(source, target, permissions);
}
fileEntriesLayers.add(fel.build());
}
return fileEntriesLayers;
}
use of com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer in project jkube by eclipse.
the class JibServiceUtilTest method layers_withMultipleLayers_shouldReturnTransformedLayers.
@Test
public void layers_withMultipleLayers_shouldReturnTransformedLayers() throws IOException {
// Given
final BuildDirs buildDirs = new BuildDirs("layers-test", JKubeConfiguration.builder().outputDirectory("target/docker").project(JavaProject.builder().baseDirectory(temporaryFolder.getRoot()).build()).build());
final Map<Assembly, List<AssemblyFileEntry>> originalLayers = new LinkedHashMap<>();
originalLayers.put(Assembly.builder().id("layer-1").build(), Arrays.asList(AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(buildDirs.getOutputDirectory().toPath().resolve("layer-1").resolve("l1.1.txt").toFile()).build(), AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(buildDirs.getOutputDirectory().toPath().resolve("layer-1").resolve("l1.2.txt").toFile()).build()));
originalLayers.put(Assembly.builder().build(), Arrays.asList(AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(new File(buildDirs.getOutputDirectory(), "l2.1.txt")).build(), AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(new File(buildDirs.getOutputDirectory(), "l2.2.txt")).build()));
// Creates a denormalized path in JDK 8
originalLayers.put(Assembly.builder().id("jkube-generated-layer-final-artifact").build(), Collections.singletonList(AssemblyFileEntry.builder().source(temporaryFolder.newFile()).dest(buildDirs.getOutputDirectory().toPath().resolve("jkube-generated-layer-final-artifact").resolve("deployments").resolve(".").resolve("edge.case").toFile()).build()));
// When
final List<FileEntriesLayer> result = JibServiceUtil.layers(buildDirs, originalLayers);
// Then
assertThat(result).hasSize(3).anySatisfy(fel -> assertThat(fel).hasFieldOrPropertyWithValue("name", "layer-1").extracting(FileEntriesLayer::getEntries).asList().extracting("extractionPath.unixPath").containsExactly("/l1.1.txt", "/l1.2.txt")).anySatisfy(fel -> assertThat(fel).hasFieldOrPropertyWithValue("name", "").extracting(FileEntriesLayer::getEntries).asList().extracting("extractionPath.unixPath").containsExactly("/l2.1.txt", "/l2.2.txt")).anySatisfy(fel -> assertThat(fel).hasFieldOrPropertyWithValue("name", "jkube-generated-layer-final-artifact").extracting(FileEntriesLayer::getEntries).asList().extracting("extractionPath.unixPath").containsExactly("/deployments/edge.case")).extracting(FileEntriesLayer::getName).containsExactly("layer-1", "", "jkube-generated-layer-final-artifact");
}
use of com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer in project jib-extensions by GoogleContainerTools.
the class JibSpringBootExtension method filterOutDevtools.
@VisibleForTesting
static LayerObject filterOutDevtools(LayerObject layerObject) {
String dependencyLayerName = JavaContainerBuilder.LayerType.DEPENDENCIES.getName();
if (!dependencyLayerName.equals(layerObject.getName())) {
return layerObject;
}
FileEntriesLayer layer = (FileEntriesLayer) layerObject;
Predicate<FileEntry> notDevtoolsJar = fileEntry -> !isDevtoolsJar(fileEntry.getSourceFile().toFile());
List<FileEntry> newEntries = layer.getEntries().stream().filter(notDevtoolsJar).collect(Collectors.toList());
return layer.toBuilder().setEntries(newEntries).build();
}
use of com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer in project jib-extensions by GoogleContainerTools.
the class JibSpringBootExtensionTest method testExtendContainerBuildPlan_noFiltering.
@Test
public void testExtendContainerBuildPlan_noFiltering() throws JibPluginExtensionException {
when(bootJar.getClasspath()).thenReturn(new MockFileCollection(Paths.get("spring-boot-devtools-1.2.3.jar")));
FileEntriesLayer layer1 = buildLayer("dependencies", Paths.get("spring-boot-devtools-1.2.3.jar"), Paths.get("archive").resolve("bar.zip"));
FileEntriesLayer layer2 = buildLayer("NOT dependencies", Paths.get("spring-boot-devtools-1.2.3.jar"));
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer1).addLayer(layer2).build();
ContainerBuildPlan newPlan = new JibSpringBootExtension().extendContainerBuildPlan(buildPlan, properties, Optional.empty(), gradleData, logger);
assertSame(buildPlan, newPlan);
verify(logger).log(LogLevel.INFO, "Keeping spring-boot-devtools (if any)");
}
Aggregations