|
16 | 16 |
|
17 | 17 | package com.google.cloud.tools.jib.gradle; |
18 | 18 |
|
| 19 | +import com.google.api.client.http.HttpTransport; |
19 | 20 | import com.google.cloud.tools.jib.builder.BuildConfiguration; |
20 | 21 | import com.google.cloud.tools.jib.docker.DockerClient; |
21 | 22 | import com.google.cloud.tools.jib.frontend.BuildStepsExecutionException; |
|
25 | 26 | import com.google.cloud.tools.jib.http.Authorization; |
26 | 27 | import com.google.cloud.tools.jib.image.ImageReference; |
27 | 28 | import com.google.cloud.tools.jib.image.InvalidImageReferenceException; |
| 29 | +import com.google.cloud.tools.jib.registry.RegistryClient; |
28 | 30 | import com.google.cloud.tools.jib.registry.credentials.RegistryCredentials; |
29 | 31 | import com.google.common.base.Preconditions; |
| 32 | +import java.util.logging.Level; |
| 33 | +import java.util.logging.Logger; |
30 | 34 | import javax.annotation.Nullable; |
31 | 35 | import org.gradle.api.DefaultTask; |
32 | 36 | import org.gradle.api.GradleException; |
33 | 37 | import org.gradle.api.tasks.Nested; |
34 | 38 | import org.gradle.api.tasks.TaskAction; |
35 | 39 | import org.gradle.api.tasks.options.Option; |
| 40 | +import org.gradle.internal.logging.events.LogEvent; |
| 41 | +import org.gradle.internal.logging.events.OutputEventListener; |
| 42 | +import org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext; |
| 43 | +import org.slf4j.LoggerFactory; |
36 | 44 |
|
37 | 45 | /** Builds a container image and exports to the default Docker daemon. */ |
38 | 46 | public class BuildDockerTask extends DefaultTask { |
39 | 47 |
|
| 48 | + /** {@code User-Agent} header suffix to send to the registry. */ |
| 49 | + private static final String USER_AGENT_SUFFIX = "jib-gradle-plugin"; |
| 50 | + |
40 | 51 | private static final HelpfulSuggestions HELPFUL_SUGGESTIONS = |
41 | 52 | HelpfulSuggestionsProvider.get("Build to Docker daemon failed"); |
42 | 53 |
|
@@ -86,6 +97,26 @@ public void buildDocker() throws InvalidImageReferenceException { |
86 | 97 | .setJvmFlags(jibExtension.getJvmFlags()) |
87 | 98 | .build(); |
88 | 99 |
|
| 100 | + // TODO: Consolidate with BuildImageTask |
| 101 | + // TODO: Instead of disabling logging, have authentication credentials be provided |
| 102 | + // Disables annoying Apache HTTP client logging. |
| 103 | + // Note that this is a hack and depends on internal Gradle classes |
| 104 | + OutputEventListenerBackedLoggerContext context = |
| 105 | + (OutputEventListenerBackedLoggerContext) LoggerFactory.getILoggerFactory(); |
| 106 | + OutputEventListener defaultOutputEventListener = context.getOutputEventListener(); |
| 107 | + context.setOutputEventListener( |
| 108 | + event -> { |
| 109 | + LogEvent logEvent = (LogEvent) event; |
| 110 | + if (!logEvent.getCategory().contains("org.apache")) { |
| 111 | + defaultOutputEventListener.onOutput(event); |
| 112 | + } |
| 113 | + }); |
| 114 | + |
| 115 | + // Disables Google HTTP client logging. |
| 116 | + Logger.getLogger(HttpTransport.class.getName()).setLevel(Level.OFF); |
| 117 | + |
| 118 | + RegistryClient.setUserAgentSuffix(USER_AGENT_SUFFIX); |
| 119 | + |
89 | 120 | // Uses a directory in the Gradle build cache as the Jib cache. |
90 | 121 | try { |
91 | 122 | BuildStepsRunner.forBuildToDockerDaemon( |
|
0 commit comments