Search in sources :

Example 1 with GlobalConfig

use of com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig 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 2 with GlobalConfig

use of com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig in project jib by GoogleContainerTools.

the class BuildDockerMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    checkJibVersion();
    if (MojoCommon.shouldSkipJibExecution(this)) {
        return;
    }
    Path dockerExecutable = getDockerClientExecutable();
    boolean isDockerInstalled = dockerExecutable == null ? DockerClient.isDefaultDockerInstalled() : DockerClient.isDockerInstalled(dockerExecutable);
    if (!isDockerInstalled) {
        throw new MojoExecutionException(HelpfulSuggestions.forDockerNotInstalled(HELPFUL_SUGGESTIONS_PREFIX));
    }
    MavenSettingsProxyProvider.activateHttpAndHttpsProxies(getSession().getSettings(), getSettingsDecrypter());
    TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
    MavenProjectProperties projectProperties = MavenProjectProperties.getForProject(Preconditions.checkNotNull(descriptor), getProject(), getSession(), getLog(), tempDirectoryProvider, getInjectedPluginExtensions());
    Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
    try {
        GlobalConfig globalConfig = GlobalConfig.readConfig();
        updateCheckFuture = MojoCommon.newUpdateChecker(projectProperties, globalConfig, getLog());
        PluginConfigurationProcessor.createJibBuildRunnerForDockerDaemonImage(new MavenRawConfiguration(this), new MavenSettingsServerCredentials(getSession().getSettings(), getSettingsDecrypter()), projectProperties, globalConfig, new MavenHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX)).runBuild();
    } catch (InvalidAppRootException ex) {
        throw new MojoExecutionException("<container><appRoot> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
    } catch (InvalidContainerizingModeException ex) {
        throw new MojoExecutionException("invalid value for <containerizingMode>: " + ex.getInvalidContainerizingMode(), ex);
    } catch (InvalidWorkingDirectoryException ex) {
        throw new MojoExecutionException("<container><workingDirectory> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
    } catch (InvalidPlatformException ex) {
        throw new MojoExecutionException("<from><platforms> contains a platform configuration that is missing required values or has invalid values: " + ex.getMessage() + ": " + ex.getInvalidPlatform(), ex);
    } catch (InvalidContainerVolumeException ex) {
        throw new MojoExecutionException("<container><volumes> is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
    } catch (InvalidFilesModificationTimeException ex) {
        throw new MojoExecutionException("<container><filesModificationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or special keyword \"EPOCH_PLUS_SECOND\": " + ex.getInvalidFilesModificationTime(), ex);
    } catch (InvalidCreationTimeException ex) {
        throw new MojoExecutionException("<container><creationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or a special keyword (\"EPOCH\", " + "\"USE_CURRENT_TIMESTAMP\"): " + ex.getInvalidCreationTime(), ex);
    } catch (JibPluginExtensionException ex) {
        String extensionName = ex.getExtensionClass().getName();
        throw new MojoExecutionException("error running extension '" + extensionName + "': " + ex.getMessage(), ex);
    } catch (IncompatibleBaseImageJavaVersionException ex) {
        throw new MojoExecutionException(HelpfulSuggestions.forIncompatibleBaseImageJavaVersionForMaven(ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()), ex);
    } catch (InvalidImageReferenceException ex) {
        throw new MojoExecutionException(HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
    } catch (IOException | CacheDirectoryCreationException | MainClassInferenceException | InvalidGlobalConfigException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    } catch (BuildStepsExecutionException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex.getCause());
    } catch (ExtraDirectoryNotFoundException ex) {
        throw new MojoExecutionException("<extraDirectories><paths> contain \"from\" directory that doesn't exist locally: " + ex.getPath(), ex);
    } finally {
        tempDirectoryProvider.close();
        MojoCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
        projectProperties.waitForLoggingThread();
        getLog().info("");
    }
}
Also used : InvalidContainerVolumeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerVolumeException) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) ExtraDirectoryNotFoundException(com.google.cloud.tools.jib.plugins.common.ExtraDirectoryNotFoundException) InvalidFilesModificationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidFilesModificationTimeException) IncompatibleBaseImageJavaVersionException(com.google.cloud.tools.jib.plugins.common.IncompatibleBaseImageJavaVersionException) InvalidWorkingDirectoryException(com.google.cloud.tools.jib.plugins.common.InvalidWorkingDirectoryException) TempDirectoryProvider(com.google.cloud.tools.jib.filesystem.TempDirectoryProvider) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException) InvalidPlatformException(com.google.cloud.tools.jib.plugins.common.InvalidPlatformException) Path(java.nio.file.Path) InvalidAppRootException(com.google.cloud.tools.jib.plugins.common.InvalidAppRootException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Optional(java.util.Optional) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) BuildStepsExecutionException(com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException) IOException(java.io.IOException) InvalidGlobalConfigException(com.google.cloud.tools.jib.plugins.common.globalconfig.InvalidGlobalConfigException) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) InvalidCreationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidCreationTimeException) MainClassInferenceException(com.google.cloud.tools.jib.plugins.common.MainClassInferenceException)

Example 3 with GlobalConfig

use of com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig in project jib by GoogleContainerTools.

the class BuildTarMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    checkJibVersion();
    if (MojoCommon.shouldSkipJibExecution(this)) {
        return;
    }
    MavenSettingsProxyProvider.activateHttpAndHttpsProxies(getSession().getSettings(), getSettingsDecrypter());
    TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
    MavenProjectProperties projectProperties = MavenProjectProperties.getForProject(Preconditions.checkNotNull(descriptor), getProject(), getSession(), getLog(), tempDirectoryProvider, getInjectedPluginExtensions());
    Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
    try {
        GlobalConfig globalConfig = GlobalConfig.readConfig();
        updateCheckFuture = MojoCommon.newUpdateChecker(projectProperties, globalConfig, getLog());
        PluginConfigurationProcessor.createJibBuildRunnerForTarImage(new MavenRawConfiguration(this), new MavenSettingsServerCredentials(getSession().getSettings(), getSettingsDecrypter()), projectProperties, globalConfig, new MavenHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX)).runBuild();
    } catch (InvalidAppRootException ex) {
        throw new MojoExecutionException("<container><appRoot> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
    } catch (InvalidContainerizingModeException ex) {
        throw new MojoExecutionException("invalid value for <containerizingMode>: " + ex.getInvalidContainerizingMode(), ex);
    } catch (InvalidWorkingDirectoryException ex) {
        throw new MojoExecutionException("<container><workingDirectory> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
    } catch (InvalidPlatformException ex) {
        throw new MojoExecutionException("<from><platforms> contains a platform configuration that is missing required values or has invalid values: " + ex.getMessage() + ": " + ex.getInvalidPlatform(), ex);
    } catch (InvalidContainerVolumeException ex) {
        throw new MojoExecutionException("<container><volumes> is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
    } catch (InvalidFilesModificationTimeException ex) {
        throw new MojoExecutionException("<container><filesModificationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or special keyword \"EPOCH_PLUS_SECOND\": " + ex.getInvalidFilesModificationTime(), ex);
    } catch (InvalidCreationTimeException ex) {
        throw new MojoExecutionException("<container><creationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or a special keyword (\"EPOCH\", " + "\"USE_CURRENT_TIMESTAMP\"): " + ex.getInvalidCreationTime(), ex);
    } catch (JibPluginExtensionException ex) {
        String extensionName = ex.getExtensionClass().getName();
        throw new MojoExecutionException("error running extension '" + extensionName + "': " + ex.getMessage(), ex);
    } catch (IncompatibleBaseImageJavaVersionException ex) {
        throw new MojoExecutionException(HelpfulSuggestions.forIncompatibleBaseImageJavaVersionForMaven(ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()), ex);
    } catch (InvalidImageReferenceException ex) {
        throw new MojoExecutionException(HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
    } catch (IOException | CacheDirectoryCreationException | MainClassInferenceException | InvalidGlobalConfigException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    } catch (BuildStepsExecutionException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex.getCause());
    } catch (ExtraDirectoryNotFoundException ex) {
        throw new MojoExecutionException("<extraDirectories><paths> contain \"from\" directory that doesn't exist locally: " + ex.getPath(), ex);
    } finally {
        tempDirectoryProvider.close();
        MojoCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
        projectProperties.waitForLoggingThread();
        getLog().info("");
    }
}
Also used : InvalidContainerVolumeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerVolumeException) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) ExtraDirectoryNotFoundException(com.google.cloud.tools.jib.plugins.common.ExtraDirectoryNotFoundException) InvalidFilesModificationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidFilesModificationTimeException) IncompatibleBaseImageJavaVersionException(com.google.cloud.tools.jib.plugins.common.IncompatibleBaseImageJavaVersionException) InvalidWorkingDirectoryException(com.google.cloud.tools.jib.plugins.common.InvalidWorkingDirectoryException) TempDirectoryProvider(com.google.cloud.tools.jib.filesystem.TempDirectoryProvider) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException) InvalidPlatformException(com.google.cloud.tools.jib.plugins.common.InvalidPlatformException) InvalidAppRootException(com.google.cloud.tools.jib.plugins.common.InvalidAppRootException) Optional(java.util.Optional) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) BuildStepsExecutionException(com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException) IOException(java.io.IOException) InvalidGlobalConfigException(com.google.cloud.tools.jib.plugins.common.globalconfig.InvalidGlobalConfigException) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) InvalidCreationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidCreationTimeException) MainClassInferenceException(com.google.cloud.tools.jib.plugins.common.MainClassInferenceException)

Example 4 with GlobalConfig

use of com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig in project jib by GoogleContainerTools.

the class BuildDockerTask method buildDocker.

/**
 * Task Action, builds an image to docker daemon.
 *
 * @throws IOException if an error occurs creating the jib runner
 * @throws BuildStepsExecutionException if an error occurs while executing build steps
 * @throws CacheDirectoryCreationException if a new cache directory could not be created
 * @throws MainClassInferenceException if a main class could not be found
 * @throws InvalidGlobalConfigException if the global config file is invalid
 */
@TaskAction
public void buildDocker() throws IOException, BuildStepsExecutionException, CacheDirectoryCreationException, MainClassInferenceException, InvalidGlobalConfigException {
    Preconditions.checkNotNull(jibExtension);
    // Check deprecated parameters
    Path dockerExecutable = jibExtension.getDockerClient().getExecutablePath();
    boolean isDockerInstalled = dockerExecutable == null ? DockerClient.isDefaultDockerInstalled() : DockerClient.isDockerInstalled(dockerExecutable);
    if (!isDockerInstalled) {
        throw new GradleException(HelpfulSuggestions.forDockerNotInstalled(HELPFUL_SUGGESTIONS_PREFIX));
    }
    TaskCommon.disableHttpLogging();
    TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
    GradleProjectProperties projectProperties = GradleProjectProperties.getForProject(getProject(), getLogger(), tempDirectoryProvider, jibExtension.getConfigurationName().get());
    GlobalConfig globalConfig = GlobalConfig.readConfig();
    Future<Optional<String>> updateCheckFuture = TaskCommon.newUpdateChecker(projectProperties, globalConfig, getLogger());
    try {
        PluginConfigurationProcessor.createJibBuildRunnerForDockerDaemonImage(new GradleRawConfiguration(jibExtension), ignored -> java.util.Optional.empty(), projectProperties, globalConfig, new GradleHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX)).runBuild();
    } catch (InvalidAppRootException ex) {
        throw new GradleException("container.appRoot is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
    } catch (InvalidContainerizingModeException ex) {
        throw new GradleException("invalid value for containerizingMode: " + ex.getInvalidContainerizingMode(), ex);
    } catch (InvalidWorkingDirectoryException ex) {
        throw new GradleException("container.workingDirectory is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
    } catch (InvalidPlatformException ex) {
        throw new GradleException("from.platforms contains a platform configuration that is missing required values or has invalid values: " + ex.getMessage() + ": " + ex.getInvalidPlatform(), ex);
    } catch (InvalidContainerVolumeException ex) {
        throw new GradleException("container.volumes is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
    } catch (InvalidFilesModificationTimeException ex) {
        throw new GradleException("container.filesModificationTime should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or special keyword \"EPOCH_PLUS_SECOND\": " + ex.getInvalidFilesModificationTime(), ex);
    } catch (InvalidCreationTimeException ex) {
        throw new GradleException("container.creationTime should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or a special keyword (\"EPOCH\", " + "\"USE_CURRENT_TIMESTAMP\"): " + ex.getInvalidCreationTime(), ex);
    } catch (JibPluginExtensionException ex) {
        String extensionName = ex.getExtensionClass().getName();
        throw new GradleException("error running extension '" + extensionName + "': " + ex.getMessage(), ex);
    } catch (IncompatibleBaseImageJavaVersionException ex) {
        throw new GradleException(HelpfulSuggestions.forIncompatibleBaseImageJavaVersionForGradle(ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()), ex);
    } catch (InvalidImageReferenceException ex) {
        throw new GradleException(HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
    } catch (ExtraDirectoryNotFoundException ex) {
        throw new GradleException("extraDirectories.paths contain \"from\" directory that doesn't exist locally: " + ex.getPath(), ex);
    } finally {
        tempDirectoryProvider.close();
        TaskCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
        projectProperties.waitForLoggingThread();
    }
}
Also used : Path(java.nio.file.Path) BuildStepsExecutionException(com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException) InvalidAppRootException(com.google.cloud.tools.jib.plugins.common.InvalidAppRootException) MainClassInferenceException(com.google.cloud.tools.jib.plugins.common.MainClassInferenceException) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) InvalidPlatformException(com.google.cloud.tools.jib.plugins.common.InvalidPlatformException) TaskAction(org.gradle.api.tasks.TaskAction) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException) Future(java.util.concurrent.Future) DockerClient(com.google.cloud.tools.jib.docker.DockerClient) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) DefaultTask(org.gradle.api.DefaultTask) Path(java.nio.file.Path) TempDirectoryProvider(com.google.cloud.tools.jib.filesystem.TempDirectoryProvider) Nullable(javax.annotation.Nullable) InvalidGlobalConfigException(com.google.cloud.tools.jib.plugins.common.globalconfig.InvalidGlobalConfigException) ExtraDirectoryNotFoundException(com.google.cloud.tools.jib.plugins.common.ExtraDirectoryNotFoundException) PluginConfigurationProcessor(com.google.cloud.tools.jib.plugins.common.PluginConfigurationProcessor) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) HelpfulSuggestions(com.google.cloud.tools.jib.plugins.common.HelpfulSuggestions) IOException(java.io.IOException) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) GradleException(org.gradle.api.GradleException) InvalidWorkingDirectoryException(com.google.cloud.tools.jib.plugins.common.InvalidWorkingDirectoryException) Optional(java.util.Optional) Option(org.gradle.api.tasks.options.Option) InvalidContainerVolumeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerVolumeException) Preconditions(com.google.common.base.Preconditions) Nested(org.gradle.api.tasks.Nested) InvalidFilesModificationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidFilesModificationTimeException) IncompatibleBaseImageJavaVersionException(com.google.cloud.tools.jib.plugins.common.IncompatibleBaseImageJavaVersionException) InvalidCreationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidCreationTimeException) InvalidAppRootException(com.google.cloud.tools.jib.plugins.common.InvalidAppRootException) Optional(java.util.Optional) InvalidContainerVolumeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerVolumeException) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) ExtraDirectoryNotFoundException(com.google.cloud.tools.jib.plugins.common.ExtraDirectoryNotFoundException) InvalidFilesModificationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidFilesModificationTimeException) IncompatibleBaseImageJavaVersionException(com.google.cloud.tools.jib.plugins.common.IncompatibleBaseImageJavaVersionException) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) GradleException(org.gradle.api.GradleException) InvalidWorkingDirectoryException(com.google.cloud.tools.jib.plugins.common.InvalidWorkingDirectoryException) TempDirectoryProvider(com.google.cloud.tools.jib.filesystem.TempDirectoryProvider) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException) InvalidPlatformException(com.google.cloud.tools.jib.plugins.common.InvalidPlatformException) InvalidCreationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidCreationTimeException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with GlobalConfig

use of com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig in project jib by google.

the class BuildDockerMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    checkJibVersion();
    if (MojoCommon.shouldSkipJibExecution(this)) {
        return;
    }
    Path dockerExecutable = getDockerClientExecutable();
    boolean isDockerInstalled = dockerExecutable == null ? DockerClient.isDefaultDockerInstalled() : DockerClient.isDockerInstalled(dockerExecutable);
    if (!isDockerInstalled) {
        throw new MojoExecutionException(HelpfulSuggestions.forDockerNotInstalled(HELPFUL_SUGGESTIONS_PREFIX));
    }
    MavenSettingsProxyProvider.activateHttpAndHttpsProxies(getSession().getSettings(), getSettingsDecrypter());
    TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
    MavenProjectProperties projectProperties = MavenProjectProperties.getForProject(Preconditions.checkNotNull(descriptor), getProject(), getSession(), getLog(), tempDirectoryProvider, getInjectedPluginExtensions());
    Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
    try {
        GlobalConfig globalConfig = GlobalConfig.readConfig();
        updateCheckFuture = MojoCommon.newUpdateChecker(projectProperties, globalConfig, getLog());
        PluginConfigurationProcessor.createJibBuildRunnerForDockerDaemonImage(new MavenRawConfiguration(this), new MavenSettingsServerCredentials(getSession().getSettings(), getSettingsDecrypter()), projectProperties, globalConfig, new MavenHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX)).runBuild();
    } catch (InvalidAppRootException ex) {
        throw new MojoExecutionException("<container><appRoot> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
    } catch (InvalidContainerizingModeException ex) {
        throw new MojoExecutionException("invalid value for <containerizingMode>: " + ex.getInvalidContainerizingMode(), ex);
    } catch (InvalidWorkingDirectoryException ex) {
        throw new MojoExecutionException("<container><workingDirectory> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
    } catch (InvalidPlatformException ex) {
        throw new MojoExecutionException("<from><platforms> contains a platform configuration that is missing required values or has invalid values: " + ex.getMessage() + ": " + ex.getInvalidPlatform(), ex);
    } catch (InvalidContainerVolumeException ex) {
        throw new MojoExecutionException("<container><volumes> is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
    } catch (InvalidFilesModificationTimeException ex) {
        throw new MojoExecutionException("<container><filesModificationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or special keyword \"EPOCH_PLUS_SECOND\": " + ex.getInvalidFilesModificationTime(), ex);
    } catch (InvalidCreationTimeException ex) {
        throw new MojoExecutionException("<container><creationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or a special keyword (\"EPOCH\", " + "\"USE_CURRENT_TIMESTAMP\"): " + ex.getInvalidCreationTime(), ex);
    } catch (JibPluginExtensionException ex) {
        String extensionName = ex.getExtensionClass().getName();
        throw new MojoExecutionException("error running extension '" + extensionName + "': " + ex.getMessage(), ex);
    } catch (IncompatibleBaseImageJavaVersionException ex) {
        throw new MojoExecutionException(HelpfulSuggestions.forIncompatibleBaseImageJavaVersionForMaven(ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()), ex);
    } catch (InvalidImageReferenceException ex) {
        throw new MojoExecutionException(HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
    } catch (IOException | CacheDirectoryCreationException | MainClassInferenceException | InvalidGlobalConfigException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    } catch (BuildStepsExecutionException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex.getCause());
    } catch (ExtraDirectoryNotFoundException ex) {
        throw new MojoExecutionException("<extraDirectories><paths> contain \"from\" directory that doesn't exist locally: " + ex.getPath(), ex);
    } finally {
        tempDirectoryProvider.close();
        MojoCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
        projectProperties.waitForLoggingThread();
        getLog().info("");
    }
}
Also used : InvalidContainerVolumeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerVolumeException) GlobalConfig(com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig) ExtraDirectoryNotFoundException(com.google.cloud.tools.jib.plugins.common.ExtraDirectoryNotFoundException) InvalidFilesModificationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidFilesModificationTimeException) IncompatibleBaseImageJavaVersionException(com.google.cloud.tools.jib.plugins.common.IncompatibleBaseImageJavaVersionException) InvalidWorkingDirectoryException(com.google.cloud.tools.jib.plugins.common.InvalidWorkingDirectoryException) TempDirectoryProvider(com.google.cloud.tools.jib.filesystem.TempDirectoryProvider) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException) InvalidPlatformException(com.google.cloud.tools.jib.plugins.common.InvalidPlatformException) Path(java.nio.file.Path) InvalidAppRootException(com.google.cloud.tools.jib.plugins.common.InvalidAppRootException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Optional(java.util.Optional) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) BuildStepsExecutionException(com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException) IOException(java.io.IOException) InvalidGlobalConfigException(com.google.cloud.tools.jib.plugins.common.globalconfig.InvalidGlobalConfigException) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) InvalidCreationTimeException(com.google.cloud.tools.jib.plugins.common.InvalidCreationTimeException) MainClassInferenceException(com.google.cloud.tools.jib.plugins.common.MainClassInferenceException)

Aggregations

GlobalConfig (com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig)18 Optional (java.util.Optional)18 CacheDirectoryCreationException (com.google.cloud.tools.jib.api.CacheDirectoryCreationException)12 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)12 TempDirectoryProvider (com.google.cloud.tools.jib.filesystem.TempDirectoryProvider)12 BuildStepsExecutionException (com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException)12 ExtraDirectoryNotFoundException (com.google.cloud.tools.jib.plugins.common.ExtraDirectoryNotFoundException)12 IncompatibleBaseImageJavaVersionException (com.google.cloud.tools.jib.plugins.common.IncompatibleBaseImageJavaVersionException)12 InvalidAppRootException (com.google.cloud.tools.jib.plugins.common.InvalidAppRootException)12 InvalidContainerVolumeException (com.google.cloud.tools.jib.plugins.common.InvalidContainerVolumeException)12 InvalidContainerizingModeException (com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException)12 InvalidCreationTimeException (com.google.cloud.tools.jib.plugins.common.InvalidCreationTimeException)12 InvalidFilesModificationTimeException (com.google.cloud.tools.jib.plugins.common.InvalidFilesModificationTimeException)12 InvalidPlatformException (com.google.cloud.tools.jib.plugins.common.InvalidPlatformException)12 InvalidWorkingDirectoryException (com.google.cloud.tools.jib.plugins.common.InvalidWorkingDirectoryException)12 MainClassInferenceException (com.google.cloud.tools.jib.plugins.common.MainClassInferenceException)12 InvalidGlobalConfigException (com.google.cloud.tools.jib.plugins.common.globalconfig.InvalidGlobalConfigException)12 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)12 IOException (java.io.IOException)12 Path (java.nio.file.Path)12