use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class CacheStorageWriterTest method testWriteUncompressed.
@Test
public void testWriteUncompressed() throws IOException {
Blob uncompressedLayerBlob = Blobs.from("uncompressedLayerBlob");
DescriptorDigest layerDigest = getDigest(compress(uncompressedLayerBlob)).getDigest();
DescriptorDigest selector = getDigest(Blobs.from("selector")).getDigest();
CachedLayer cachedLayer = cacheStorageWriter.writeUncompressed(uncompressedLayerBlob, selector);
verifyCachedLayer(cachedLayer, uncompressedLayerBlob);
// Verifies that the files are present.
Path selectorFile = cacheStorageFiles.getSelectorFile(selector);
Assert.assertTrue(Files.exists(selectorFile));
Assert.assertEquals(layerDigest.getHash(), Blobs.writeToString(Blobs.from(selectorFile)));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class LayerEntriesSelectorTest method testGenerateSelector.
@Test
public void testGenerateSelector() throws IOException {
DescriptorDigest expectedSelector = Digests.computeJsonDigest(toLayerEntryTemplates(inOrderLayerEntries));
Assert.assertEquals(expectedSelector, LayerEntriesSelector.generateSelector(outOfOrderLayerEntries));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
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)));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class PushImageStep method makeListForManifestList.
static ImmutableList<PushImageStep> makeListForManifestList(BuildContext buildContext, ProgressEventDispatcher.Factory progressEventDispatcherFactory, RegistryClient registryClient, ManifestTemplate manifestList, boolean manifestListAlreadyExists) throws IOException {
Set<String> tags = buildContext.getAllTargetImageTags();
EventHandlers eventHandlers = buildContext.getEventHandlers();
try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, "Preparing manifest list pushers");
ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("launching manifest list pushers", tags.size())) {
boolean singlePlatform = buildContext.getContainerConfiguration().getPlatforms().size() == 1;
if (singlePlatform) {
// single image; no need to push a manifest list
return ImmutableList.of();
}
if (JibSystemProperties.skipExistingImages() && manifestListAlreadyExists) {
eventHandlers.dispatch(LogEvent.info("Skipping pushing manifest list; already exists."));
return ImmutableList.of();
}
DescriptorDigest manifestListDigest = Digests.computeJsonDigest(manifestList);
return tags.stream().map(tag -> new PushImageStep(buildContext, progressEventDispatcher.newChildProducer(), registryClient, manifestList, tag, manifestListDigest, // return value and type.
manifestListDigest)).collect(ImmutableList.toImmutableList());
}
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class StepsRunner method obtainBaseImageLayers.
// This method updates the given "preparedLayersCache" and should not be called concurrently.
@VisibleForTesting
List<Future<PreparedLayer>> obtainBaseImageLayers(Image baseImage, boolean layersRequiredLocally, Map<DescriptorDigest, Future<PreparedLayer>> preparedLayersCache, ProgressEventDispatcher.Factory progressDispatcherFactory) throws InterruptedException, ExecutionException {
List<Future<PreparedLayer>> preparedLayers = new ArrayList<>();
try (ProgressEventDispatcher progressDispatcher = progressDispatcherFactory.create("launching base image layer pullers", baseImage.getLayers().size())) {
for (Layer layer : baseImage.getLayers()) {
DescriptorDigest digest = layer.getBlobDescriptor().getDigest();
Future<PreparedLayer> preparedLayer = preparedLayersCache.get(digest);
if (preparedLayer != null) {
progressDispatcher.dispatchProgress(1);
} else {
// If we haven't obtained this layer yet, launcher a puller.
preparedLayer = executorService.submit(layersRequiredLocally ? ObtainBaseImageLayerStep.forForcedDownload(buildContext, progressDispatcher.newChildProducer(), layer, results.baseImagesAndRegistryClient.get().registryClient) : ObtainBaseImageLayerStep.forSelectiveDownload(buildContext, progressDispatcher.newChildProducer(), layer, results.baseImagesAndRegistryClient.get().registryClient, results.targetRegistryClient.get()));
preparedLayersCache.put(digest, preparedLayer);
}
preparedLayers.add(preparedLayer);
}
return preparedLayers;
}
}
Aggregations