use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class PlatformCheckerTest method testCheckManifestPlatform_tarBaseImage.
@Test
public void testCheckManifestPlatform_tarBaseImage() {
Path tar = Paths.get("/foo/bar.tar");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(ImageReference.scratch()).setTarPath(tar).build());
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arch", "os")));
PlatformChecker.checkManifestPlatform(buildContext, new ContainerConfigurationTemplate());
Mockito.verify(eventHandlers).dispatch(LogEvent.warn("platforms configured, but '" + tar.toString() + "' is not a manifest list"));
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class PlatformCheckerTest method testCheckManifestPlatform_multiplePlatformsConfigured.
@Test
public void testCheckManifestPlatform_multiplePlatformsConfigured() {
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arch", "os")));
PlatformChecker.checkManifestPlatform(buildContext, new ContainerConfigurationTemplate());
Mockito.verify(eventHandlers).dispatch(LogEvent.warn("platforms configured, but 'scratch' is not a manifest list"));
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms.
@Test
public void testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("target-arch", "target-os")).thenReturn(Arrays.asList("sha256:target-digest"));
ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
containerConfigJson.setContainerUser("target-user");
ManifestAndConfigTemplate targetManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:target-digest");
ManifestAndConfigTemplate unrelatedManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:unrelated-digest");
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(unrelatedManifestAndConfig, targetManifestAndConfig, unrelatedManifestAndConfig));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("target-arch", "target-os")));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(1, images.size());
Assert.assertEquals("target-user", images.get(0).getUser());
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_partialMatches.
@Test
public void testGetCachedBaseImages_v22ManifestListCached_partialMatches() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1")).thenReturn(Arrays.asList("sha256:digest1"));
Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2")).thenReturn(Arrays.asList("sha256:digest2"));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest1")));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
Assert.assertEquals(Arrays.asList(), pullBaseImageStep.getCachedBaseImages());
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testCall_scratch_multiplePlatforms.
@Test
public void testCall_scratch_multiplePlatforms() throws LayerPropertyNotFoundException, IOException, RegistryException, LayerCountMismatchException, BadContainerConfigurationFormatException, CacheCorruptedException, CredentialRetrievalException {
Mockito.when(imageConfiguration.getImage()).thenReturn(ImageReference.scratch());
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("architecture1", "os1"), new Platform("architecture2", "os2")));
ImagesAndRegistryClient result = pullBaseImageStep.call();
Assert.assertEquals(2, result.images.size());
Assert.assertEquals("architecture1", result.images.get(0).getArchitecture());
Assert.assertEquals("os1", result.images.get(0).getOs());
Assert.assertEquals("architecture2", result.images.get(1).getArchitecture());
Assert.assertEquals("os2", result.images.get(1).getOs());
Assert.assertNull(result.registryClient);
}
Aggregations