use of com.google.cloud.tools.jib.image.ReferenceLayer in project jib by google.
the class JsonToImageTranslator method toImage.
/**
* Translates {@link BuildableManifestTemplate} to {@link Image}. Uses the corresponding {@link
* ContainerConfigurationTemplate} to get the layer diff IDs.
*/
public static Image toImage(BuildableManifestTemplate manifestTemplate, ContainerConfigurationTemplate containerConfigurationTemplate) throws LayerCountMismatchException, LayerPropertyNotFoundException {
Image image = new Image();
List<ReferenceNoDiffIdLayer> layers = new ArrayList<>();
for (BuildableManifestTemplate.ContentDescriptorTemplate layerObjectTemplate : manifestTemplate.getLayers()) {
if (layerObjectTemplate.getDigest() == null) {
throw new IllegalArgumentException("All layers in the manifest template must have digest set");
}
layers.add(new ReferenceNoDiffIdLayer(new BlobDescriptor(layerObjectTemplate.getSize(), layerObjectTemplate.getDigest())));
}
List<DescriptorDigest> diffIds = containerConfigurationTemplate.getDiffIds();
if (layers.size() != diffIds.size()) {
throw new LayerCountMismatchException("Mismatch between image manifest and container configuration");
}
for (int layerIndex = 0; layerIndex < layers.size(); layerIndex++) {
ReferenceNoDiffIdLayer noDiffIdLayer = layers.get(layerIndex);
DescriptorDigest diffId = diffIds.get(layerIndex);
Layer layer = new ReferenceLayer(noDiffIdLayer.getBlobDescriptor(), diffId);
image.addLayer(layer);
}
if (containerConfigurationTemplate.getContainerEntrypoint() == null) {
throw new IllegalArgumentException("containerConfigurationTemplate must have an entrypoint");
}
image.setEntrypoint(containerConfigurationTemplate.getContainerEntrypoint());
for (String environmentVariable : containerConfigurationTemplate.getContainerEnvironment()) {
image.addEnvironmentVariableDefinition(environmentVariable);
}
return image;
}
use of com.google.cloud.tools.jib.image.ReferenceLayer in project jib by google.
the class ImageToJsonTranslatorTest method setUp.
@Before
public void setUp() throws DigestException, LayerPropertyNotFoundException {
Image testImage = new Image();
testImage.setEnvironmentVariable("VAR1", "VAL1");
testImage.setEnvironmentVariable("VAR2", "VAL2");
testImage.setEntrypoint(Arrays.asList("some", "entrypoint", "command"));
DescriptorDigest fakeDigest = DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad");
Layer fakeLayer = new ReferenceLayer(new BlobDescriptor(1000, fakeDigest), fakeDigest);
testImage.addLayer(fakeLayer);
imageToJsonTranslator = new ImageToJsonTranslator(testImage);
}
use of com.google.cloud.tools.jib.image.ReferenceLayer in project jib by google.
the class CacheReaderTest method testAreBaseImageLayersCached.
@Test
public void testAreBaseImageLayersCached() throws DigestException, LayerPropertyNotFoundException, CacheMetadataCorruptedException, IOException {
ImageLayers<ReferenceLayer> layers = new ImageLayers<>();
layers.add(new ReferenceLayer(new BlobDescriptor(1000, DescriptorDigest.fromDigest("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")), DescriptorDigest.fromDigest("sha256:b56ae66c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a4647"))).add(new ReferenceLayer(new BlobDescriptor(1001, DescriptorDigest.fromDigest("sha256:6f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")), DescriptorDigest.fromDigest("sha256:b56ae66c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a4647"))).add(new ReferenceLayer(new BlobDescriptor(2000, DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad")), DescriptorDigest.fromDigest("sha256:a3f3e99c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a8372")));
try (Cache cache = Cache.init(testCacheFolder)) {
CacheReader cacheReader = new CacheReader(cache);
Assert.assertNotNull(cacheReader.getLayer(DescriptorDigest.fromDigest("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")));
Assert.assertNull(cacheReader.getLayer(DescriptorDigest.fromDigest("sha256:6f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")));
Assert.assertNotNull(cacheReader.getLayer(DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad")));
}
}
Aggregations