Search in sources :

Example 11 with ImagesAndRegistryClient

use of com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient in project jib by google.

the class PullBaseImageStepTest method testTryMirrors_noMatchingMirrors.

@Test
public void testTryMirrors_noMatchingMirrors() throws LayerCountMismatchException, BadContainerConfigurationFormatException {
    Mockito.when(imageConfiguration.getImageRegistry()).thenReturn("registry");
    Mockito.when(buildContext.getRegistryMirrors()).thenReturn(ImmutableListMultimap.of("unmatched1", "mirror1", "unmatched2", "mirror2"));
    Optional<ImagesAndRegistryClient> result = pullBaseImageStep.tryMirrors(buildContext, progressDispatcherFactory);
    Assert.assertEquals(Optional.empty(), result);
    InOrder inOrder = Mockito.inOrder(eventHandlers);
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("mirror config: unmatched1 --> mirror1"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("mirror config: unmatched2 --> mirror2"));
    Mockito.verify(buildContext, Mockito.never()).newBaseImageRegistryClientFactory(Mockito.any());
}
Also used : InOrder(org.mockito.InOrder) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) Test(org.junit.Test)

Example 12 with ImagesAndRegistryClient

use of com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient in project jib by google.

the class PullBaseImageStepTest method testCall_scratch_multiplePlatforms.

@Test
public void testCall_scratch_multiplePlatforms() throws LayerPropertyNotFoundException, IOException, RegistryException, LayerCountMismatchException, BadContainerConfigurationFormatException, CacheCorruptedException, CredentialRetrievalException {
    Mockito.when(imageConfiguration.getImage()).thenReturn(ImageReference.scratch());
    Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("architecture1", "os1"), new Platform("architecture2", "os2")));
    ImagesAndRegistryClient result = pullBaseImageStep.call();
    Assert.assertEquals(2, result.images.size());
    Assert.assertEquals("architecture1", result.images.get(0).getArchitecture());
    Assert.assertEquals("os1", result.images.get(0).getOs());
    Assert.assertEquals("architecture2", result.images.get(1).getArchitecture());
    Assert.assertEquals("os2", result.images.get(1).getOs());
    Assert.assertNull(result.registryClient);
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) Test(org.junit.Test)

Example 13 with ImagesAndRegistryClient

use of com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient in project jib by google.

the class PullBaseImageStepTest method testTryMirrors_multipleMirrors.

@Test
public void testTryMirrors_multipleMirrors() throws LayerCountMismatchException, BadContainerConfigurationFormatException, IOException, RegistryException, InvalidImageReferenceException {
    Mockito.when(imageConfiguration.getImage()).thenReturn(ImageReference.parse("registry/repo"));
    Mockito.when(imageConfiguration.getImageRegistry()).thenReturn("registry");
    Mockito.when(buildContext.getRegistryMirrors()).thenReturn(ImmutableListMultimap.of("registry", "quay.io", "registry", "gcr.io"));
    Mockito.when(buildContext.newBaseImageRegistryClientFactory("quay.io")).thenReturn(registryClientFactory);
    Mockito.when(registryClient.pullManifest(Mockito.any())).thenThrow(new RegistryException("not found"));
    RegistryClient.Factory gcrRegistryClientFactory = setUpWorkingRegistryClientFactory();
    Mockito.when(buildContext.newBaseImageRegistryClientFactory("gcr.io")).thenReturn(gcrRegistryClientFactory);
    Optional<ImagesAndRegistryClient> result = pullBaseImageStep.tryMirrors(buildContext, progressDispatcherFactory);
    Assert.assertTrue(result.isPresent());
    Assert.assertEquals(gcrRegistryClientFactory.newRegistryClient(), result.get().registryClient);
    InOrder inOrder = Mockito.inOrder(eventHandlers);
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("trying mirror quay.io for the base image"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("failed to get manifest from mirror quay.io: not found"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("trying mirror gcr.io for the base image"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("pulled manifest from mirror gcr.io"));
}
Also used : InOrder(org.mockito.InOrder) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) RegistryException(com.google.cloud.tools.jib.api.RegistryException) Test(org.junit.Test)

Example 14 with ImagesAndRegistryClient

use of com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient in project jib by google.

the class PullBaseImageStepTest method testCall_allMirrorsFail.

@Test
public void testCall_allMirrorsFail() throws InvalidImageReferenceException, IOException, RegistryException, LayerPropertyNotFoundException, LayerCountMismatchException, BadContainerConfigurationFormatException, CacheCorruptedException, CredentialRetrievalException {
    Mockito.when(imageConfiguration.getImage()).thenReturn(ImageReference.parse("registry/repo"));
    Mockito.when(imageConfiguration.getImageRegistry()).thenReturn("registry");
    Mockito.when(buildContext.getRegistryMirrors()).thenReturn(ImmutableListMultimap.of("registry", "quay.io", "registry", "gcr.io"));
    Mockito.when(buildContext.newBaseImageRegistryClientFactory(Mockito.any())).thenReturn(registryClientFactory);
    Mockito.when(registryClient.pullManifest(Mockito.any())).thenThrow(new RegistryException("not found"));
    RegistryClient.Factory dockerHubRegistryClientFactory = setUpWorkingRegistryClientFactory();
    Mockito.when(buildContext.newBaseImageRegistryClientFactory()).thenReturn(dockerHubRegistryClientFactory);
    ImagesAndRegistryClient result = pullBaseImageStep.call();
    Assert.assertEquals(dockerHubRegistryClientFactory.newRegistryClient(), result.registryClient);
    InOrder inOrder = Mockito.inOrder(eventHandlers);
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("trying mirror quay.io for the base image"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("failed to get manifest from mirror quay.io: not found"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("trying mirror gcr.io for the base image"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("failed to get manifest from mirror gcr.io: not found"));
}
Also used : InOrder(org.mockito.InOrder) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) RegistryException(com.google.cloud.tools.jib.api.RegistryException) Test(org.junit.Test)

Example 15 with ImagesAndRegistryClient

use of com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient in project jib by google.

the class PullBaseImageStepTest method testTryMirrors_mirrorIoError.

@Test
public void testTryMirrors_mirrorIoError() throws LayerCountMismatchException, BadContainerConfigurationFormatException, IOException, RegistryException {
    Mockito.when(imageConfiguration.getImageRegistry()).thenReturn("registry");
    Mockito.when(buildContext.getRegistryMirrors()).thenReturn(ImmutableListMultimap.of("registry", "gcr.io"));
    Mockito.when(buildContext.newBaseImageRegistryClientFactory("gcr.io")).thenReturn(registryClientFactory);
    Mockito.when(registryClient.pullManifest(Mockito.any())).thenThrow(new IOException("test exception"));
    Optional<ImagesAndRegistryClient> result = pullBaseImageStep.tryMirrors(buildContext, progressDispatcherFactory);
    Assert.assertEquals(Optional.empty(), result);
    InOrder inOrder = Mockito.inOrder(eventHandlers);
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("trying mirror gcr.io for the base image"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("failed to get manifest from mirror gcr.io: test exception"));
}
Also used : InOrder(org.mockito.InOrder) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ImagesAndRegistryClient (com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient)22 Test (org.junit.Test)18 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)8 InOrder (org.mockito.InOrder)8 ImageReference (com.google.cloud.tools.jib.api.ImageReference)6 RegistryException (com.google.cloud.tools.jib.api.RegistryException)6 Image (com.google.cloud.tools.jib.image.Image)6 IOException (java.io.IOException)6 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)4 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)4 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)4 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)4 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)4 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)4 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)4 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)4 Credential (com.google.cloud.tools.jib.api.Credential)2 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)2 RegistryUnauthorizedException (com.google.cloud.tools.jib.api.RegistryUnauthorizedException)2 DigestOnlyLayer (com.google.cloud.tools.jib.image.DigestOnlyLayer)2