use of com.google.cloud.tools.jib.builder.steps.BuildResult in project jib by google.
the class JibContainerBuilder method containerize.
/**
* Builds the container.
*
* @param containerizer the {@link Containerizer} that configures how to containerize
* @return the built container
* @throws IOException if an I/O exception occurs
* @throws CacheDirectoryCreationException if a directory to be used for the cache could not be
* created
* @throws HttpHostConnectException if jib failed to connect to a registry
* @throws RegistryUnauthorizedException if a registry request is unauthorized and needs
* authentication
* @throws RegistryAuthenticationFailedException if registry authentication failed
* @throws UnknownHostException if the registry does not exist
* @throws InsecureRegistryException if a server could not be verified due to an insecure
* connection
* @throws RegistryException if some other error occurred while interacting with a registry
* @throws ExecutionException if some other exception occurred during execution
* @throws InterruptedException if the execution was interrupted
*/
public JibContainer containerize(Containerizer containerizer) throws InterruptedException, RegistryException, IOException, CacheDirectoryCreationException, ExecutionException {
try (BuildContext buildContext = toBuildContext(containerizer);
TimerEventDispatcher ignored = new TimerEventDispatcher(buildContext.getEventHandlers(), containerizer.getDescription())) {
logSources(buildContext.getEventHandlers());
BuildResult buildResult = containerizer.run(buildContext);
return JibContainer.from(buildContext, buildResult);
} catch (ExecutionException ex) {
// If an ExecutionException occurs, re-throw the cause to be more easily handled by the user
if (ex.getCause() instanceof RegistryException) {
throw (RegistryException) ex.getCause();
}
throw ex;
}
}
use of com.google.cloud.tools.jib.builder.steps.BuildResult in project jib by google.
the class JibContainerTest method testCreation_withBuildContextAndBuildResult.
@Test
public void testCreation_withBuildContextAndBuildResult() {
BuildResult buildResult = Mockito.mock(BuildResult.class);
BuildContext buildContext = Mockito.mock(BuildContext.class);
ImageConfiguration mockTargetConfiguration = Mockito.mock(ImageConfiguration.class);
when(buildResult.getImageDigest()).thenReturn(digest1);
when(buildResult.getImageId()).thenReturn(digest1);
when(buildResult.isImagePushed()).thenReturn(true);
when(mockTargetConfiguration.getImage()).thenReturn(targetImage1);
when(buildContext.getTargetImageConfiguration()).thenReturn(mockTargetConfiguration);
when(buildContext.getAllTargetImageTags()).thenReturn(ImmutableSet.copyOf(tags1));
JibContainer container = JibContainer.from(buildContext, buildResult);
Assert.assertEquals(targetImage1, container.getTargetImage());
Assert.assertEquals(digest1, container.getDigest());
Assert.assertEquals(digest1, container.getImageId());
Assert.assertEquals(tags1, container.getTags());
Assert.assertTrue(container.isImagePushed());
}
use of com.google.cloud.tools.jib.builder.steps.BuildResult in project jib by GoogleContainerTools.
the class JibContainerBuilder method containerize.
/**
* Builds the container.
*
* @param containerizer the {@link Containerizer} that configures how to containerize
* @return the built container
* @throws IOException if an I/O exception occurs
* @throws CacheDirectoryCreationException if a directory to be used for the cache could not be
* created
* @throws HttpHostConnectException if jib failed to connect to a registry
* @throws RegistryUnauthorizedException if a registry request is unauthorized and needs
* authentication
* @throws RegistryAuthenticationFailedException if registry authentication failed
* @throws UnknownHostException if the registry does not exist
* @throws InsecureRegistryException if a server could not be verified due to an insecure
* connection
* @throws RegistryException if some other error occurred while interacting with a registry
* @throws ExecutionException if some other exception occurred during execution
* @throws InterruptedException if the execution was interrupted
*/
public JibContainer containerize(Containerizer containerizer) throws InterruptedException, RegistryException, IOException, CacheDirectoryCreationException, ExecutionException {
try (BuildContext buildContext = toBuildContext(containerizer);
TimerEventDispatcher ignored = new TimerEventDispatcher(buildContext.getEventHandlers(), containerizer.getDescription())) {
logSources(buildContext.getEventHandlers());
BuildResult buildResult = containerizer.run(buildContext);
return JibContainer.from(buildContext, buildResult);
} catch (ExecutionException ex) {
// If an ExecutionException occurs, re-throw the cause to be more easily handled by the user
if (ex.getCause() instanceof RegistryException) {
throw (RegistryException) ex.getCause();
}
throw ex;
}
}
Aggregations