Search in sources :

Example 51 with DescriptorDigest

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 52 with DescriptorDigest

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));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 53 with DescriptorDigest

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;
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient)

Example 54 with DescriptorDigest

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));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 55 with DescriptorDigest

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());
}
Also used : Blob(com.google.cloud.tools.jib.blob.Blob) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) LayerPropertyNotFoundException(com.google.cloud.tools.jib.image.LayerPropertyNotFoundException) Image(com.google.cloud.tools.jib.image.Image) Layer(com.google.cloud.tools.jib.image.Layer)

Aggregations

DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)112 Test (org.junit.Test)68 Path (java.nio.file.Path)28 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)24 Blob (com.google.cloud.tools.jib.blob.Blob)18 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)16 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)16 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)16 Image (com.google.cloud.tools.jib.image.Image)14 ByteArrayInputStream (java.io.ByteArrayInputStream)14 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 RegistryException (com.google.cloud.tools.jib.api.RegistryException)12 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)12 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)10 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)10 DigestException (java.security.DigestException)10 FailoverHttpClient (com.google.cloud.tools.jib.http.FailoverHttpClient)8 Layer (com.google.cloud.tools.jib.image.Layer)8 OutputStream (java.io.OutputStream)8