use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class BlobTest method verifyBlobWriteTo.
/**
* Checks that the {@link Blob} streams the expected string.
*/
private void verifyBlobWriteTo(String expected, Blob blob) throws IOException {
OutputStream outputStream = new ByteArrayOutputStream();
BlobDescriptor blobDescriptor = blob.writeTo(outputStream);
String output = outputStream.toString();
Assert.assertEquals(expected, output);
byte[] expectedBytes = expected.getBytes(StandardCharsets.UTF_8);
Assert.assertEquals(expectedBytes.length, blobDescriptor.getSize());
DescriptorDigest expectedDigest = Digests.computeDigest(new ByteArrayInputStream(expectedBytes)).getDigest();
Assert.assertEquals(expectedDigest, blobDescriptor.getDigest());
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class AbstractManifestPuller method handleResponse.
/**
* Parses the response body into a {@link ManifestAndDigest}.
*/
@Override
public R handleResponse(Response response) throws IOException, UnknownManifestFormatException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DescriptorDigest digest = Digests.computeDigest(response.getBody(), byteArrayOutputStream).getDigest();
String jsonString = byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
T manifestTemplate = getManifestTemplateFromJson(jsonString);
return computeReturn(new ManifestAndDigest<>(manifestTemplate, digest));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class PullBaseImageStepTest method setUpWorkingRegistryClientFactory.
private static RegistryClient.Factory setUpWorkingRegistryClientFactory() throws IOException, RegistryException {
DescriptorDigest digest = Mockito.mock(DescriptorDigest.class);
V22ManifestTemplate manifest = new V22ManifestTemplate();
manifest.setContainerConfiguration(1234, digest);
RegistryClient.Factory clientFactory = Mockito.mock(RegistryClient.Factory.class);
RegistryClient client = Mockito.mock(RegistryClient.class);
Mockito.when(clientFactory.newRegistryClient()).thenReturn(client);
Mockito.when(client.pullManifest(Mockito.any())).thenReturn(new ManifestAndDigest<>(manifest, digest));
// mocking pulling container config json
Mockito.when(client.pullBlob(Mockito.any(), Mockito.any(), Mockito.any())).then(invocation -> {
Consumer<Long> blobSizeListener = invocation.getArgument(1);
blobSizeListener.accept(1L);
return Blobs.from("{}");
});
return clientFactory;
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class CacheStorageFilesTest method testGetLayerFilename.
@Test
public void testGetLayerFilename() throws DigestException {
DescriptorDigest diffId = DescriptorDigest.fromHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
Assert.assertEquals("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", TEST_CACHE_STORAGE_FILES.getLayerFilename(diffId));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class ImageToJsonTranslatorTest method setUp.
private void setUp(Class<? extends BuildableManifestTemplate> imageFormat) throws DigestException, LayerPropertyNotFoundException {
Image.Builder testImageBuilder = Image.builder(imageFormat).setCreated(Instant.ofEpochSecond(20)).setArchitecture("wasm").setOs("js").addEnvironmentVariable("VAR1", "VAL1").addEnvironmentVariable("VAR2", "VAL2").setEntrypoint(Arrays.asList("some", "entrypoint", "command")).setProgramArguments(Arrays.asList("arg1", "arg2")).setHealthCheck(DockerHealthCheck.fromCommand(ImmutableList.of("CMD-SHELL", "/checkhealth")).setInterval(Duration.ofSeconds(3)).setTimeout(Duration.ofSeconds(1)).setStartPeriod(Duration.ofSeconds(2)).setRetries(3).build()).addExposedPorts(ImmutableSet.of(Port.tcp(1000), Port.tcp(2000), Port.udp(3000))).addVolumes(ImmutableSet.of(AbsoluteUnixPath.get("/var/job-result-data"), AbsoluteUnixPath.get("/var/log/my-app-logs"))).addLabels(ImmutableMap.of("key1", "value1", "key2", "value2")).setWorkingDirectory("/some/workspace").setUser("tomcat");
DescriptorDigest fakeDigest = DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad");
testImageBuilder.addLayer(new Layer() {
@Override
public Blob getBlob() throws LayerPropertyNotFoundException {
return Blobs.from("ignored");
}
@Override
public BlobDescriptor getBlobDescriptor() throws LayerPropertyNotFoundException {
return new BlobDescriptor(1000, fakeDigest);
}
@Override
public DescriptorDigest getDiffId() throws LayerPropertyNotFoundException {
return fakeDigest;
}
});
testImageBuilder.addHistory(HistoryEntry.builder().setCreationTimestamp(Instant.EPOCH).setAuthor("Bazel").setCreatedBy("bazel build ...").setEmptyLayer(true).build());
testImageBuilder.addHistory(HistoryEntry.builder().setCreationTimestamp(Instant.ofEpochSecond(20)).setAuthor("Jib").setCreatedBy("jib").build());
imageToJsonTranslator = new ImageToJsonTranslator(testImageBuilder.build());
}
Aggregations