use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
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 google.
the class JibContainerBuilderTest method testToBuildContext_containerConfigurationAdd.
@Test
public void testToBuildContext_containerConfigurationAdd() throws InvalidImageReferenceException, CacheDirectoryCreationException {
ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
JibContainerBuilder jibContainerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).addPlatform("testArchitecture", "testOS").setEntrypoint("entry", "point").setEnvironment(ImmutableMap.of("name", "value")).addEnvironmentVariable("environment", "variable").setExposedPorts(Port.tcp(1234), Port.udp(5678)).addExposedPort(Port.tcp(1337)).setLabels(ImmutableMap.of("key", "value")).addLabel("added", "label").setProgramArguments("program", "arguments");
BuildContext buildContext = jibContainerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS"), new Platform("amd64", "linux")), containerConfiguration.getPlatforms());
Assert.assertEquals(Arrays.asList("entry", "point"), containerConfiguration.getEntrypoint());
Assert.assertEquals(ImmutableMap.of("name", "value", "environment", "variable"), containerConfiguration.getEnvironmentMap());
Assert.assertEquals(ImmutableSet.of(Port.tcp(1234), Port.udp(5678), Port.tcp(1337)), containerConfiguration.getExposedPorts());
Assert.assertEquals(ImmutableMap.of("key", "value", "added", "label"), containerConfiguration.getLabels());
Assert.assertEquals(Arrays.asList("program", "arguments"), containerConfiguration.getProgramArguments());
Assert.assertEquals(Instant.EPOCH, containerConfiguration.getCreationTime());
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
the class JibContainerTest method testCreation_withBuildContextAndBuildResult.
@Test
public void testCreation_withBuildContextAndBuildResult() {
BuildResult buildResult = Mockito.mock(BuildResult.class);
BuildContext buildContext = Mockito.mock(BuildContext.class);
ImageConfiguration mockTargetConfiguration = Mockito.mock(ImageConfiguration.class);
when(buildResult.getImageDigest()).thenReturn(digest1);
when(buildResult.getImageId()).thenReturn(digest1);
when(buildResult.isImagePushed()).thenReturn(true);
when(mockTargetConfiguration.getImage()).thenReturn(targetImage1);
when(buildContext.getTargetImageConfiguration()).thenReturn(mockTargetConfiguration);
when(buildContext.getAllTargetImageTags()).thenReturn(ImmutableSet.copyOf(tags1));
JibContainer container = JibContainer.from(buildContext, buildResult);
Assert.assertEquals(targetImage1, container.getTargetImage());
Assert.assertEquals(digest1, container.getDigest());
Assert.assertEquals(digest1, container.getImageId());
Assert.assertEquals(tags1, container.getTags());
Assert.assertTrue(container.isImagePushed());
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
the class RegistryCredentialRetrieverTest method testCall_retrieved.
@Test
public void testCall_retrieved() throws CredentialRetrievalException, CacheDirectoryCreationException {
BuildContext buildContext = makeFakeBuildContext(Arrays.asList(Optional::empty, () -> Optional.of(Credential.from("baseusername", "basepassword"))), Arrays.asList(() -> Optional.of(Credential.from("targetusername", "targetpassword")), () -> Optional.of(Credential.from("ignored", "ignored"))));
Assert.assertEquals(Optional.of(Credential.from("baseusername", "basepassword")), RegistryCredentialRetriever.getBaseImageCredential(buildContext));
Assert.assertEquals(Optional.of(Credential.from("targetusername", "targetpassword")), RegistryCredentialRetriever.getTargetImageCredential(buildContext));
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
the class RegistryCredentialRetrieverTest method testCall_none.
@Test
public void testCall_none() throws CredentialRetrievalException, CacheDirectoryCreationException {
BuildContext buildContext = makeFakeBuildContext(Arrays.asList(Optional::empty, Optional::empty), Collections.emptyList());
Assert.assertFalse(RegistryCredentialRetriever.getBaseImageCredential(buildContext).isPresent());
Mockito.verify(mockEventHandlers).dispatch(LogEvent.info("No credentials could be retrieved for baseregistry/baserepo"));
Assert.assertFalse(RegistryCredentialRetriever.getTargetImageCredential(buildContext).isPresent());
Mockito.verify(mockEventHandlers).dispatch(LogEvent.info("No credentials could be retrieved for targetregistry/targetrepo"));
}
Aggregations