use of com.google.cloud.tools.jib.api.RegistryException in project jib by google.
the class JibBuildRunnerTest method testBuildImage_other.
@Test
public void testBuildImage_other() throws InterruptedException, IOException, CacheDirectoryCreationException, RegistryException, ExecutionException {
Mockito.doThrow(new RegistryException("messagePrefix")).when(mockJibContainerBuilder).containerize(mockContainerizer);
try {
testJibBuildRunner.runBuild();
Assert.fail();
} catch (BuildStepsExecutionException ex) {
Assert.assertEquals(TEST_HELPFUL_SUGGESTIONS.none(), ex.getMessage());
}
}
use of com.google.cloud.tools.jib.api.RegistryException in project jib by google.
the class JibBuildRunner method runBuild.
/**
* Runs the Jib build.
*
* @return the built {@link JibContainer}
* @throws BuildStepsExecutionException if another exception is thrown during the build
* @throws IOException if an I/O exception occurs
* @throws CacheDirectoryCreationException if the cache directory could not be created
*/
public JibContainer runBuild() throws BuildStepsExecutionException, IOException, CacheDirectoryCreationException {
try {
logger.accept(LogEvent.lifecycle(""));
logger.accept(LogEvent.lifecycle(startupMessage));
JibContainer jibContainer = jibContainerBuilder.containerize(containerizer);
logger.accept(LogEvent.lifecycle(""));
logger.accept(LogEvent.lifecycle(successMessage));
// when an image is built, write out the digest and id
if (imageDigestOutputPath != null) {
String imageDigest = jibContainer.getDigest().toString();
Files.write(imageDigestOutputPath, imageDigest.getBytes(StandardCharsets.UTF_8));
}
if (imageIdOutputPath != null) {
String imageId = jibContainer.getImageId().toString();
Files.write(imageIdOutputPath, imageId.getBytes(StandardCharsets.UTF_8));
}
if (imageJsonOutputPath != null) {
ImageMetadataOutput metadataOutput = ImageMetadataOutput.fromJibContainer(jibContainer);
String imageJson = metadataOutput.toJson();
Files.write(imageJsonOutputPath, imageJson.getBytes(StandardCharsets.UTF_8));
}
return jibContainer;
} catch (HttpHostConnectException ex) {
// Failed to connect to registry.
throw new BuildStepsExecutionException(helpfulSuggestions.forHttpHostConnect(), ex);
} catch (RegistryUnauthorizedException ex) {
handleRegistryUnauthorizedException(ex, helpfulSuggestions);
} catch (RegistryCredentialsNotSentException ex) {
throw new BuildStepsExecutionException(helpfulSuggestions.forCredentialsNotSent(), ex);
} catch (RegistryAuthenticationFailedException ex) {
if (ex.getCause() instanceof ResponseException) {
handleRegistryUnauthorizedException(new RegistryUnauthorizedException(ex.getServerUrl(), ex.getImageName(), (ResponseException) ex.getCause()), helpfulSuggestions);
} else {
// Unknown cause
throw new BuildStepsExecutionException(helpfulSuggestions.none(), ex);
}
} catch (UnknownHostException ex) {
throw new BuildStepsExecutionException(helpfulSuggestions.forUnknownHost(), ex);
} catch (InsecureRegistryException ex) {
throw new BuildStepsExecutionException(helpfulSuggestions.forInsecureRegistry(), ex);
} catch (RegistryException ex) {
// keep null-away happy
String message = Verify.verifyNotNull(ex.getMessage());
throw new BuildStepsExecutionException(message, ex);
} catch (ExecutionException ex) {
String message = ex.getCause().getMessage();
throw new BuildStepsExecutionException(message == null ? "(null exception message)" : message, ex.getCause());
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new BuildStepsExecutionException(helpfulSuggestions.none(), ex);
}
throw new IllegalStateException("unreachable");
}
use of com.google.cloud.tools.jib.api.RegistryException 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));
}
use of com.google.cloud.tools.jib.api.RegistryException 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 -> {
}));
}
use of com.google.cloud.tools.jib.api.RegistryException in project jib by GoogleContainerTools.
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"));
}
Aggregations