Search in sources :

Example 1 with ReferenceLayer

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;
}
Also used : LayerCountMismatchException(com.google.cloud.tools.jib.image.LayerCountMismatchException) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) ArrayList(java.util.ArrayList) Image(com.google.cloud.tools.jib.image.Image) ReferenceNoDiffIdLayer(com.google.cloud.tools.jib.image.ReferenceNoDiffIdLayer) Layer(com.google.cloud.tools.jib.image.Layer) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) DigestOnlyLayer(com.google.cloud.tools.jib.image.DigestOnlyLayer) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) ReferenceNoDiffIdLayer(com.google.cloud.tools.jib.image.ReferenceNoDiffIdLayer)

Example 2 with ReferenceLayer

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);
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Image(com.google.cloud.tools.jib.image.Image) Layer(com.google.cloud.tools.jib.image.Layer) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) Before(org.junit.Before)

Example 3 with ReferenceLayer

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")));
    }
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) ImageLayers(com.google.cloud.tools.jib.image.ImageLayers) Test(org.junit.Test)

Aggregations

BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)3 ReferenceLayer (com.google.cloud.tools.jib.image.ReferenceLayer)3 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)2 Image (com.google.cloud.tools.jib.image.Image)2 Layer (com.google.cloud.tools.jib.image.Layer)2 DigestOnlyLayer (com.google.cloud.tools.jib.image.DigestOnlyLayer)1 ImageLayers (com.google.cloud.tools.jib.image.ImageLayers)1 LayerCountMismatchException (com.google.cloud.tools.jib.image.LayerCountMismatchException)1 ReferenceNoDiffIdLayer (com.google.cloud.tools.jib.image.ReferenceNoDiffIdLayer)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1