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);
}
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;
}
});
}
Aggregations