use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class JavaContainerBuilderTest method testToJibContainerBuilder_setAppRootLate.
@Test
public void testToJibContainerBuilder_setAppRootLate() throws URISyntaxException, IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
BuildContext buildContext = JavaContainerBuilder.from("scratch").addClasses(getResource("core/application/classes")).addResources(getResource("core/application/resources")).addDependencies(getResource("core/application/dependencies/libraryA.jar")).addToClasspath(getResource("core/fileA")).setAppRoot("/different").setMainClass("HelloWorld").toContainerBuilder().toBuildContext(Containerizer.to(RegistryImage.named("hello")));
// Check entrypoint
Assert.assertEquals(ImmutableList.of("java", "-cp", "/different/classes:/different/resources:/different/libs/*:/different/classpath", "HelloWorld"), buildContext.getContainerConfiguration().getEntrypoint());
// Check classes
List<AbsoluteUnixPath> expectedClasses = ImmutableList.of(AbsoluteUnixPath.get("/different/classes/HelloWorld.class"), AbsoluteUnixPath.get("/different/classes/some.class"));
Assert.assertEquals(expectedClasses, getExtractionPaths(buildContext, "classes"));
// Check resources
List<AbsoluteUnixPath> expectedResources = ImmutableList.of(AbsoluteUnixPath.get("/different/resources/resourceA"), AbsoluteUnixPath.get("/different/resources/resourceB"), AbsoluteUnixPath.get("/different/resources/world"));
Assert.assertEquals(expectedResources, getExtractionPaths(buildContext, "resources"));
// Check dependencies
List<AbsoluteUnixPath> expectedDependencies = ImmutableList.of(AbsoluteUnixPath.get("/different/libs/libraryA.jar"));
Assert.assertEquals(expectedDependencies, getExtractionPaths(buildContext, "dependencies"));
Assert.assertEquals(expectedClasses, getExtractionPaths(buildContext, "classes"));
// Check additional classpath files
List<AbsoluteUnixPath> expectedOthers = ImmutableList.of(AbsoluteUnixPath.get("/different/classpath/fileA"));
Assert.assertEquals(expectedOthers, getExtractionPaths(buildContext, "extra files"));
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class JavaContainerBuilderTest method testToJibContainerBuilder_all.
@Test
public void testToJibContainerBuilder_all() throws InvalidImageReferenceException, URISyntaxException, IOException, CacheDirectoryCreationException {
BuildContext buildContext = JavaContainerBuilder.from("scratch").setAppRoot("/hello").addResources(getResource("core/application/resources")).addClasses(getResource("core/application/classes")).addDependencies(getResource("core/application/dependencies/dependency-1.0.0.jar"), getResource("core/application/dependencies/more/dependency-1.0.0.jar")).addSnapshotDependencies(getResource("core/application/snapshot-dependencies/dependency-1.0.0-SNAPSHOT.jar")).addProjectDependencies(getResource("core/application/dependencies/libraryA.jar"), getResource("core/application/dependencies/libraryB.jar")).addToClasspath(getResource("core/fileA"), getResource("core/fileB")).setClassesDestination(RelativeUnixPath.get("different-classes")).setResourcesDestination(RelativeUnixPath.get("different-resources")).setDependenciesDestination(RelativeUnixPath.get("different-libs")).setOthersDestination(RelativeUnixPath.get("different-classpath")).addJvmFlags("-xflag1", "-xflag2").setMainClass("HelloWorld").toContainerBuilder().toBuildContext(Containerizer.to(RegistryImage.named("hello")));
// Check entrypoint
Assert.assertEquals(ImmutableList.of("java", "-xflag1", "-xflag2", "-cp", "/hello/different-resources:/hello/different-classes:/hello/different-libs/*:/hello/different-classpath", "HelloWorld"), buildContext.getContainerConfiguration().getEntrypoint());
// Check dependencies
List<AbsoluteUnixPath> expectedDependencies = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-libs/dependency-1.0.0-770.jar"), AbsoluteUnixPath.get("/hello/different-libs/dependency-1.0.0-200.jar"));
Assert.assertEquals(expectedDependencies, getExtractionPaths(buildContext, "dependencies"));
// Check snapshots
List<AbsoluteUnixPath> expectedSnapshotDependencies = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-libs/dependency-1.0.0-SNAPSHOT.jar"));
Assert.assertEquals(expectedSnapshotDependencies, getExtractionPaths(buildContext, "snapshot dependencies"));
List<AbsoluteUnixPath> expectedProjectDependencies = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-libs/libraryA.jar"), AbsoluteUnixPath.get("/hello/different-libs/libraryB.jar"));
Assert.assertEquals(expectedProjectDependencies, getExtractionPaths(buildContext, "project dependencies"));
// Check resources
List<AbsoluteUnixPath> expectedResources = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-resources/resourceA"), AbsoluteUnixPath.get("/hello/different-resources/resourceB"), AbsoluteUnixPath.get("/hello/different-resources/world"));
Assert.assertEquals(expectedResources, getExtractionPaths(buildContext, "resources"));
// Check classes
List<AbsoluteUnixPath> expectedClasses = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-classes/HelloWorld.class"), AbsoluteUnixPath.get("/hello/different-classes/some.class"));
Assert.assertEquals(expectedClasses, getExtractionPaths(buildContext, "classes"));
// Check additional classpath files
List<AbsoluteUnixPath> expectedOthers = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-classpath/fileA"), AbsoluteUnixPath.get("/hello/different-classpath/fileB"));
Assert.assertEquals(expectedOthers, getExtractionPaths(buildContext, "extra files"));
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class JavaContainerBuilderTest method testToJibContainerBuilder_missingAndMultipleAdds.
@Test
public void testToJibContainerBuilder_missingAndMultipleAdds() throws InvalidImageReferenceException, URISyntaxException, IOException, CacheDirectoryCreationException {
BuildContext buildContext = JavaContainerBuilder.from("scratch").addDependencies(getResource("core/application/dependencies/libraryA.jar")).addDependencies(getResource("core/application/dependencies/libraryB.jar")).addSnapshotDependencies(getResource("core/application/snapshot-dependencies/dependency-1.0.0-SNAPSHOT.jar")).addClasses(getResource("core/application/classes/")).addClasses(getResource("core/class-finder-tests/extension")).setMainClass("HelloWorld").toContainerBuilder().toBuildContext(Containerizer.to(RegistryImage.named("hello")));
// Check entrypoint
Assert.assertEquals(ImmutableList.of("java", "-cp", "/app/libs/*:/app/classes", "HelloWorld"), buildContext.getContainerConfiguration().getEntrypoint());
// Check dependencies
List<AbsoluteUnixPath> expectedDependencies = ImmutableList.of(AbsoluteUnixPath.get("/app/libs/libraryA.jar"), AbsoluteUnixPath.get("/app/libs/libraryB.jar"));
Assert.assertEquals(expectedDependencies, getExtractionPaths(buildContext, "dependencies"));
// Check snapshots
List<AbsoluteUnixPath> expectedSnapshotDependencies = ImmutableList.of(AbsoluteUnixPath.get("/app/libs/dependency-1.0.0-SNAPSHOT.jar"));
Assert.assertEquals(expectedSnapshotDependencies, getExtractionPaths(buildContext, "snapshot dependencies"));
// Check classes
List<AbsoluteUnixPath> expectedClasses = ImmutableList.of(AbsoluteUnixPath.get("/app/classes/HelloWorld.class"), AbsoluteUnixPath.get("/app/classes/some.class"), AbsoluteUnixPath.get("/app/classes/main/"), AbsoluteUnixPath.get("/app/classes/main/MainClass.class"), AbsoluteUnixPath.get("/app/classes/pack/"), AbsoluteUnixPath.get("/app/classes/pack/Apple.class"), AbsoluteUnixPath.get("/app/classes/pack/Orange.class"));
Assert.assertEquals(expectedClasses, getExtractionPaths(buildContext, "classes"));
// Check empty layers
Assert.assertEquals(ImmutableList.of(), getExtractionPaths(buildContext, "resources"));
Assert.assertEquals(ImmutableList.of(), getExtractionPaths(buildContext, "extra files"));
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class JibContainerBuilderTest method testToBuildContext_containerConfigurationSet.
@Test
public void testToBuildContext_containerConfigurationSet() throws InvalidImageReferenceException, CacheDirectoryCreationException {
ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
JibContainerBuilder jibContainerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).setPlatforms(ImmutableSet.of(new Platform("testArchitecture", "testOS"))).setEntrypoint(Arrays.asList("entry", "point")).setEnvironment(ImmutableMap.of("name", "value")).setExposedPorts(ImmutableSet.of(Port.tcp(1234), Port.udp(5678))).setLabels(ImmutableMap.of("key", "value")).setProgramArguments(Arrays.asList("program", "arguments")).setCreationTime(Instant.ofEpochMilli(1000)).setUser("user").setWorkingDirectory(AbsoluteUnixPath.get("/working/directory"));
BuildContext buildContext = jibContainerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS")), containerConfiguration.getPlatforms());
Assert.assertEquals(Arrays.asList("entry", "point"), containerConfiguration.getEntrypoint());
Assert.assertEquals(ImmutableMap.of("name", "value"), containerConfiguration.getEnvironmentMap());
Assert.assertEquals(ImmutableSet.of(Port.tcp(1234), Port.udp(5678)), containerConfiguration.getExposedPorts());
Assert.assertEquals(ImmutableMap.of("key", "value"), containerConfiguration.getLabels());
Assert.assertEquals(Arrays.asList("program", "arguments"), containerConfiguration.getProgramArguments());
Assert.assertEquals(Instant.ofEpochMilli(1000), containerConfiguration.getCreationTime());
Assert.assertEquals("user", containerConfiguration.getUser());
Assert.assertEquals(AbsoluteUnixPath.get("/working/directory"), containerConfiguration.getWorkingDirectory());
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class PushImageStep method makeListForManifestList.
static ImmutableList<PushImageStep> makeListForManifestList(BuildContext buildContext, ProgressEventDispatcher.Factory progressEventDispatcherFactory, RegistryClient registryClient, ManifestTemplate manifestList, boolean manifestListAlreadyExists) throws IOException {
Set<String> tags = buildContext.getAllTargetImageTags();
EventHandlers eventHandlers = buildContext.getEventHandlers();
try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, "Preparing manifest list pushers");
ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("launching manifest list pushers", tags.size())) {
boolean singlePlatform = buildContext.getContainerConfiguration().getPlatforms().size() == 1;
if (singlePlatform) {
// single image; no need to push a manifest list
return ImmutableList.of();
}
if (JibSystemProperties.skipExistingImages() && manifestListAlreadyExists) {
eventHandlers.dispatch(LogEvent.info("Skipping pushing manifest list; already exists."));
return ImmutableList.of();
}
DescriptorDigest manifestListDigest = Digests.computeJsonDigest(manifestList);
return tags.stream().map(tag -> new PushImageStep(buildContext, progressEventDispatcher.newChildProducer(), registryClient, manifestList, tag, manifestListDigest, // return value and type.
manifestListDigest)).collect(ImmutableList.toImmutableList());
}
}
Aggregations