Search in sources :

Example 1 with BlobDescriptor

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

the class CacheMetadataTranslatorTest method setUp.

@Before
public void setUp() throws DigestException {
    baseLayerBlobDescriptor = new BlobDescriptor(631, DescriptorDigest.fromDigest("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"));
    baseLayerDiffId = DescriptorDigest.fromDigest("sha256:b56ae66c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a4647");
    classesLayerBlobDescriptor = new BlobDescriptor(223, DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"));
    classesLayerDiffId = DescriptorDigest.fromDigest("sha256:a3f3e99c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a8372");
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) Before(org.junit.Before)

Example 2 with BlobDescriptor

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

the class ImageToJsonTranslatorTest method testGetManifest.

/**
 * Tests translation of image to {@link BuildableManifestTemplate}.
 */
private <T extends BuildableManifestTemplate> void testGetManifest(Class<T> manifestTemplateClass, String translatedJsonFilename) throws URISyntaxException, IOException, LayerPropertyNotFoundException {
    // Loads the expected JSON string.
    Path jsonFile = Paths.get(Resources.getResource(translatedJsonFilename).toURI());
    String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
    // Translates the image to the manifest and writes the JSON string.
    Blob containerConfigurationBlob = imageToJsonTranslator.getContainerConfigurationBlob();
    BlobDescriptor blobDescriptor = containerConfigurationBlob.writeTo(ByteStreams.nullOutputStream());
    T manifestTemplate = imageToJsonTranslator.getManifestTemplate(manifestTemplateClass, blobDescriptor);
    ByteArrayOutputStream jsonStream = new ByteArrayOutputStream();
    JsonTemplateMapper.toBlob(manifestTemplate).writeTo(jsonStream);
    Assert.assertEquals(expectedJson, new String(jsonStream.toByteArray(), StandardCharsets.UTF_8));
}
Also used : Path(java.nio.file.Path) Blob(com.google.cloud.tools.jib.blob.Blob) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with BlobDescriptor

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

the class JsonToImageTranslatorTest method testToImage_buildable.

private <T extends BuildableManifestTemplate> void testToImage_buildable(String jsonFilename, Class<T> manifestTemplateClass) throws IOException, LayerPropertyNotFoundException, LayerCountMismatchException, DigestException, URISyntaxException {
    // Loads the container configuration JSON.
    Path containerConfigurationJsonFile = Paths.get(getClass().getClassLoader().getResource("json/containerconfig.json").toURI());
    ContainerConfigurationTemplate containerConfigurationTemplate = JsonTemplateMapper.readJsonFromFile(containerConfigurationJsonFile, ContainerConfigurationTemplate.class);
    // Loads the manifest JSON.
    Path manifestJsonFile = Paths.get(getClass().getClassLoader().getResource(jsonFilename).toURI());
    T manifestTemplate = JsonTemplateMapper.readJsonFromFile(manifestJsonFile, manifestTemplateClass);
    Image image = JsonToImageTranslator.toImage(manifestTemplate, containerConfigurationTemplate);
    List<Layer> layers = image.getLayers();
    Assert.assertEquals(1, layers.size());
    Assert.assertEquals(new BlobDescriptor(1000000, DescriptorDigest.fromDigest("sha256:4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236")), layers.get(0).getBlobDescriptor());
    Assert.assertEquals(DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"), layers.get(0).getDiffId());
    Assert.assertEquals(Arrays.asList("some", "entrypoint", "command"), image.getEntrypoint());
    Assert.assertEquals(Arrays.asList("VAR1=VAL1", "VAR2=VAL2"), image.getEnvironment());
}
Also used : Path(java.nio.file.Path) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) Image(com.google.cloud.tools.jib.image.Image) Layer(com.google.cloud.tools.jib.image.Layer)

Example 4 with BlobDescriptor

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

the class BlobCheckerTest method testHandleHttpResponseException.

@Test
public void testHandleHttpResponseException() throws IOException, RegistryErrorException {
    HttpResponseException mockHttpResponseException = Mockito.mock(HttpResponseException.class);
    Mockito.when(mockHttpResponseException.getStatusCode()).thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
    ErrorResponseTemplate emptyErrorResponseTemplate = new ErrorResponseTemplate().addError(new ErrorEntryTemplate(ErrorCodes.BLOB_UNKNOWN.name(), "some message"));
    Mockito.when(mockHttpResponseException.getContent()).thenReturn(Blobs.writeToString(JsonTemplateMapper.toBlob(emptyErrorResponseTemplate)));
    BlobDescriptor blobDescriptor = testBlobChecker.handleHttpResponseException(mockHttpResponseException);
    Assert.assertNull(blobDescriptor);
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) HttpResponseException(com.google.api.client.http.HttpResponseException) ErrorResponseTemplate(com.google.cloud.tools.jib.registry.json.ErrorResponseTemplate) ErrorEntryTemplate(com.google.cloud.tools.jib.registry.json.ErrorEntryTemplate) Test(org.junit.Test)

Example 5 with BlobDescriptor

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

the class CacheMetadataTest method mockCachedLayer.

private static CachedLayer mockCachedLayer() {
    CachedLayer mockCachedLayer = Mockito.mock(CachedLayer.class);
    BlobDescriptor mockBlobDescriptor = Mockito.mock(BlobDescriptor.class);
    DescriptorDigest mockDescriptorDigest = Mockito.mock(DescriptorDigest.class);
    Mockito.when(mockCachedLayer.getBlobDescriptor()).thenReturn(mockBlobDescriptor);
    Mockito.when(mockBlobDescriptor.getDigest()).thenReturn(mockDescriptorDigest);
    return mockCachedLayer;
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest)

Aggregations

BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)17 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)6 Path (java.nio.file.Path)5 Image (com.google.cloud.tools.jib.image.Image)4 Test (org.junit.Test)4 Blob (com.google.cloud.tools.jib.blob.Blob)3 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)3 Layer (com.google.cloud.tools.jib.image.Layer)3 ReferenceLayer (com.google.cloud.tools.jib.image.ReferenceLayer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Before (org.junit.Before)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 HttpResponseException (com.google.api.client.http.HttpResponseException)1 Timer (com.google.cloud.tools.jib.Timer)1 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)1 CacheMetadataLayerObjectTemplate (com.google.cloud.tools.jib.cache.json.CacheMetadataLayerObjectTemplate)1 CacheMetadataLayerPropertiesObjectTemplate (com.google.cloud.tools.jib.cache.json.CacheMetadataLayerPropertiesObjectTemplate)1 DigestOnlyLayer (com.google.cloud.tools.jib.image.DigestOnlyLayer)1 ImageLayers (com.google.cloud.tools.jib.image.ImageLayers)1