use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class TarStreamBuilderTest method testToBlob_withCompression.
@Test
public void testToBlob_withCompression() throws IOException {
Blob blob = testTarStreamBuilder.toBlob();
// Writes the BLOB and captures the output.
ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream();
OutputStream compressorStream = new GZIPOutputStream(tarByteOutputStream);
blob.writeTo(compressorStream);
// Rearrange the output into input for verification.
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tarByteOutputStream.toByteArray());
InputStream tarByteInputStream = new GZIPInputStream(byteArrayInputStream);
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarByteInputStream);
verifyTarArchive(tarArchiveInputStream);
}
use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class CacheWriterTest method getExpectedLayer.
/**
* @return the expected layer to test against, represented by the {@code resourceBlob} resource
* file
*/
private ExpectedLayer getExpectedLayer() throws IOException {
String expectedBlobAString = new String(Files.readAllBytes(resourceBlob), StandardCharsets.UTF_8);
// Gets the expected content descriptor, diff ID, and compressed BLOB.
ByteArrayOutputStream compressedBlobOutputStream = new ByteArrayOutputStream();
CountingDigestOutputStream compressedDigestOutputStream = new CountingDigestOutputStream(compressedBlobOutputStream);
CountingDigestOutputStream uncompressedDigestOutputStream;
try (GZIPOutputStream compressorStream = new GZIPOutputStream(compressedDigestOutputStream)) {
uncompressedDigestOutputStream = new CountingDigestOutputStream(compressorStream);
uncompressedDigestOutputStream.write(expectedBlobAString.getBytes(StandardCharsets.UTF_8));
}
BlobDescriptor expectedBlobADescriptor = compressedDigestOutputStream.toBlobDescriptor();
DescriptorDigest expectedBlobADiffId = uncompressedDigestOutputStream.toBlobDescriptor().getDigest();
ByteArrayInputStream compressedBlobInputStream = new ByteArrayInputStream(compressedBlobOutputStream.toByteArray());
Blob blob = Blobs.from(compressedBlobInputStream);
return new ExpectedLayer(expectedBlobADescriptor, expectedBlobADiffId, blob);
}
use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class BuildAndPushContainerConfigurationStep method afterBaseImageLayerFuturesFuture.
/**
* Depends on {@code pushAuthorizationFuture}, {@code pullBaseImageLayerFuturesFuture.get()}, and
* {@code buildApplicationLayerFutures}.
*/
private BlobDescriptor afterBaseImageLayerFuturesFuture() throws ExecutionException, InterruptedException, LayerPropertyNotFoundException, IOException, RegistryException {
try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
RegistryClient registryClient = new RegistryClient(NonBlockingFutures.get(pushAuthorizationFuture), buildConfiguration.getTargetRegistry(), buildConfiguration.getTargetRepository()).setTimer(timer);
// Constructs the image.
Image image = new Image();
for (Future<CachedLayer> cachedLayerFuture : NonBlockingFutures.get(pullBaseImageLayerFuturesFuture)) {
image.addLayer(NonBlockingFutures.get(cachedLayerFuture));
}
for (Future<CachedLayer> cachedLayerFuture : buildApplicationLayerFutures) {
image.addLayer(NonBlockingFutures.get(cachedLayerFuture));
}
image.setEnvironment(buildConfiguration.getEnvironment());
image.setEntrypoint(entrypoint);
ImageToJsonTranslator imageToJsonTranslator = new ImageToJsonTranslator(image);
// Gets the container configuration content descriptor.
Blob containerConfigurationBlob = imageToJsonTranslator.getContainerConfigurationBlob();
CountingDigestOutputStream digestOutputStream = new CountingDigestOutputStream(ByteStreams.nullOutputStream());
containerConfigurationBlob.writeTo(digestOutputStream);
BlobDescriptor containerConfigurationBlobDescriptor = digestOutputStream.toBlobDescriptor();
timer.lap("Pushing container configuration " + containerConfigurationBlobDescriptor.getDigest());
// TODO: Use PushBlobStep.
// Pushes the container configuration.
registryClient.pushBlob(containerConfigurationBlobDescriptor.getDigest(), containerConfigurationBlob);
return containerConfigurationBlobDescriptor;
}
}
Aggregations