use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib-extensions by GoogleContainerTools.
the class JibOwnershipExtensionTest method testExtendContainerBuildPlan_noGlobGiven.
@Test
public void testExtendContainerBuildPlan_noGlobGiven() {
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
Configuration.Rule rule = mockRule("", "doesn't matter");
when(config.getRules()).thenReturn(Arrays.asList(rule));
try {
new JibOwnershipExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
fail();
} catch (JibPluginExtensionException ex) {
assertEquals(JibOwnershipExtension.class, ex.getExtensionClass());
assertEquals("glob pattern not given in ownership configuration", ex.getMessage());
}
}
use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib-extensions by GoogleContainerTools.
the class JibOwnershipExtensionTest method testExtendContainerBuildPlan_noConfiguration.
@Test
public void testExtendContainerBuildPlan_noConfiguration() throws JibPluginExtensionException {
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
ContainerBuildPlan newPlan = new JibOwnershipExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), null, logger);
assertSame(buildPlan, newPlan);
verify(logger).log(LogLevel.WARN, "Nothing configured for Jib Ownership Extension");
}
use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib-extensions by GoogleContainerTools.
the class JibOwnershipExtensionTest method testExtendContainerBuildPlan.
@Test
public void testExtendContainerBuildPlan() throws JibPluginExtensionException {
FileEntriesLayer layer1 = FileEntriesLayer.builder().addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/file")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/another")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/sub/dir/file")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/sub/dir/another")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/untouched/file")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/untouched/another")).build();
FileEntriesLayer layer2 = FileEntriesLayer.builder().addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/foo")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/bar")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/sub/dir/foo")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/target/sub/dir/bar")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/untouched/foo")).addEntry(Paths.get("whatever"), AbsoluteUnixPath.get("/untouched/bar")).build();
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer1).addLayer(layer2).build();
Configuration.Rule rule1 = mockRule("/target/**", "10:20");
Configuration.Rule rule2 = mockRule("**/bar", "999:777");
when(config.getRules()).thenReturn(Arrays.asList(rule1, rule2));
ContainerBuildPlan newPlan = new JibOwnershipExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
FileEntriesLayer newLayer1 = (FileEntriesLayer) newPlan.getLayers().get(0);
FileEntriesLayer newLayer2 = (FileEntriesLayer) newPlan.getLayers().get(1);
assertEquals(Arrays.asList(AbsoluteUnixPath.get("/target/file"), AbsoluteUnixPath.get("/target/another"), AbsoluteUnixPath.get("/target/sub/dir/file"), AbsoluteUnixPath.get("/target/sub/dir/another"), AbsoluteUnixPath.get("/untouched/file"), AbsoluteUnixPath.get("/untouched/another")), mapLayerEntries(newLayer1, FileEntry::getExtractionPath));
assertEquals(Arrays.asList("10:20", "10:20", "10:20", "10:20", "", ""), mapLayerEntries(newLayer1, FileEntry::getOwnership));
assertEquals(Arrays.asList(AbsoluteUnixPath.get("/target/foo"), AbsoluteUnixPath.get("/target/bar"), AbsoluteUnixPath.get("/target/sub/dir/foo"), AbsoluteUnixPath.get("/target/sub/dir/bar"), AbsoluteUnixPath.get("/untouched/foo"), AbsoluteUnixPath.get("/untouched/bar")), mapLayerEntries(newLayer2, FileEntry::getExtractionPath));
assertEquals(Arrays.asList("10:20", "999:777", "10:20", "999:777", "", "999:777"), mapLayerEntries(newLayer2, FileEntry::getOwnership));
}
use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan 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.api.buildplan.ContainerBuildPlan in project jib-extensions by GoogleContainerTools.
the class JibQuarkusExtensionTest method testExtendContainerBuildPlan_layers.
@Test
public void testExtendContainerBuildPlan_layers() throws JibPluginExtensionException {
FileEntriesLayer originalLayer = buildLayer("to be reset", Arrays.asList("/ignored"));
FileEntriesLayer extraLayer1 = buildLayer("extra files", Arrays.asList("/extra/files/1"));
FileEntriesLayer extraLayer2 = buildLayer("extra files", Arrays.asList("/extra/files/2"));
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().setLayers(Arrays.asList(originalLayer, extraLayer1, extraLayer2)).build();
ContainerBuildPlan newPlan = new JibQuarkusExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), gradleData, logger);
assertEquals(6, newPlan.getLayers().size());
FileEntriesLayer layer1 = (FileEntriesLayer) newPlan.getLayers().get(0);
FileEntriesLayer layer2 = (FileEntriesLayer) newPlan.getLayers().get(1);
FileEntriesLayer layer3 = (FileEntriesLayer) newPlan.getLayers().get(2);
FileEntriesLayer layer4 = (FileEntriesLayer) newPlan.getLayers().get(3);
FileEntriesLayer layer5 = (FileEntriesLayer) newPlan.getLayers().get(4);
FileEntriesLayer layer6 = (FileEntriesLayer) newPlan.getLayers().get(5);
assertEquals("dependencies", layer1.getName());
assertEquals("snapshot dependencies", layer2.getName());
assertEquals("project dependencies", layer3.getName());
assertEquals("quarkus jar", layer4.getName());
assertEquals("extra files", layer5.getName());
assertEquals("extra files", layer6.getName());
assertEquals(Arrays.asList("/new/appRoot/lib/com.example.third-party-artifact.jar"), layerToExtractionPaths(layer1));
assertEquals(Arrays.asList("/new/appRoot/lib/com.example.third-party-SNAPSHOT-artifact.jar"), layerToExtractionPaths(layer2));
assertEquals(Arrays.asList("/new/appRoot/lib/com.example.sub-module-artifact.jar"), layerToExtractionPaths(layer3));
assertEquals(Arrays.asList("/new/appRoot/app.jar"), layerToExtractionPaths(layer4));
assertEquals(extraLayer1.getEntries(), layer5.getEntries());
assertEquals(extraLayer2.getEntries(), layer6.getEntries());
}
Aggregations