Search in sources :

Example 1 with ImageLayers

use of com.google.cloud.tools.jib.image.ImageLayers in project jib by google.

the class CacheReaderTest method testAreBaseImageLayersCached.

@Test
public void testAreBaseImageLayersCached() throws DigestException, LayerPropertyNotFoundException, CacheMetadataCorruptedException, IOException {
    ImageLayers<ReferenceLayer> layers = new ImageLayers<>();
    layers.add(new ReferenceLayer(new BlobDescriptor(1000, DescriptorDigest.fromDigest("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")), DescriptorDigest.fromDigest("sha256:b56ae66c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a4647"))).add(new ReferenceLayer(new BlobDescriptor(1001, DescriptorDigest.fromDigest("sha256:6f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")), DescriptorDigest.fromDigest("sha256:b56ae66c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a4647"))).add(new ReferenceLayer(new BlobDescriptor(2000, DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad")), DescriptorDigest.fromDigest("sha256:a3f3e99c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a8372")));
    try (Cache cache = Cache.init(testCacheFolder)) {
        CacheReader cacheReader = new CacheReader(cache);
        Assert.assertNotNull(cacheReader.getLayer(DescriptorDigest.fromDigest("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")));
        Assert.assertNull(cacheReader.getLayer(DescriptorDigest.fromDigest("sha256:6f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")));
        Assert.assertNotNull(cacheReader.getLayer(DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad")));
    }
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) ImageLayers(com.google.cloud.tools.jib.image.ImageLayers) Test(org.junit.Test)

Example 2 with ImageLayers

use of com.google.cloud.tools.jib.image.ImageLayers in project jib by google.

the class BuildAndCacheApplicationLayersStepTest method testRun.

@Test
public void testRun() throws LayerPropertyNotFoundException, IOException, CacheMetadataCorruptedException, URISyntaxException, ExecutionException, InterruptedException {
    Mockito.when(mockBuildConfiguration.getBuildLogger()).thenReturn(new TestBuildLogger());
    TestSourceFilesConfiguration testSourceFilesConfiguration = new TestSourceFilesConfiguration();
    Path temporaryCacheDirectory = temporaryFolder.newFolder().toPath();
    ImageLayers<CachedLayer> applicationLayers = new ImageLayers<>();
    try (Cache cache = Cache.init(temporaryCacheDirectory)) {
        BuildAndCacheApplicationLayersStep buildAndCacheApplicationLayersStep = new BuildAndCacheApplicationLayersStep(mockBuildConfiguration, testSourceFilesConfiguration, cache, MoreExecutors.newDirectExecutorService());
        for (ListenableFuture<CachedLayer> applicationLayerFuture : buildAndCacheApplicationLayersStep.call()) {
            applicationLayers.add(applicationLayerFuture.get());
        }
        Assert.assertEquals(3, applicationLayers.size());
    }
    // Re-initialize cache with the updated metadata.
    Cache cache = Cache.init(temporaryCacheDirectory);
    // Verifies that the cached layers are up-to-date.
    CacheReader cacheReader = new CacheReader(cache);
    Assert.assertEquals(applicationLayers.get(0).getBlobDescriptor(), cacheReader.getUpToDateLayerBySourceFiles(testSourceFilesConfiguration.getDependenciesFiles()).getBlobDescriptor());
    Assert.assertEquals(applicationLayers.get(1).getBlobDescriptor(), cacheReader.getUpToDateLayerBySourceFiles(testSourceFilesConfiguration.getResourcesFiles()).getBlobDescriptor());
    Assert.assertEquals(applicationLayers.get(2).getBlobDescriptor(), cacheReader.getUpToDateLayerBySourceFiles(testSourceFilesConfiguration.getClassesFiles()).getBlobDescriptor());
    // Verifies that the cache reader gets the same layers as the newest application layers.
    Assert.assertEquals(applicationLayers.get(0).getContentFile(), cacheReader.getLayerFile(testSourceFilesConfiguration.getDependenciesFiles()));
    Assert.assertEquals(applicationLayers.get(1).getContentFile(), cacheReader.getLayerFile(testSourceFilesConfiguration.getResourcesFiles()));
    Assert.assertEquals(applicationLayers.get(2).getContentFile(), cacheReader.getLayerFile(testSourceFilesConfiguration.getClassesFiles()));
}
Also used : Path(java.nio.file.Path) ImageLayers(com.google.cloud.tools.jib.image.ImageLayers) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) CacheReader(com.google.cloud.tools.jib.cache.CacheReader) Cache(com.google.cloud.tools.jib.cache.Cache) Test(org.junit.Test)

Aggregations

ImageLayers (com.google.cloud.tools.jib.image.ImageLayers)2 Test (org.junit.Test)2 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)1 Cache (com.google.cloud.tools.jib.cache.Cache)1 CacheReader (com.google.cloud.tools.jib.cache.CacheReader)1 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)1 ReferenceLayer (com.google.cloud.tools.jib.image.ReferenceLayer)1 Path (java.nio.file.Path)1