Search in sources :

Example 1 with ConsoleLogger

use of com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger in project jib by GoogleContainerTools.

the class Containerizers method create.

private static Containerizer create(CommonCliOptions commonCliOptions, ConsoleLogger logger) throws InvalidImageReferenceException, FileNotFoundException {
    String imageSpec = commonCliOptions.getTargetImage();
    if (imageSpec.startsWith(DOCKER_DAEMON_IMAGE_PREFIX)) {
        // TODO: allow setting docker env and docker executable (along with path/env)
        return Containerizer.to(DockerDaemonImage.named(imageSpec.replaceFirst(DOCKER_DAEMON_IMAGE_PREFIX, "")));
    }
    if (imageSpec.startsWith(TAR_IMAGE_PREFIX)) {
        return Containerizer.to(TarImage.at(Paths.get(imageSpec.replaceFirst(TAR_IMAGE_PREFIX, ""))).named(commonCliOptions.getName()));
    }
    ImageReference imageReference = ImageReference.parse(imageSpec.replaceFirst(REGISTRY_IMAGE_PREFIX, ""));
    RegistryImage registryImage = RegistryImage.named(imageReference);
    DefaultCredentialRetrievers defaultCredentialRetrievers = DefaultCredentialRetrievers.init(CredentialRetrieverFactory.forImage(imageReference, logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage())));
    Credentials.getToCredentialRetrievers(commonCliOptions, defaultCredentialRetrievers).forEach(registryImage::addCredentialRetriever);
    return Containerizer.to(registryImage);
}
Also used : DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) ImageReference(com.google.cloud.tools.jib.api.ImageReference) TAR_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.TAR_IMAGE_PREFIX) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) ProgressEvent(com.google.cloud.tools.jib.event.events.ProgressEvent) TarImage(com.google.cloud.tools.jib.api.TarImage) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) DOCKER_DAEMON_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.DOCKER_DAEMON_IMAGE_PREFIX) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) ProgressEventHandler(com.google.cloud.tools.jib.event.progress.ProgressEventHandler) FileNotFoundException(java.io.FileNotFoundException) REGISTRY_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.REGISTRY_IMAGE_PREFIX) LogEvent(com.google.cloud.tools.jib.api.LogEvent) List(java.util.List) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) JibSystemProperties(com.google.cloud.tools.jib.global.JibSystemProperties) ProgressDisplayGenerator(com.google.cloud.tools.jib.plugins.common.logging.ProgressDisplayGenerator) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) ImageReference(com.google.cloud.tools.jib.api.ImageReference) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage)

Example 2 with ConsoleLogger

use of com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger in project jib by GoogleContainerTools.

the class War method call.

@Override
public Integer call() {
    commonCliOptions.validate();
    SingleThreadedExecutor executor = new SingleThreadedExecutor();
    ConsoleLogger logger = CliLogger.newLogger(commonCliOptions.getVerbosity(), commonCliOptions.getHttpTrace(), commonCliOptions.getConsoleOutput(), spec.commandLine().getOut(), spec.commandLine().getErr(), executor);
    Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
    try {
        JibCli.configureHttpLogging(commonCliOptions.getHttpTrace().toJulLevel());
        GlobalConfig globalConfig = GlobalConfig.readConfig();
        updateCheckFuture = JibCli.newUpdateChecker(globalConfig, commonCliOptions.getVerbosity(), logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage()));
        if (!Files.exists(warFile)) {
            logger.log(LogEvent.Level.ERROR, "The file path provided does not exist: " + warFile);
            return 1;
        }
        if (Files.isDirectory(warFile)) {
            logger.log(LogEvent.Level.ERROR, "The file path provided is for a directory. Please provide a path to a WAR: " + warFile);
            return 1;
        }
        Path warFileParentDir = Verify.verifyNotNull(warFile.toAbsolutePath().getParent());
        CacheDirectories cacheDirectories = CacheDirectories.from(commonCliOptions, warFileParentDir);
        ArtifactProcessor processor = ArtifactProcessors.fromWar(warFile, cacheDirectories, this, commonContainerConfigCliOptions);
        JibContainerBuilder containerBuilder = WarFiles.toJibContainerBuilder(processor, commonCliOptions, commonContainerConfigCliOptions, logger);
        Containerizer containerizer = Containerizers.from(commonCliOptions, logger, cacheDirectories);
        // Enable registry mirrors
        Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
        JibContainer jibContainer = containerBuilder.containerize(containerizer);
        JibCli.writeImageJson(commonCliOptions.getImageJsonPath(), jibContainer);
    } catch (InterruptedException ex) {
        JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
        Thread.currentThread().interrupt();
        return 1;
    } catch (Exception ex) {
        JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
        return 1;
    } finally {
        JibCli.finishUpdateChecker(logger, updateCheckFuture);
        executor.shutDownAndAwaitTermination(Duration.ofSeconds(3));
    }
    return 0;
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Verify(com.google.common.base.Verify) SingleThreadedExecutor(com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) WarFiles(com.google.cloud.tools.jib.cli.war.WarFiles) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) Files(java.nio.file.Files) JibContainer(com.google.cloud.tools.jib.api.JibContainer) Callable(java.util.concurrent.Callable) Multimaps(com.google.common.collect.Multimaps) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Futures(com.google.common.util.concurrent.Futures) Future(java.util.concurrent.Future) CliLogger(com.google.cloud.tools.jib.cli.logging.CliLogger) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Duration(java.time.Duration) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Path(java.nio.file.Path) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) CommandLine(picocli.CommandLine) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) Optional(java.util.Optional) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) JibContainer(com.google.cloud.tools.jib.api.JibContainer) SingleThreadedExecutor(com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) Containerizer(com.google.cloud.tools.jib.api.Containerizer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder)

Example 3 with ConsoleLogger

use of com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger in project jib by google.

the class CliLoggerTest method createLoggerAndSendMessages.

private void createLoggerAndSendMessages(Verbosity verbosity, ConsoleOutput consoleOutput) {
    SingleThreadedExecutor executor = new SingleThreadedExecutor();
    ConsoleLogger logger = CliLogger.newLogger(verbosity, HttpTraceLevel.off, consoleOutput, mockOut, mockErr, executor);
    logger.log(Level.DEBUG, "debug");
    logger.log(Level.INFO, "info");
    logger.log(Level.LIFECYCLE, "lifecycle");
    logger.log(Level.PROGRESS, "progress");
    logger.log(Level.WARN, "warn");
    logger.log(Level.ERROR, "error");
    executor.shutDownAndAwaitTermination(Duration.ofSeconds(3));
}
Also used : ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) SingleThreadedExecutor(com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor)

Example 4 with ConsoleLogger

use of com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger in project jib by google.

the class War method call.

@Override
public Integer call() {
    commonCliOptions.validate();
    SingleThreadedExecutor executor = new SingleThreadedExecutor();
    ConsoleLogger logger = CliLogger.newLogger(commonCliOptions.getVerbosity(), commonCliOptions.getHttpTrace(), commonCliOptions.getConsoleOutput(), spec.commandLine().getOut(), spec.commandLine().getErr(), executor);
    Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
    try {
        JibCli.configureHttpLogging(commonCliOptions.getHttpTrace().toJulLevel());
        GlobalConfig globalConfig = GlobalConfig.readConfig();
        updateCheckFuture = JibCli.newUpdateChecker(globalConfig, commonCliOptions.getVerbosity(), logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage()));
        if (!Files.exists(warFile)) {
            logger.log(LogEvent.Level.ERROR, "The file path provided does not exist: " + warFile);
            return 1;
        }
        if (Files.isDirectory(warFile)) {
            logger.log(LogEvent.Level.ERROR, "The file path provided is for a directory. Please provide a path to a WAR: " + warFile);
            return 1;
        }
        Path warFileParentDir = Verify.verifyNotNull(warFile.toAbsolutePath().getParent());
        CacheDirectories cacheDirectories = CacheDirectories.from(commonCliOptions, warFileParentDir);
        ArtifactProcessor processor = ArtifactProcessors.fromWar(warFile, cacheDirectories, this, commonContainerConfigCliOptions);
        JibContainerBuilder containerBuilder = WarFiles.toJibContainerBuilder(processor, commonCliOptions, commonContainerConfigCliOptions, logger);
        Containerizer containerizer = Containerizers.from(commonCliOptions, logger, cacheDirectories);
        // Enable registry mirrors
        Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
        JibContainer jibContainer = containerBuilder.containerize(containerizer);
        JibCli.writeImageJson(commonCliOptions.getImageJsonPath(), jibContainer);
    } catch (InterruptedException ex) {
        JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
        Thread.currentThread().interrupt();
        return 1;
    } catch (Exception ex) {
        JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
        return 1;
    } finally {
        JibCli.finishUpdateChecker(logger, updateCheckFuture);
        executor.shutDownAndAwaitTermination(Duration.ofSeconds(3));
    }
    return 0;
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Verify(com.google.common.base.Verify) SingleThreadedExecutor(com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) WarFiles(com.google.cloud.tools.jib.cli.war.WarFiles) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) Files(java.nio.file.Files) JibContainer(com.google.cloud.tools.jib.api.JibContainer) Callable(java.util.concurrent.Callable) Multimaps(com.google.common.collect.Multimaps) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Futures(com.google.common.util.concurrent.Futures) Future(java.util.concurrent.Future) CliLogger(com.google.cloud.tools.jib.cli.logging.CliLogger) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Duration(java.time.Duration) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Path(java.nio.file.Path) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) CommandLine(picocli.CommandLine) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) Optional(java.util.Optional) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) JibContainer(com.google.cloud.tools.jib.api.JibContainer) SingleThreadedExecutor(com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) Containerizer(com.google.cloud.tools.jib.api.Containerizer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder)

Example 5 with ConsoleLogger

use of com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger in project jib by google.

the class Build method call.

@Override
public Integer call() {
    commonCliOptions.validate();
    Path buildFile = getBuildFile();
    SingleThreadedExecutor executor = new SingleThreadedExecutor();
    ConsoleLogger logger = CliLogger.newLogger(commonCliOptions.getVerbosity(), commonCliOptions.getHttpTrace(), commonCliOptions.getConsoleOutput(), spec.commandLine().getOut(), spec.commandLine().getErr(), executor);
    Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
    try {
        JibCli.configureHttpLogging(commonCliOptions.getHttpTrace().toJulLevel());
        GlobalConfig globalConfig = GlobalConfig.readConfig();
        updateCheckFuture = JibCli.newUpdateChecker(globalConfig, commonCliOptions.getVerbosity(), logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage()));
        if (!Files.isReadable(buildFile)) {
            logger.log(LogEvent.Level.ERROR, "The Build File YAML either does not exist or cannot be opened for reading: " + buildFile);
            return 1;
        }
        if (!Files.isRegularFile(buildFile)) {
            logger.log(LogEvent.Level.ERROR, "Build File YAML path is a not a file: " + buildFile);
            return 1;
        }
        CacheDirectories cacheDirectories = CacheDirectories.from(commonCliOptions, contextRoot);
        Containerizer containerizer = Containerizers.from(commonCliOptions, logger, cacheDirectories);
        JibContainerBuilder containerBuilder = BuildFiles.toJibContainerBuilder(contextRoot, buildFile, this, commonCliOptions, logger);
        // Enable registry mirrors
        Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
        JibContainer jibContainer = containerBuilder.containerize(containerizer);
        JibCli.writeImageJson(commonCliOptions.getImageJsonPath(), jibContainer);
    } catch (InterruptedException ex) {
        JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
        Thread.currentThread().interrupt();
        return 1;
    } catch (Exception ex) {
        JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
        return 1;
    } finally {
        JibCli.finishUpdateChecker(logger, updateCheckFuture);
        executor.shutDownAndAwaitTermination(Duration.ofSeconds(3));
    }
    return 0;
}
Also used : Path(java.nio.file.Path) SingleThreadedExecutor(com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) Files(java.nio.file.Files) JibContainer(com.google.cloud.tools.jib.api.JibContainer) Callable(java.util.concurrent.Callable) Multimaps(com.google.common.collect.Multimaps) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Futures(com.google.common.util.concurrent.Futures) Future(java.util.concurrent.Future) CliLogger(com.google.cloud.tools.jib.cli.logging.CliLogger) Containerizer(com.google.cloud.tools.jib.api.Containerizer) BuildFiles(com.google.cloud.tools.jib.cli.buildfile.BuildFiles) Duration(java.time.Duration) Map(java.util.Map) Optional(java.util.Optional) CommandSpec(picocli.CommandLine.Model.CommandSpec) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Path(java.nio.file.Path) Collections(java.util.Collections) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) CommandLine(picocli.CommandLine) Optional(java.util.Optional) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) JibContainer(com.google.cloud.tools.jib.api.JibContainer) SingleThreadedExecutor(com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) Containerizer(com.google.cloud.tools.jib.api.Containerizer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder)

Aggregations

ConsoleLogger (com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger)12 Containerizer (com.google.cloud.tools.jib.api.Containerizer)8 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)8 LogEvent (com.google.cloud.tools.jib.api.LogEvent)8 SingleThreadedExecutor (com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor)8 JibContainer (com.google.cloud.tools.jib.api.JibContainer)6 CliLogger (com.google.cloud.tools.jib.cli.logging.CliLogger)6 GlobalConfig (com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 Multimaps (com.google.common.collect.Multimaps)6 Futures (com.google.common.util.concurrent.Futures)6 Files (java.nio.file.Files)6 Path (java.nio.file.Path)6 Duration (java.time.Duration)6 Optional (java.util.Optional)6 Callable (java.util.concurrent.Callable)6 Future (java.util.concurrent.Future)6 CommandLine (picocli.CommandLine)6 DockerDaemonImage (com.google.cloud.tools.jib.api.DockerDaemonImage)4 ImageReference (com.google.cloud.tools.jib.api.ImageReference)4