use of com.google.cloud.tools.jib.json.JsonTemplate in project jib by google.
the class ImageToJsonTranslatorTest method testGetManifest.
/**
* Tests translation of image to {@link BuildableManifestTemplate}.
*/
private <T extends BuildableManifestTemplate> void testGetManifest(Class<T> manifestTemplateClass, String translatedJsonFilename) throws URISyntaxException, IOException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource(translatedJsonFilename).toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
// Translates the image to the manifest and writes the JSON string.
JsonTemplate containerConfiguration = imageToJsonTranslator.getContainerConfiguration();
BlobDescriptor blobDescriptor = Digests.computeDigest(containerConfiguration);
T manifestTemplate = imageToJsonTranslator.getManifestTemplate(manifestTemplateClass, blobDescriptor);
Assert.assertEquals(expectedJson, JsonTemplateMapper.toUtf8String(manifestTemplate));
}
use of com.google.cloud.tools.jib.json.JsonTemplate in project jib by google.
the class ImageTarball method dockerWriteTo.
private void dockerWriteTo(OutputStream out) throws IOException {
TarStreamBuilder tarStreamBuilder = new TarStreamBuilder();
DockerManifestEntryTemplate manifestTemplate = new DockerManifestEntryTemplate();
// Adds all the layers to the tarball and manifest.
for (Layer layer : image.getLayers()) {
String layerName = layer.getBlobDescriptor().getDigest().getHash() + LAYER_FILE_EXTENSION;
tarStreamBuilder.addBlobEntry(layer.getBlob(), layer.getBlobDescriptor().getSize(), layerName, TAR_ENTRY_MODIFICATION_TIME);
manifestTemplate.addLayerFile(layerName);
}
// Adds the container configuration to the tarball.
JsonTemplate containerConfiguration = new ImageToJsonTranslator(image).getContainerConfiguration();
tarStreamBuilder.addByteEntry(JsonTemplateMapper.toByteArray(containerConfiguration), CONTAINER_CONFIGURATION_JSON_FILE_NAME, TAR_ENTRY_MODIFICATION_TIME);
// Adds the manifest to tarball.
for (String tag : allTargetImageTags) {
manifestTemplate.addRepoTag(imageReference.withQualifier(tag).toStringWithQualifier());
}
tarStreamBuilder.addByteEntry(JsonTemplateMapper.toByteArray(Collections.singletonList(manifestTemplate)), MANIFEST_JSON_FILE_NAME, TAR_ENTRY_MODIFICATION_TIME);
tarStreamBuilder.writeAsTarArchiveTo(out);
}
use of com.google.cloud.tools.jib.json.JsonTemplate in project jib by GoogleContainerTools.
the class ImageToJsonTranslatorTest method testGetContainerConfiguration.
@Test
public void testGetContainerConfiguration() throws IOException, URISyntaxException, DigestException {
setUp(V22ManifestTemplate.class);
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/containerconfig.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
// Translates the image to the container configuration and writes the JSON string.
JsonTemplate containerConfiguration = imageToJsonTranslator.getContainerConfiguration();
Assert.assertEquals(expectedJson, JsonTemplateMapper.toUtf8String(containerConfiguration));
}
Aggregations