Search in sources :

Example 1 with BuildResult

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;
    }
}
Also used : BuildResult(com.google.cloud.tools.jib.builder.steps.BuildResult) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with BuildResult

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());
}
Also used : BuildResult(com.google.cloud.tools.jib.builder.steps.BuildResult) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) Test(org.junit.Test)

Example 3 with BuildResult

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;
    }
}
Also used : BuildResult(com.google.cloud.tools.jib.builder.steps.BuildResult) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BuildResult (com.google.cloud.tools.jib.builder.steps.BuildResult)3 BuildContext (com.google.cloud.tools.jib.configuration.BuildContext)3 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)2 ExecutionException (java.util.concurrent.ExecutionException)2 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)1 Test (org.junit.Test)1