use of com.google.cloud.tools.jib.gradle.extension.GradleData in project jib-extensions by GoogleContainerTools.
the class JibQuarkusExtension method extendContainerBuildPlan.
@Override
public ContainerBuildPlan extendContainerBuildPlan(ContainerBuildPlan buildPlan, Map<String, String> properties, Optional<Void> config, GradleData gradleData, ExtensionLogger logger) throws JibPluginExtensionException {
try {
logger.log(LogLevel.LIFECYCLE, "Running Quarkus Jib extension");
readJibConfigurations(gradleData.getProject());
Project project = gradleData.getProject();
Path buildDir = project.getBuildDir().toPath();
Jar jarTask = (Jar) project.getTasks().findByName("jar");
String jarName = jarTask.getArchiveFile().get().getAsFile().getName();
Path jar = buildDir.resolve(jarName.replaceAll("\\.jar$", "-runner.jar"));
if (!Files.isRegularFile(jar)) {
throw new JibPluginExtensionException(getClass(), jar + " doesn't exist; did you run the Qaurkus Gradle plugin ('quarkusBuild' task)?");
}
ContainerBuildPlan.Builder planBuilder = buildPlan.toBuilder();
planBuilder.setLayers(Collections.emptyList());
// dependency layers
addDependencyLayers(project, planBuilder, buildDir.resolve("lib"));
// Quarkus runner JAR layer
AbsoluteUnixPath appRootJar = appRoot.resolve("app.jar");
FileEntriesLayer jarLayer = FileEntriesLayer.builder().setName("quarkus jar").addEntry(jar, appRootJar).build();
planBuilder.addLayer(jarLayer);
// Preserve extra directories layers.
String extraFilesLayerName = JavaContainerBuilder.LayerType.EXTRA_FILES.getName();
buildPlan.getLayers().stream().filter(layer -> layer.getName().startsWith(extraFilesLayerName)).forEach(planBuilder::addLayer);
// set entrypoint
List<String> entrypoint = new ArrayList<>();
entrypoint.add("java");
entrypoint.addAll(jvmFlags);
entrypoint.add("-jar");
entrypoint.add(appRootJar.toString());
planBuilder.setEntrypoint(entrypoint);
return planBuilder.build();
} catch (IOException ex) {
throw new JibPluginExtensionException(getClass(), Verify.verifyNotNull(ex.getMessage()), ex);
}
}
use of com.google.cloud.tools.jib.gradle.extension.GradleData in project jib-extensions by GoogleContainerTools.
the class JibLayerFilterExtension method extendContainerBuildPlan.
@Override
public ContainerBuildPlan extendContainerBuildPlan(ContainerBuildPlan buildPlan, Map<String, String> properties, Optional<Configuration> config, GradleData gradleData, ExtensionLogger logger) throws JibPluginExtensionException {
logger.log(LogLevel.LIFECYCLE, "Running Jib Layer Filter Extension");
if (!config.isPresent()) {
logger.log(LogLevel.WARN, "Nothing configured for Jib Layer Filter Extension");
return buildPlan;
}
preparePathMatchersAndLayerBuilders(buildPlan, config.get());
ContainerBuildPlan.Builder newPlanBuilder = buildPlan.toBuilder();
newPlanBuilder.setLayers(Collections.emptyList());
@SuppressWarnings("unchecked") List<FileEntriesLayer> originalLayers = (List<FileEntriesLayer>) buildPlan.getLayers();
// Start filtering original layers.
for (FileEntriesLayer layer : originalLayers) {
List<FileEntry> filesToKeep = new ArrayList<>();
for (FileEntry entry : layer.getEntries()) {
Optional<String> finalLayerName = determineFinalLayerName(entry, layer.getName());
// Either keep, move, or delete this FileEntry.
if (finalLayerName.isPresent()) {
if (finalLayerName.get().equals(layer.getName())) {
filesToKeep.add(entry);
} else {
FileEntriesLayer.Builder targetLayerBuilder = Verify.verifyNotNull(newToLayers.get(finalLayerName.get()));
targetLayerBuilder.addEntry(entry);
}
}
}
if (!filesToKeep.isEmpty()) {
newPlanBuilder.addLayer(layer.toBuilder().setEntries(filesToKeep).build());
}
}
// Add newly created non-empty to-layers (if any).
newToLayers.values().stream().map(FileEntriesLayer.Builder::build).filter(layer -> !layer.getEntries().isEmpty()).forEach(newPlanBuilder::addLayer);
return newPlanBuilder.build();
}
Aggregations