Skip to content

Commit ebc7507

Browse files
authored
Logs with new logging scheme at lifecycle level. (GoogleContainerTools#270)
1 parent 15fb6da commit ebc7507

22 files changed

Lines changed: 220 additions & 141 deletions

File tree

-379 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
4-
zipStorePath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
54
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/BuildAndCacheApplicationLayersStep.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ private ListenableFuture<CachedLayer> buildAndCacheLayerAsync(
8181

8282
return listeningExecutorService.submit(
8383
() -> {
84+
buildConfiguration.getBuildLogger().lifecycle(description + "...");
85+
8486
try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), description)) {
8587
// Don't build the layer if it exists already.
8688
CachedLayer cachedLayer =

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/BuildConfiguration.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ public BuildLogger getBuildLogger() {
222222
return buildLogger;
223223
}
224224

225+
public ImageReference getBaseImageReference() {
226+
return baseImageReference;
227+
}
228+
225229
public String getBaseImageRegistry() {
226230
return baseImageReference.getRegistry();
227231
}

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/BuildDockerSteps.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.common.util.concurrent.ListeningExecutorService;
3030
import com.google.common.util.concurrent.MoreExecutors;
3131
import java.io.IOException;
32+
import java.util.ArrayList;
3233
import java.util.List;
3334
import java.util.concurrent.ExecutionException;
3435
import java.util.concurrent.Executors;
@@ -68,6 +69,8 @@ public void run()
6869
buildConfiguration.getJvmFlags(),
6970
buildConfiguration.getMainClass());
7071

72+
buildConfiguration.getBuildLogger().lifecycle("");
73+
7174
try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
7275
try (Timer timer2 = timer.subTimer("Initializing cache")) {
7376
ListeningExecutorService listeningExecutorService =
@@ -134,6 +137,31 @@ public void run()
134137
entrypoint),
135138
listeningExecutorService);
136139

140+
// TODO: Move this somewhere that doesn't clutter this method. Consolidate with
141+
// BuildImageSteps.
142+
// Logs a message after pushing all the layers.
143+
Futures.whenAllSucceed(pullBaseImageLayerFuturesFuture)
144+
.call(
145+
() -> {
146+
// Depends on all the layers being pushed.
147+
List<ListenableFuture<?>> beforeFinalizing = new ArrayList<>();
148+
beforeFinalizing.addAll(
149+
NonBlockingFutures.get(pullBaseImageLayerFuturesFuture));
150+
beforeFinalizing.addAll(buildAndCacheApplicationLayerFutures);
151+
152+
Futures.whenAllSucceed(beforeFinalizing)
153+
.call(
154+
() -> {
155+
// TODO: Have this be more descriptive?
156+
buildConfiguration.getBuildLogger().lifecycle("Finalizing...");
157+
return null;
158+
},
159+
listeningExecutorService);
160+
161+
return null;
162+
},
163+
listeningExecutorService);
164+
137165
timer2.lap("Setting up build to docker daemon");
138166
// Builds the image tarball and loads into the Docker daemon.
139167
ListenableFuture<Void> buildToDockerFutureFuture =

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/BuildImageSteps.java‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.common.util.concurrent.ListeningExecutorService;
3131
import com.google.common.util.concurrent.MoreExecutors;
3232
import java.io.IOException;
33+
import java.util.ArrayList;
3334
import java.util.List;
3435
import java.util.concurrent.ExecutionException;
3536
import java.util.concurrent.Executors;
@@ -56,6 +57,10 @@ public BuildConfiguration getBuildConfiguration() {
5657
return buildConfiguration;
5758
}
5859

60+
public SourceFilesConfiguration getSourceFilesConfiguration() {
61+
return sourceFilesConfiguration;
62+
}
63+
5964
public void run()
6065
throws InterruptedException, ExecutionException, CacheMetadataCorruptedException, IOException,
6166
CacheDirectoryNotOwnedException {
@@ -65,6 +70,8 @@ public void run()
6570
buildConfiguration.getJvmFlags(),
6671
buildConfiguration.getMainClass());
6772

73+
buildConfiguration.getBuildLogger().lifecycle("");
74+
6875
try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
6976
try (Timer timer2 = timer.subTimer("Initializing cache")) {
7077
ListeningExecutorService listeningExecutorService =
@@ -170,14 +177,38 @@ public void run()
170177

171178
timer2.lap("Setting up application layer push");
172179
// Pushes the application layers.
173-
List<ListenableFuture<Void>> pushApplicationLayersFuture =
180+
List<ListenableFuture<Void>> pushApplicationLayersFutures =
174181
new PushLayersStep(
175182
buildConfiguration,
176183
listeningExecutorService,
177184
authenticatePushFuture,
178185
Futures.immediateFuture(buildAndCacheApplicationLayerFutures))
179186
.call();
180187

188+
// TODO: Move this somewhere that doesn't clutter this method.
189+
// Logs a message after pushing all the layers.
190+
Futures.whenAllSucceed(pushBaseImageLayerFuturesFuture)
191+
.call(
192+
() -> {
193+
// Depends on all the layers being pushed.
194+
List<ListenableFuture<?>> beforeFinalizing = new ArrayList<>();
195+
beforeFinalizing.addAll(
196+
NonBlockingFutures.get(pushBaseImageLayerFuturesFuture));
197+
beforeFinalizing.addAll(pushApplicationLayersFutures);
198+
199+
Futures.whenAllSucceed(beforeFinalizing)
200+
.call(
201+
() -> {
202+
// TODO: Have this be more descriptive?
203+
buildConfiguration.getBuildLogger().lifecycle("Finalizing...");
204+
return null;
205+
},
206+
listeningExecutorService);
207+
208+
return null;
209+
},
210+
listeningExecutorService);
211+
181212
timer2.lap("Setting up image manifest push");
182213
// Pushes the new image manifest.
183214
ListenableFuture<Void> pushImageFuture =
@@ -189,7 +220,7 @@ public void run()
189220
listeningExecutorService,
190221
authenticatePushFuture,
191222
pushBaseImageLayerFuturesFuture,
192-
pushApplicationLayersFuture,
223+
pushApplicationLayersFutures,
193224
pushContainerConfigurationFutureFuture,
194225
buildImageFutureFuture),
195226
listeningExecutorService);

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/PullBaseImageStep.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class PullBaseImageStep implements Callable<Image> {
5757
public Image call()
5858
throws IOException, RegistryException, LayerPropertyNotFoundException,
5959
LayerCountMismatchException, ExecutionException, InterruptedException {
60+
buildConfiguration
61+
.getBuildLogger()
62+
.lifecycle("Getting base image " + buildConfiguration.getBaseImageReference() + "...");
63+
6064
try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
6165
RegistryClient registryClient =
6266
new RegistryClient(

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/RetrieveRegistryCredentialsStep.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ private RetrieveRegistryCredentialsStep(
100100
@Override
101101
@Nullable
102102
public Authorization call() throws IOException, NonexistentDockerCredentialHelperException {
103+
buildLogger.lifecycle(String.format(DESCRIPTION, registry) + "...");
104+
103105
try (Timer ignored = new Timer(buildLogger, String.format(DESCRIPTION, registry))) {
104106
// Tries to get registry credentials from Docker credential helpers.
105107
if (credentialHelperSuffix != null) {

‎jib-core/src/main/java/com/google/cloud/tools/jib/frontend/BuildDockerStepsRunner.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import com.google.api.client.http.HttpStatusCodes;
2121
import com.google.cloud.tools.jib.builder.BuildConfiguration;
2222
import com.google.cloud.tools.jib.builder.BuildDockerSteps;
23+
import com.google.cloud.tools.jib.builder.BuildLogger;
2324
import com.google.cloud.tools.jib.builder.SourceFilesConfiguration;
2425
import com.google.cloud.tools.jib.cache.CacheDirectoryNotOwnedException;
2526
import com.google.cloud.tools.jib.cache.CacheMetadataCorruptedException;
2627
import com.google.cloud.tools.jib.cache.Caches;
28+
import com.google.cloud.tools.jib.image.ImageReference;
2729
import com.google.cloud.tools.jib.registry.RegistryAuthenticationFailedException;
2830
import com.google.cloud.tools.jib.registry.RegistryUnauthorizedException;
2931
import java.io.IOException;
@@ -91,8 +93,20 @@ public void buildDocker(HelpfulSuggestions helpfulSuggestions)
9193
BuildDockerSteps buildDockerSteps = buildDockerStepsSupplier.get();
9294

9395
try {
96+
BuildLogger buildLogger = buildDockerSteps.getBuildConfiguration().getBuildLogger();
97+
ImageReference targetImageReference =
98+
buildDockerSteps.getBuildConfiguration().getTargetImageReference();
99+
100+
buildLogger.lifecycle("");
101+
buildLogger.lifecycle("Building to Docker daemon as " + targetImageReference + "...");
102+
94103
buildDockerSteps.run();
95104

105+
buildLogger.lifecycle("");
106+
// targetImageReference in cyan.
107+
buildLogger.lifecycle(
108+
"Built image to Docker daemon as \u001B[36m" + targetImageReference + "\u001B[0m");
109+
96110
} catch (CacheMetadataCorruptedException cacheMetadataCorruptedException) {
97111
// TODO: Have this be different for Maven and Gradle.
98112
throw new BuildImageStepsExecutionException(

‎jib-core/src/main/java/com/google/cloud/tools/jib/frontend/BuildImageStepsRunner.java‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import com.google.api.client.http.HttpStatusCodes;
2121
import com.google.cloud.tools.jib.builder.BuildConfiguration;
2222
import com.google.cloud.tools.jib.builder.BuildImageSteps;
23+
import com.google.cloud.tools.jib.builder.BuildLogger;
2324
import com.google.cloud.tools.jib.builder.SourceFilesConfiguration;
2425
import com.google.cloud.tools.jib.cache.CacheDirectoryNotOwnedException;
2526
import com.google.cloud.tools.jib.cache.CacheMetadataCorruptedException;
2627
import com.google.cloud.tools.jib.cache.Caches;
28+
import com.google.cloud.tools.jib.image.ImageReference;
2729
import com.google.cloud.tools.jib.registry.RegistryAuthenticationFailedException;
2830
import com.google.cloud.tools.jib.registry.RegistryUnauthorizedException;
2931
import com.google.common.annotations.VisibleForTesting;
@@ -92,8 +94,42 @@ public void buildImage(HelpfulSuggestions helpfulSuggestions)
9294
BuildImageSteps buildImageSteps = buildImageStepsSupplier.get();
9395

9496
try {
97+
// TODO: This logging should be injected via another logging class.
98+
BuildLogger buildLogger = buildImageSteps.getBuildConfiguration().getBuildLogger();
99+
ImageReference targetImageReference =
100+
buildImageSteps.getBuildConfiguration().getTargetImageReference();
101+
102+
buildLogger.lifecycle("");
103+
buildLogger.lifecycle("Containerizing application to " + targetImageReference + "...");
104+
105+
// Logs the different source files used.
106+
buildLogger.info("Containerizing application with the following files:");
107+
108+
buildLogger.info("\tClasses:");
109+
buildImageSteps
110+
.getSourceFilesConfiguration()
111+
.getClassesFiles()
112+
.forEach(classesFile -> buildLogger.info("\t\t" + classesFile));
113+
114+
buildLogger.info("\tResources:");
115+
buildImageSteps
116+
.getSourceFilesConfiguration()
117+
.getResourcesFiles()
118+
.forEach(resourceFile -> buildLogger.info("\t\t" + resourceFile));
119+
120+
buildLogger.info("\tDependencies:");
121+
buildImageSteps
122+
.getSourceFilesConfiguration()
123+
.getDependenciesFiles()
124+
.forEach(dependencyFile -> buildLogger.info("\t\t" + dependencyFile));
125+
95126
buildImageSteps.run();
96127

128+
buildLogger.lifecycle("");
129+
// targetImageReference in cyan.
130+
buildLogger.lifecycle(
131+
"Built and pushed image as \u001B[36m" + targetImageReference + "\u001B[0m");
132+
97133
} catch (CacheMetadataCorruptedException cacheMetadataCorruptedException) {
98134
// TODO: Have this be different for Maven and Gradle.
99135
throw new BuildImageStepsExecutionException(

0 commit comments

Comments
 (0)