use of com.google.cloud.tools.jib.image.DescriptorDigest 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.DescriptorDigest in project jib by google.
the class BlobCheckerIntegrationTest method testCheck_exists.
@Test
public void testCheck_exists() throws IOException, RegistryException {
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V22ManifestTemplate.class);
DescriptorDigest blobDigest = manifestTemplate.getLayers().get(0).getDigest();
Assert.assertEquals(blobDigest, registryClient.checkBlob(blobDigest).getDigest());
}
use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.
the class BlobPusherIntegrationTest method testPush.
@Test
public void testPush() throws DigestException, IOException, RegistryException {
Blob testBlob = Blobs.from("crepecake");
// Known digest for 'crepecake'
DescriptorDigest testBlobDigest = DescriptorDigest.fromHash("52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c");
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "testimage");
Assert.assertFalse(registryClient.pushBlob(testBlobDigest, testBlob));
}
use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.
the class ManifestPusherIntegrationTest method testPush.
/**
* Tests manifest pushing. This test is a comprehensive test of push and pull.
*/
@Test
public void testPush() throws DigestException, IOException, RegistryException {
Blob testLayerBlob = Blobs.from("crepecake");
// Known digest for 'crepecake'
DescriptorDigest testLayerBlobDigest = DescriptorDigest.fromHash("52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c");
Blob testContainerConfigurationBlob = Blobs.from("12345");
DescriptorDigest testContainerConfigurationBlobDigest = DescriptorDigest.fromHash("5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5");
// Creates a valid image manifest.
V22ManifestTemplate expectedManifestTemplate = new V22ManifestTemplate();
expectedManifestTemplate.addLayer(9, testLayerBlobDigest);
expectedManifestTemplate.setContainerConfiguration(5, testContainerConfigurationBlobDigest);
// Pushes the BLOBs.
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "testimage");
Assert.assertFalse(registryClient.pushBlob(testLayerBlobDigest, testLayerBlob));
Assert.assertFalse(registryClient.pushBlob(testContainerConfigurationBlobDigest, testContainerConfigurationBlob));
// Pushes the manifest.
registryClient.pushManifest(expectedManifestTemplate, "latest");
// Pulls the manifest.
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V22ManifestTemplate.class);
Assert.assertEquals(1, manifestTemplate.getLayers().size());
Assert.assertEquals(testLayerBlobDigest, manifestTemplate.getLayers().get(0).getDigest());
Assert.assertEquals(testContainerConfigurationBlobDigest, manifestTemplate.getContainerConfiguration().getDigest());
}
use of com.google.cloud.tools.jib.image.DescriptorDigest 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);
}
Aggregations