Search in sources :

Example 6 with Layer

use of com.google.cloud.tools.jib.image.Layer in project jib by google.

the class ImageToJsonTranslator method getManifestTemplate.

/**
 * Gets the manifest as a JSON template. The {@code containerConfigurationBlobDescriptor} must be
 * the [@link BlobDescriptor} obtained by writing out the container configuration {@link Blob}
 * returned from {@link #getContainerConfigurationBlob()}.
 */
public <T extends BuildableManifestTemplate> T getManifestTemplate(Class<T> manifestTemplateClass, BlobDescriptor containerConfigurationBlobDescriptor) throws LayerPropertyNotFoundException {
    try {
        // Set up the JSON template.
        T template = manifestTemplateClass.getDeclaredConstructor().newInstance();
        // Adds the container configuration reference.
        DescriptorDigest containerConfigurationDigest = containerConfigurationBlobDescriptor.getDigest();
        long containerConfigurationSize = containerConfigurationBlobDescriptor.getSize();
        template.setContainerConfiguration(containerConfigurationSize, containerConfigurationDigest);
        // Adds the layers.
        for (Layer layer : image.getLayers()) {
            template.addLayer(layer.getBlobDescriptor().getSize(), layer.getBlobDescriptor().getDigest());
        }
        // Serializes into JSON.
        return template;
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
        throw new IllegalArgumentException(manifestTemplateClass + " cannot be instantiated", ex);
    }
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Layer(com.google.cloud.tools.jib.image.Layer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with Layer

use of com.google.cloud.tools.jib.image.Layer in project jib by google.

the class ImageToJsonTranslator method getContainerConfigurationBlob.

/**
 * Gets the container configuration as a {@link Blob}.
 */
public Blob getContainerConfigurationBlob() throws LayerPropertyNotFoundException {
    // Set up the JSON template.
    ContainerConfigurationTemplate template = new ContainerConfigurationTemplate();
    // Adds the layer diff IDs.
    for (Layer layer : image.getLayers()) {
        template.addLayerDiffId(layer.getDiffId());
    }
    // Adds the environment variables.
    template.setContainerEnvironment(image.getEnvironment());
    // Sets the entrypoint.
    template.setContainerEntrypoint(image.getEntrypoint());
    // Serializes into JSON.
    return JsonTemplateMapper.toBlob(template);
}
Also used : Layer(com.google.cloud.tools.jib.image.Layer)

Aggregations

Layer (com.google.cloud.tools.jib.image.Layer)7 Image (com.google.cloud.tools.jib.image.Image)5 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)4 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)3 ReferenceLayer (com.google.cloud.tools.jib.image.ReferenceLayer)3 DigestOnlyLayer (com.google.cloud.tools.jib.image.DigestOnlyLayer)2 ReferenceNoDiffIdLayer (com.google.cloud.tools.jib.image.ReferenceNoDiffIdLayer)2 Path (java.nio.file.Path)2 LayerCountMismatchException (com.google.cloud.tools.jib.image.LayerCountMismatchException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1