Search in sources :

Example 1 with TimerEventHandler

use of com.google.cloud.tools.jib.plugins.common.TimerEventHandler in project fabric8-maven-plugin by fabric8io.

the class JibServiceUtil method buildContainer.

static void buildContainer(JibContainerBuilder jibContainerBuilder, TarImage image, Logger logger) throws InterruptedException {
    final ExecutorService jibBuildExecutor = Executors.newCachedThreadPool();
    try {
        jibContainerBuilder.setCreationTime(Instant.now());
        jibContainerBuilder.containerize(Containerizer.to(image).setExecutorService(jibBuildExecutor).addEventHandler(LogEvent.class, log(logger)).addEventHandler(TimerEvent.class, new TimerEventHandler(logger::debug)).addEventHandler(ProgressEvent.class, new ProgressEventHandler(logUpdate())));
        logUpdateFinished();
    } catch (CacheDirectoryCreationException | IOException | ExecutionException | RegistryException ex) {
        logger.error("Unable to build the image tarball: ", ex);
        throw new IllegalStateException(ex);
    } catch (InterruptedException ex) {
        logger.error("Thread interrupted", ex);
        throw ex;
    } finally {
        jibBuildExecutor.shutdown();
        jibBuildExecutor.awaitTermination(JIB_EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    }
}
Also used : CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) LogEvent(com.google.cloud.tools.jib.api.LogEvent) TimerEventHandler(com.google.cloud.tools.jib.plugins.common.TimerEventHandler) ProgressEventHandler(com.google.cloud.tools.jib.event.progress.ProgressEventHandler) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException) ProgressEvent(com.google.cloud.tools.jib.event.events.ProgressEvent) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExecutionException(java.util.concurrent.ExecutionException) RegistryException(com.google.cloud.tools.jib.api.RegistryException)

Example 2 with TimerEventHandler

use of com.google.cloud.tools.jib.plugins.common.TimerEventHandler in project fabric8-maven-plugin by fabric8io.

the class JibServiceUtil method pushImage.

/**
 * @param baseImage Base TarImage from where the image will be built.
 * @param targetImageName Full name of the target Image to be pushed to the registry
 * @param credential
 * @param logger
 */
private static void pushImage(TarImage baseImage, String targetImageName, Credential credential, Logger logger) throws InterruptedException {
    final ExecutorService jibBuildExecutor = Executors.newCachedThreadPool();
    try {
        RegistryImage targetImage = RegistryImage.named(targetImageName);
        if (credential != null && !credential.getUsername().isEmpty() && !credential.getPassword().isEmpty()) {
            targetImage.addCredential(credential.getUsername(), credential.getPassword());
        }
        Jib.from(baseImage).containerize(Containerizer.to(targetImage).setExecutorService(jibBuildExecutor).addEventHandler(LogEvent.class, log(logger)).addEventHandler(TimerEvent.class, new TimerEventHandler(logger::debug)).addEventHandler(ProgressEvent.class, new ProgressEventHandler(logUpdate())));
        logUpdateFinished();
    } catch (RegistryException | CacheDirectoryCreationException | InvalidImageReferenceException | IOException | ExecutionException e) {
        logger.error("Exception occurred while pushing the image: %s", targetImageName);
        throw new IllegalStateException(e.getMessage(), e);
    } catch (InterruptedException ex) {
        logger.error("Thread interrupted", ex);
        throw ex;
    } finally {
        jibBuildExecutor.shutdown();
        jibBuildExecutor.awaitTermination(JIB_EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    }
}
Also used : LogEvent(com.google.cloud.tools.jib.api.LogEvent) TimerEventHandler(com.google.cloud.tools.jib.plugins.common.TimerEventHandler) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) IOException(java.io.IOException) ProgressEvent(com.google.cloud.tools.jib.event.events.ProgressEvent) RegistryException(com.google.cloud.tools.jib.api.RegistryException) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) ProgressEventHandler(com.google.cloud.tools.jib.event.progress.ProgressEventHandler) ExecutorService(java.util.concurrent.ExecutorService) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CacheDirectoryCreationException (com.google.cloud.tools.jib.api.CacheDirectoryCreationException)2 LogEvent (com.google.cloud.tools.jib.api.LogEvent)2 RegistryException (com.google.cloud.tools.jib.api.RegistryException)2 ProgressEvent (com.google.cloud.tools.jib.event.events.ProgressEvent)2 ProgressEventHandler (com.google.cloud.tools.jib.event.progress.ProgressEventHandler)2 TimerEventHandler (com.google.cloud.tools.jib.plugins.common.TimerEventHandler)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)1 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)1