Search in sources :

Example 6 with Blob

use of com.google.cloud.tools.jib.blob.Blob in project jib by google.

the class TarStreamBuilderTest method testToBlob.

@Test
public void testToBlob() throws IOException {
    Blob blob = testTarStreamBuilder.toBlob();
    // Writes the BLOB and captures the output.
    ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream();
    blob.writeTo(tarByteOutputStream);
    // Rearrange the output into input for verification.
    ByteArrayInputStream tarByteInputStream = new ByteArrayInputStream(tarByteOutputStream.toByteArray());
    TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarByteInputStream);
    verifyTarArchive(tarArchiveInputStream);
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Blob(com.google.cloud.tools.jib.blob.Blob) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 7 with Blob

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

Example 8 with Blob

use of com.google.cloud.tools.jib.blob.Blob 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());
}
Also used : Blob(com.google.cloud.tools.jib.blob.Blob) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Test(org.junit.Test)

Example 9 with Blob

use of com.google.cloud.tools.jib.blob.Blob in project jib by google.

the class ResponseTest method testGetContent.

@Test
public void testGetContent() throws IOException {
    String expectedResponse = "crepecake\nis\ngood!";
    ByteArrayInputStream responseInputStream = new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8));
    Mockito.when(httpResponseMock.getContent()).thenReturn(responseInputStream);
    Response response = new Response(httpResponseMock);
    Blob responseStream = response.getBody();
    ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream();
    responseStream.writeTo(responseOutputStream);
    Assert.assertEquals(expectedResponse, new String(responseOutputStream.toByteArray(), StandardCharsets.UTF_8));
}
Also used : HttpResponse(com.google.api.client.http.HttpResponse) Blob(com.google.cloud.tools.jib.blob.Blob) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 10 with Blob

use of com.google.cloud.tools.jib.blob.Blob in project jib by google.

the class LayerBuilderTest method testToBlob_reproducibility.

@Test
public void testToBlob_reproducibility() throws IOException {
    Path testRoot = temporaryFolder.getRoot().toPath();
    Path root1 = Files.createDirectories(testRoot.resolve("files1"));
    Path root2 = Files.createDirectories(testRoot.resolve("files2"));
    String extractionPath = "/somewhere";
    // TODO: Currently this test only covers variation in order and modified time, even though
    // TODO: the code is designed to clean up userid/groupid, this test does not check that yet.
    String contentA = "abcabc";
    Path fileA1 = createFile(root1, "fileA", contentA, 10000);
    Path fileA2 = createFile(root2, "fileA", contentA, 20000);
    String contentB = "yumyum";
    Path fileB1 = createFile(root1, "fileB", contentB, 10000);
    Path fileB2 = createFile(root2, "fileB", contentB, 20000);
    // check if modified times are off
    Assert.assertNotEquals(Files.getLastModifiedTime(fileA1), Files.getLastModifiedTime(fileA2));
    Assert.assertNotEquals(Files.getLastModifiedTime(fileB1), Files.getLastModifiedTime(fileB2));
    // create layers of exact same content but ordered differently and with different timestamps
    Blob layer = new LayerBuilder(Arrays.asList(fileA1, fileB1), extractionPath, true).build().getBlob();
    Blob reproduced = new LayerBuilder(Arrays.asList(fileB2, fileA2), extractionPath, true).build().getBlob();
    // this is a control layer that is the same as 'layerReproduced' without reproducibility on
    Blob notReproduced = new LayerBuilder(Arrays.asList(fileB2, fileA2), extractionPath, false).build().getBlob();
    byte[] layerContent = Blobs.writeToByteArray(layer);
    byte[] reproducedLayerContent = Blobs.writeToByteArray(reproduced);
    byte[] notReproducedLayerContent = Blobs.writeToByteArray(notReproduced);
    Assert.assertThat(layerContent, CoreMatchers.is(reproducedLayerContent));
    Assert.assertThat(layerContent, CoreMatchers.not(notReproducedLayerContent));
}
Also used : Path(java.nio.file.Path) Blob(com.google.cloud.tools.jib.blob.Blob) Test(org.junit.Test)

Aggregations

Blob (com.google.cloud.tools.jib.blob.Blob)13 Test (org.junit.Test)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Path (java.nio.file.Path)4 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)3 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)2 Response (com.google.cloud.tools.jib.http.Response)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)2 HttpResponse (com.google.api.client.http.HttpResponse)1 Timer (com.google.cloud.tools.jib.Timer)1 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)1 Image (com.google.cloud.tools.jib.image.Image)1 ImageToJsonTranslator (com.google.cloud.tools.jib.image.json.ImageToJsonTranslator)1 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)1 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1