Search in sources :

Example 1 with LayerBuilder

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

the class CacheWriterTest method testWriteLayer_unwritten.

@Test
public void testWriteLayer_unwritten() throws IOException, LayerPropertyNotFoundException {
    ExpectedLayer expectedLayer = getExpectedLayer();
    // Writes resourceBlob as a layer to the cache.
    CacheWriter cacheWriter = new CacheWriter(testCache);
    UnwrittenLayer unwrittenLayer = new UnwrittenLayer(Blobs.from(resourceBlob));
    List<Path> fakeSourceFiles = Collections.singletonList(Paths.get("some", "source", "file"));
    LayerBuilder mockLayerBuilder = Mockito.mock(LayerBuilder.class);
    Mockito.when(mockLayerBuilder.build()).thenReturn(unwrittenLayer);
    Mockito.when(mockLayerBuilder.getSourceFiles()).thenReturn(fakeSourceFiles);
    CachedLayer cachedLayer = cacheWriter.writeLayer(mockLayerBuilder);
    CachedLayerWithMetadata layerInMetadata = testCache.getMetadata().getLayers().get(0);
    Assert.assertNotNull(layerInMetadata.getMetadata());
    Assert.assertEquals(Collections.singletonList(Paths.get("some", "source", "file").toString()), layerInMetadata.getMetadata().getSourceFiles());
    verifyCachedLayerIsExpected(expectedLayer, cachedLayer);
}
Also used : Path(java.nio.file.Path) LayerBuilder(com.google.cloud.tools.jib.image.LayerBuilder) UnwrittenLayer(com.google.cloud.tools.jib.image.UnwrittenLayer) Test(org.junit.Test)

Example 2 with LayerBuilder

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

the class BuildAndCacheApplicationLayersStep method buildAndCacheLayerAsync.

private ListenableFuture<CachedLayer> buildAndCacheLayerAsync(String layerType, List<Path> sourceFiles, String extractionPath) {
    String description = "Building " + layerType + " layer";
    return listeningExecutorService.submit(() -> {
        try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), description)) {
            // Don't build the layer if it exists already.
            CachedLayer cachedLayer = new CacheReader(cache).getUpToDateLayerBySourceFiles(sourceFiles);
            if (cachedLayer != null) {
                return cachedLayer;
            }
            LayerBuilder layerBuilder = new LayerBuilder(sourceFiles, extractionPath, buildConfiguration.getEnableReproducibleBuilds());
            cachedLayer = new CacheWriter(cache).writeLayer(layerBuilder);
            // TODO: Remove
            buildConfiguration.getBuildLogger().debug(description + " built " + cachedLayer.getBlobDescriptor().getDigest());
            return cachedLayer;
        }
    });
}
Also used : Timer(com.google.cloud.tools.jib.Timer) LayerBuilder(com.google.cloud.tools.jib.image.LayerBuilder) CacheWriter(com.google.cloud.tools.jib.cache.CacheWriter) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) CacheReader(com.google.cloud.tools.jib.cache.CacheReader)

Aggregations

LayerBuilder (com.google.cloud.tools.jib.image.LayerBuilder)2 Timer (com.google.cloud.tools.jib.Timer)1 CacheReader (com.google.cloud.tools.jib.cache.CacheReader)1 CacheWriter (com.google.cloud.tools.jib.cache.CacheWriter)1 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)1 UnwrittenLayer (com.google.cloud.tools.jib.image.UnwrittenLayer)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1