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);
}
}
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);
}
Aggregations