Search in sources :

Example 21 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

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)

Example 22 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class ManifestPullerTest method testHandleResponse_v22ManifestListFromParentType.

@Test
public void testHandleResponse_v22ManifestListFromParentType() throws URISyntaxException, IOException, UnknownManifestFormatException {
    Path v22ManifestListFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
    InputStream v22ManifestList = new ByteArrayInputStream(Files.readAllBytes(v22ManifestListFile));
    DescriptorDigest expectedDigest = Digests.computeDigest(v22ManifestList).getDigest();
    v22ManifestList.reset();
    Mockito.when(mockResponse.getBody()).thenReturn(v22ManifestList);
    ManifestAndDigest<?> manifestAndDigest = new ManifestPuller<>(fakeRegistryEndpointRequestProperties, "test-image-tag", ManifestTemplate.class).handleResponse(mockResponse);
    ManifestTemplate manifestTemplate = manifestAndDigest.getManifest();
    MatcherAssert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
    Assert.assertTrue(((V22ManifestListTemplate) manifestTemplate).getManifests().size() > 0);
    Assert.assertEquals(expectedDigest, manifestAndDigest.getDigest());
}
Also used : Path(java.nio.file.Path) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) OciManifestTemplate(com.google.cloud.tools.jib.image.json.OciManifestTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) Test(org.junit.Test)

Example 23 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class ManifestPusherTest method testHandleResponse_noDigest.

@Test
public void testHandleResponse_noDigest() throws IOException {
    DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
    Mockito.when(mockResponse.getHeader("Docker-Content-Digest")).thenReturn(Collections.emptyList());
    Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
    Mockito.verify(mockEventHandlers).dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received none"));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 24 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class ManifestPusherTest method testHandleResponse_multipleDigests.

@Test
public void testHandleResponse_multipleDigests() throws IOException {
    DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
    Mockito.when(mockResponse.getHeader("Docker-Content-Digest")).thenReturn(Arrays.asList("too", "many"));
    Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
    Mockito.verify(mockEventHandlers).dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received: too, many"));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 25 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class ManifestPusherTest method testHandleResponse_invalidDigest.

@Test
public void testHandleResponse_invalidDigest() throws IOException {
    DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
    Mockito.when(mockResponse.getHeader("Docker-Content-Digest")).thenReturn(Collections.singletonList("not valid"));
    Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
    Mockito.verify(mockEventHandlers).dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received: not valid"));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

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