use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.
the class CacheStorageWriter method verifyImageMetadata.
private static void verifyImageMetadata(ImageMetadataTemplate metadata) {
Predicate<ManifestAndConfigTemplate> isManifestNull = pair -> pair.getManifest() == null;
Predicate<ManifestAndConfigTemplate> isConfigNull = pair -> pair.getConfig() == null;
Predicate<ManifestAndConfigTemplate> isDigestNull = pair -> pair.getManifestDigest() == null;
List<ManifestAndConfigTemplate> manifestsAndConfigs = metadata.getManifestsAndConfigs();
Preconditions.checkArgument(!manifestsAndConfigs.isEmpty(), "no manifests given");
Preconditions.checkArgument(manifestsAndConfigs.stream().noneMatch(isManifestNull), "null manifest(s)");
Preconditions.checkArgument(metadata.getManifestList() != null || manifestsAndConfigs.size() == 1, "manifest list missing while multiple manifests given");
ManifestTemplate firstManifest = manifestsAndConfigs.get(0).getManifest();
if (firstManifest instanceof V21ManifestTemplate) {
Preconditions.checkArgument(metadata.getManifestList() == null, "manifest list given for schema 1");
Preconditions.checkArgument(isConfigNull.test(manifestsAndConfigs.get(0)), "container config given for schema 1");
} else if (firstManifest instanceof BuildableManifestTemplate) {
Preconditions.checkArgument(manifestsAndConfigs.stream().noneMatch(isConfigNull), "null container config(s)");
if (metadata.getManifestList() != null) {
Preconditions.checkArgument(manifestsAndConfigs.stream().noneMatch(isDigestNull), "null manifest digest(s)");
}
} else {
throw new IllegalArgumentException("Unknown manifest type: " + firstManifest);
}
}
use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.
the class PullBaseImageStepTest method testGetCachedBaseImages_v21ManifestCached.
@Test
public void testGetCachedBaseImages_v21ManifestCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException, DigestException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
DescriptorDigest layerDigest = DescriptorDigest.fromHash("1111111111111111111111111111111111111111111111111111111111111111");
V21ManifestTemplate v21Manifest = Mockito.mock(V21ManifestTemplate.class);
Mockito.when(v21Manifest.getLayerDigests()).thenReturn(Arrays.asList(layerDigest));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(new ManifestAndConfigTemplate(v21Manifest, null)));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(1, images.size());
Assert.assertEquals(1, images.get(0).getLayers().size());
Assert.assertEquals("1111111111111111111111111111111111111111111111111111111111111111", images.get(0).getLayers().get(0).getBlobDescriptor().getDigest().getHash());
}
use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.
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.image.json.ImageMetadataTemplate in project jib by google.
the class CacheStorageReaderTest method testVerifyImageMetadata_validV22.
@Test
public void testVerifyImageMetadata_validV22() throws CacheCorruptedException {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate());
ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
// should pass without CacheCorruptedException
}
use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.
the class CacheStorageReaderTest method testRetrieveMetadata_ociSingleManifest.
@Test
public void testRetrieveMetadata_ociSingleManifest() throws IOException, URISyntaxException, CacheCorruptedException {
setupCachedMetadataOci(cacheDirectory);
ImageMetadataTemplate metadata = cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
Assert.assertNull(metadata.getManifestList());
Assert.assertEquals(1, metadata.getManifestsAndConfigs().size());
OciManifestTemplate manifestTemplate = (OciManifestTemplate) metadata.getManifestsAndConfigs().get(0).getManifest();
Assert.assertEquals(2, manifestTemplate.getSchemaVersion());
Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifestTemplate.getContainerConfiguration().getDigest().getHash());
}
Aggregations