Search in sources :

Example 86 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.

the class LayerEntriesSelectorTest method testGenerateSelector_empty.

@Test
public void testGenerateSelector_empty() throws IOException {
    DescriptorDigest expectedSelector = Digests.computeJsonDigest(ImmutableList.of());
    Assert.assertEquals(expectedSelector, LayerEntriesSelector.generateSelector(ImmutableList.of()));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 87 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.

the class ObtainBaseImageLayerStepTest method setUp.

@Before
public void setUp() throws IOException, RegistryException, DigestException {
    existingLayerDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    freshLayerDigest = DescriptorDigest.fromHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
    DescriptorDigest diffId = Mockito.mock(DescriptorDigest.class);
    existingLayer = new ReferenceLayer(new BlobDescriptor(existingLayerDigest), diffId);
    freshLayer = new ReferenceLayer(new BlobDescriptor(freshLayerDigest), diffId);
    Mockito.when(registryClient.checkBlob(existingLayerDigest)).thenReturn(Optional.of(Mockito.mock(BlobDescriptor.class)));
    Mockito.when(registryClient.checkBlob(freshLayerDigest)).thenReturn(Optional.empty());
    // necessary to prevent error from classes dealing with progress report
    Answer3<Blob, DescriptorDigest, Consumer<Long>, Consumer<Long>> progressSizeSetter = (ignored1, progressSizeConsumer, ignored2) -> {
        progressSizeConsumer.accept(Long.valueOf(12345));
        return null;
    };
    Mockito.when(registryClient.pullBlob(Mockito.any(), Mockito.any(), Mockito.any())).thenAnswer(AdditionalAnswers.answer(progressSizeSetter));
}
Also used : StateInTarget(com.google.cloud.tools.jib.builder.steps.PreparedLayer.StateInTarget) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) DigestException(java.security.DigestException) Before(org.junit.Before) Answer3(org.mockito.stubbing.Answer3) Layer(com.google.cloud.tools.jib.image.Layer) Answers(org.mockito.Answers) Blob(com.google.cloud.tools.jib.blob.Blob) IOException(java.io.IOException) Test(org.junit.Test) RegistryException(com.google.cloud.tools.jib.api.RegistryException) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) AdditionalAnswers(org.mockito.AdditionalAnswers) CacheCorruptedException(com.google.cloud.tools.jib.cache.CacheCorruptedException) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) Optional(java.util.Optional) Assert(org.junit.Assert) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) Blob(com.google.cloud.tools.jib.blob.Blob) Consumer(java.util.function.Consumer) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Before(org.junit.Before)

Example 88 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class BlobCheckerIntegrationTest method testCheck_doesNotExist.

@Test
public void testCheck_doesNotExist() throws IOException, RegistryException, DigestException {
    RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient).newRegistryClient();
    DescriptorDigest fakeBlobDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    Assert.assertFalse(registryClient.checkBlob(fakeBlobDigest).isPresent());
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 89 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class BlobPullerIntegrationTest method testPull.

@Test
public void testPull() throws IOException, RegistryException {
    RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient).newRegistryClient();
    V22ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V22ManifestTemplate.class).getManifest();
    DescriptorDigest realDigest = manifestTemplate.getLayers().get(0).getDigest();
    // Pulls a layer BLOB of the distroless/base image.
    LongAdder totalByteCount = new LongAdder();
    LongAdder expectedSize = new LongAdder();
    Blob pulledBlob = registryClient.pullBlob(realDigest, size -> {
        Assert.assertEquals(0, expectedSize.sum());
        expectedSize.add(size);
    }, totalByteCount::add);
    Assert.assertEquals(realDigest, pulledBlob.writeTo(ByteStreams.nullOutputStream()).getDigest());
    Assert.assertTrue(expectedSize.sum() > 0);
    Assert.assertEquals(expectedSize.sum(), totalByteCount.sum());
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) Blob(com.google.cloud.tools.jib.blob.Blob) LongAdder(java.util.concurrent.atomic.LongAdder) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 90 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class BlobPusherIntegrationTest method testPush.

@Test
public void testPush() throws DigestException, IOException, RegistryException {
    Blob testBlob = Blobs.from("crepecake");
    // Known digest for 'crepecake'
    DescriptorDigest testBlobDigest = DescriptorDigest.fromHash("52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c");
    RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "localhost:5000", "testimage", httpClient).newRegistryClient();
    Assert.assertFalse(registryClient.pushBlob(testBlobDigest, testBlob, null, ignored -> {
    }));
}
Also used : Blob(com.google.cloud.tools.jib.blob.Blob) FailoverHttpClient(com.google.cloud.tools.jib.http.FailoverHttpClient) DigestException(java.security.DigestException) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Blobs(com.google.cloud.tools.jib.blob.Blobs) IOException(java.io.IOException) Test(org.junit.Test) RegistryException(com.google.cloud.tools.jib.api.RegistryException) Assert(org.junit.Assert) ClassRule(org.junit.ClassRule) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Blob(com.google.cloud.tools.jib.blob.Blob) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Aggregations

DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)112 Test (org.junit.Test)68 Path (java.nio.file.Path)28 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)24 Blob (com.google.cloud.tools.jib.blob.Blob)18 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)16 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)16 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)16 Image (com.google.cloud.tools.jib.image.Image)14 ByteArrayInputStream (java.io.ByteArrayInputStream)14 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 RegistryException (com.google.cloud.tools.jib.api.RegistryException)12 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)12 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)10 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)10 DigestException (java.security.DigestException)10 FailoverHttpClient (com.google.cloud.tools.jib.http.FailoverHttpClient)8 Layer (com.google.cloud.tools.jib.image.Layer)8 OutputStream (java.io.OutputStream)8