Search in sources :

Example 1 with ProgressEventHandler

use of com.google.cloud.tools.jib.event.progress.ProgressEventHandler 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 ProgressEventHandler

use of com.google.cloud.tools.jib.event.progress.ProgressEventHandler 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)

Example 3 with ProgressEventHandler

use of com.google.cloud.tools.jib.event.progress.ProgressEventHandler in project jkube by eclipse.

the class JibServiceUtil method buildContainer.

/**
 * Build container image using JIB
 *
 * @param jibContainerBuilder jib container builder object
 * @param image tarball for image
 * @param logger kit logger
 * @throws InterruptedException in case thread is interrupted
 */
public static void buildContainer(JibContainerBuilder jibContainerBuilder, TarImage image, KitLogger logger) throws InterruptedException {
    final ExecutorService jibBuildExecutor = Executors.newCachedThreadPool();
    try {
        jibContainerBuilder.setCreationTime(Instant.now());
        jibContainerBuilder.containerize(Containerizer.to(image).setAllowInsecureRegistries(true).setExecutorService(jibBuildExecutor).addEventHandler(LogEvent.class, log(logger)).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) {
        Thread.currentThread().interrupt();
        throw ex;
    } finally {
        jibBuildExecutor.shutdown();
        jibBuildExecutor.awaitTermination(JIB_EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    }
}
Also used : CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) 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) ExecutionException(java.util.concurrent.ExecutionException) RegistryException(com.google.cloud.tools.jib.api.RegistryException)

Example 4 with ProgressEventHandler

use of com.google.cloud.tools.jib.event.progress.ProgressEventHandler in project docker-maven-plugin by fabric8io.

the class JibServiceUtil method buildContainer.

/**
 * Build container image using JIB
 *
 * @param jibContainerBuilder jib container builder object
 * @param image tarball for image
 * @param logger kit logger
 * @throws InterruptedException in case thread is interrupted
 */
public 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).setAllowInsecureRegistries(true).setExecutorService(jibBuildExecutor).addEventHandler(LogEvent.class, log(logger)).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) {
        Thread.currentThread().interrupt();
        throw ex;
    } finally {
        jibBuildExecutor.shutdown();
        jibBuildExecutor.awaitTermination(JIB_EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    }
}
Also used : CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) 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) ExecutionException(java.util.concurrent.ExecutionException) RegistryException(com.google.cloud.tools.jib.api.RegistryException)

Aggregations

CacheDirectoryCreationException (com.google.cloud.tools.jib.api.CacheDirectoryCreationException)4 RegistryException (com.google.cloud.tools.jib.api.RegistryException)4 ProgressEvent (com.google.cloud.tools.jib.event.events.ProgressEvent)4 ProgressEventHandler (com.google.cloud.tools.jib.event.progress.ProgressEventHandler)4 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 ExecutorService (java.util.concurrent.ExecutorService)4 LogEvent (com.google.cloud.tools.jib.api.LogEvent)2 TimerEventHandler (com.google.cloud.tools.jib.plugins.common.TimerEventHandler)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