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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations