Search in sources :

Example 91 with DescriptorDigest

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

the class CacheStorageWriterTest method verifyCachedLayer.

private void verifyCachedLayer(CachedLayer cachedLayer, Blob uncompressedLayerBlob) throws IOException {
    BlobDescriptor layerBlobDescriptor = getDigest(compress(uncompressedLayerBlob));
    DescriptorDigest layerDiffId = getDigest(uncompressedLayerBlob).getDigest();
    // Verifies cachedLayer is correct.
    Assert.assertEquals(layerBlobDescriptor.getDigest(), cachedLayer.getDigest());
    Assert.assertEquals(layerDiffId, cachedLayer.getDiffId());
    Assert.assertEquals(layerBlobDescriptor.getSize(), cachedLayer.getSize());
    Assert.assertArrayEquals(Blobs.writeToByteArray(uncompressedLayerBlob), Blobs.writeToByteArray(decompress(cachedLayer.getBlob())));
    // Verifies that the files are present.
    Assert.assertTrue(Files.exists(cacheStorageFiles.getLayerFile(cachedLayer.getDigest(), cachedLayer.getDiffId())));
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest)

Example 92 with DescriptorDigest

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

the class CacheStorageWriterTest method testWriteTarLayer.

@Test
public void testWriteTarLayer() throws IOException {
    Blob uncompressedLayerBlob = Blobs.from("uncompressedLayerBlob");
    DescriptorDigest diffId = getDigest(uncompressedLayerBlob).getDigest();
    CachedLayer cachedLayer = cacheStorageWriter.writeTarLayer(diffId, compress(uncompressedLayerBlob));
    BlobDescriptor layerBlobDescriptor = getDigest(compress(uncompressedLayerBlob));
    // Verifies cachedLayer is correct.
    Assert.assertEquals(layerBlobDescriptor.getDigest(), cachedLayer.getDigest());
    Assert.assertEquals(diffId, cachedLayer.getDiffId());
    Assert.assertEquals(layerBlobDescriptor.getSize(), cachedLayer.getSize());
    Assert.assertArrayEquals(Blobs.writeToByteArray(uncompressedLayerBlob), Blobs.writeToByteArray(decompress(cachedLayer.getBlob())));
    // Verifies that the files are present.
    Assert.assertTrue(Files.exists(cacheStorageFiles.getLocalDirectory().resolve(cachedLayer.getDiffId().getHash()).resolve(cachedLayer.getDigest().getHash())));
}
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) Test(org.junit.Test)

Example 93 with DescriptorDigest

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

the class LayerEntriesSelectorTest method testGenerateSelector.

@Test
public void testGenerateSelector() throws IOException {
    DescriptorDigest expectedSelector = Digests.computeJsonDigest(toLayerEntryTemplates(inOrderLayerEntries));
    Assert.assertEquals(expectedSelector, LayerEntriesSelector.generateSelector(outOfOrderLayerEntries));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 94 with DescriptorDigest

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

the class LayerEntriesSelectorTest method testGenerateSelector_sourceModificationTimeChanged.

@Test
public void testGenerateSelector_sourceModificationTimeChanged() throws IOException {
    Path layerFile = temporaryFolder.newFile().toPath();
    Files.setLastModifiedTime(layerFile, FileTime.from(Instant.EPOCH));
    FileEntry layerEntry = defaultLayerEntry(layerFile, AbsoluteUnixPath.get("/extraction/path"));
    DescriptorDigest expectedSelector = LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry));
    // Verify that changing source modification time generates a different selector
    Files.setLastModifiedTime(layerFile, FileTime.from(Instant.ofEpochSecond(1)));
    Assert.assertNotEquals(expectedSelector, LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry)));
    // Verify that changing source modification time back generates same selector
    Files.setLastModifiedTime(layerFile, FileTime.from(Instant.EPOCH));
    Assert.assertEquals(expectedSelector, LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry)));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Test(org.junit.Test)

Example 95 with DescriptorDigest

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

the class CacheStorageFilesTest method testGetLayerFile.

@Test
public void testGetLayerFile() throws DigestException {
    DescriptorDigest layerDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    DescriptorDigest diffId = DescriptorDigest.fromHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
    Assert.assertEquals(Paths.get("cache", "directory", "layers", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), TEST_CACHE_STORAGE_FILES.getLayerFile(layerDigest, diffId));
}
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