Skip to content

Commit 7d40071

Browse files
authored
Moves AsyncStep construction to StepsRunner. (GoogleContainerTools#307)
1 parent dd0cb04 commit 7d40071

3 files changed

Lines changed: 267 additions & 199 deletions

File tree

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

Lines changed: 18 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@
2222
import com.google.cloud.tools.jib.cache.CacheMetadataCorruptedException;
2323
import com.google.cloud.tools.jib.cache.Caches;
2424
import com.google.common.collect.ImmutableList;
25-
import com.google.common.util.concurrent.ListeningExecutorService;
26-
import com.google.common.util.concurrent.MoreExecutors;
2725
import java.io.IOException;
28-
import java.util.Collections;
2926
import java.util.concurrent.ExecutionException;
30-
import java.util.concurrent.Executors;
3127

3228
/**
3329
* All the steps to build to Docker daemon.
@@ -94,81 +90,24 @@ public void run()
9490
buildConfiguration.getBuildLogger().lifecycle("");
9591

9692
try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
97-
try (Timer timer2 = timer.subTimer("Initializing cache")) {
98-
ListeningExecutorService listeningExecutorService =
99-
MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
100-
101-
try (Caches caches = cachesInitializer.init()) {
102-
Cache baseLayersCache = caches.getBaseCache();
103-
Cache applicationLayersCache = caches.getApplicationCache();
104-
105-
timer2.lap("Setting up credential retrieval");
106-
RetrieveRegistryCredentialsStep retrieveBaseRegistryCredentialsStep =
107-
RetrieveRegistryCredentialsStep.forBaseImage(
108-
listeningExecutorService, buildConfiguration);
109-
110-
timer2.lap("Setting up image pull authentication");
111-
// Authenticates base image pull.
112-
AuthenticatePullStep authenticatePullStep =
113-
new AuthenticatePullStep(
114-
listeningExecutorService,
115-
buildConfiguration,
116-
retrieveBaseRegistryCredentialsStep);
117-
118-
timer2.lap("Setting up base image pull");
119-
// Pulls the base image.
120-
PullBaseImageStep pullBaseImageStep =
121-
new PullBaseImageStep(
122-
listeningExecutorService, buildConfiguration, authenticatePullStep);
123-
124-
timer2.lap("Setting up base image layer pull");
125-
// Pulls and caches the base image layers.
126-
PullAndCacheBaseImageLayersStep pullAndCacheBaseImageLayersStep =
127-
new PullAndCacheBaseImageLayersStep(
128-
listeningExecutorService,
129-
buildConfiguration,
130-
baseLayersCache,
131-
authenticatePullStep,
132-
pullBaseImageStep);
133-
134-
timer2.lap("Setting up build application layers");
135-
// Builds the application layers.
136-
ImmutableList<BuildAndCacheApplicationLayerStep> buildAndCacheApplicationLayerSteps =
137-
BuildAndCacheApplicationLayerStep.makeList(
138-
listeningExecutorService,
139-
buildConfiguration,
140-
sourceFilesConfiguration,
141-
applicationLayersCache);
142-
143-
timer2.lap("Setting up build container configuration");
144-
// Builds the container configuration.
145-
BuildImageStep buildImageStep =
146-
new BuildImageStep(
147-
listeningExecutorService,
148-
buildConfiguration,
149-
pullAndCacheBaseImageLayersStep,
150-
buildAndCacheApplicationLayerSteps,
151-
entrypoint);
152-
153-
new FinalizingStep(
154-
listeningExecutorService,
155-
buildConfiguration,
156-
Collections.singletonList(pullAndCacheBaseImageLayersStep),
157-
buildAndCacheApplicationLayerSteps);
158-
159-
timer2.lap("Setting up build to docker daemon");
160-
// Builds the image tarball and loads into the Docker daemon.
161-
BuildTarballAndLoadDockerStep buildTarballAndLoadDockerStep =
162-
new BuildTarballAndLoadDockerStep(
163-
listeningExecutorService,
164-
buildConfiguration,
165-
pullAndCacheBaseImageLayersStep,
166-
buildAndCacheApplicationLayerSteps,
167-
buildImageStep);
168-
169-
timer2.lap("Running build to docker daemon");
170-
buildTarballAndLoadDockerStep.getFuture().get();
171-
}
93+
try (Caches caches = cachesInitializer.init()) {
94+
Cache baseLayersCache = caches.getBaseCache();
95+
Cache applicationLayersCache = caches.getApplicationCache();
96+
97+
new StepsRunner(
98+
buildConfiguration,
99+
sourceFilesConfiguration,
100+
baseLayersCache,
101+
applicationLayersCache)
102+
.runRetrieveBaseRegistryCredentialsStep()
103+
.runAuthenticatePullStep()
104+
.runPullBaseImageStep()
105+
.runPullAndCacheBaseImageLayersStep()
106+
.runBuildAndCacheApplicationLayerSteps()
107+
.runBuildImageStep(entrypoint)
108+
.runFinalizingBuildStep()
109+
.runBuildTarballAndLoadDockerStep()
110+
.waitOnBuildTarballAndLoadDockerStep();
172111
}
173112
}
174113

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

Lines changed: 23 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@
2222
import com.google.cloud.tools.jib.cache.CacheMetadataCorruptedException;
2323
import com.google.cloud.tools.jib.cache.Caches;
2424
import com.google.common.collect.ImmutableList;
25-
import com.google.common.util.concurrent.ListeningExecutorService;
26-
import com.google.common.util.concurrent.MoreExecutors;
2725
import java.io.IOException;
28-
import java.util.Arrays;
29-
import java.util.Collections;
3026
import java.util.concurrent.ExecutionException;
31-
import java.util.concurrent.Executors;
3227

3328
/** All the steps to build an image. */
3429
public class BuildImageSteps implements BuildSteps {
@@ -91,121 +86,29 @@ public void run()
9186
buildConfiguration.getBuildLogger().lifecycle("");
9287

9388
try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
94-
try (Timer timer2 = timer.subTimer("Initializing cache")) {
95-
ListeningExecutorService listeningExecutorService =
96-
MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
97-
98-
try (Caches caches = cachesInitializer.init()) {
99-
Cache baseLayersCache = caches.getBaseCache();
100-
Cache applicationLayersCache = caches.getApplicationCache();
101-
102-
timer2.lap("Setting up credential retrieval");
103-
RetrieveRegistryCredentialsStep retrieveTargetRegistryCredentialsStep =
104-
RetrieveRegistryCredentialsStep.forTargetImage(
105-
listeningExecutorService, buildConfiguration);
106-
RetrieveRegistryCredentialsStep retrieveBaseRegistryCredentialsStep =
107-
RetrieveRegistryCredentialsStep.forBaseImage(
108-
listeningExecutorService, buildConfiguration);
109-
110-
timer2.lap("Setting up image push authentication");
111-
// Authenticates push.
112-
AuthenticatePushStep authenticatePushStep =
113-
new AuthenticatePushStep(
114-
listeningExecutorService,
115-
buildConfiguration,
116-
retrieveTargetRegistryCredentialsStep);
117-
118-
timer2.lap("Setting up image pull authentication");
119-
// Authenticates base image pull.
120-
AuthenticatePullStep authenticatePullStep =
121-
new AuthenticatePullStep(
122-
listeningExecutorService,
123-
buildConfiguration,
124-
retrieveBaseRegistryCredentialsStep);
125-
126-
timer2.lap("Setting up base image pull");
127-
// Pulls the base image.
128-
PullBaseImageStep pullBaseImageStep =
129-
new PullBaseImageStep(
130-
listeningExecutorService, buildConfiguration, authenticatePullStep);
131-
132-
timer2.lap("Setting up base image layer pull");
133-
// Pulls and caches the base image layers.
134-
PullAndCacheBaseImageLayersStep pullAndCacheBaseImageLayersStep =
135-
new PullAndCacheBaseImageLayersStep(
136-
listeningExecutorService,
137-
buildConfiguration,
138-
baseLayersCache,
139-
authenticatePullStep,
140-
pullBaseImageStep);
141-
142-
timer2.lap("Setting up base image layer push");
143-
// Pushes the base image layers.
144-
PushLayersStep pushBaseImageLayersStep =
145-
new PushLayersStep(
146-
listeningExecutorService,
147-
buildConfiguration,
148-
authenticatePushStep,
149-
pullAndCacheBaseImageLayersStep);
150-
151-
timer2.lap("Setting up build application layers");
152-
// Builds the application layers.
153-
ImmutableList<BuildAndCacheApplicationLayerStep> buildAndCacheApplicationLayerSteps =
154-
BuildAndCacheApplicationLayerStep.makeList(
155-
listeningExecutorService,
156-
buildConfiguration,
157-
sourceFilesConfiguration,
158-
applicationLayersCache);
159-
160-
timer2.lap("Setting up build container configuration");
161-
// Builds the image model.
162-
BuildImageStep buildImageStep =
163-
new BuildImageStep(
164-
listeningExecutorService,
165-
buildConfiguration,
166-
pullAndCacheBaseImageLayersStep,
167-
buildAndCacheApplicationLayerSteps,
168-
entrypoint);
169-
170-
timer2.lap("Setting up container configuration push");
171-
// Pushes the container configuration.
172-
PushContainerConfigurationStep pushContainerConfigurationStep =
173-
new PushContainerConfigurationStep(
174-
listeningExecutorService,
175-
buildConfiguration,
176-
authenticatePushStep,
177-
buildImageStep);
178-
179-
timer2.lap("Setting up application layer push");
180-
// Pushes the application layers.
181-
PushLayersStep pushApplicationLayersStep =
182-
new PushLayersStep(
183-
listeningExecutorService,
184-
buildConfiguration,
185-
authenticatePushStep,
186-
AsyncSteps.immediate(buildAndCacheApplicationLayerSteps));
187-
188-
new FinalizingStep(
189-
listeningExecutorService,
190-
buildConfiguration,
191-
Arrays.asList(pushBaseImageLayersStep, pushApplicationLayersStep),
192-
Collections.emptyList());
193-
194-
timer2.lap("Setting up image manifest push");
195-
// Pushes the new image manifest.
196-
PushImageStep pushImageStep =
197-
new PushImageStep(
198-
listeningExecutorService,
199-
buildConfiguration,
200-
authenticatePushStep,
201-
pushBaseImageLayersStep,
202-
pushApplicationLayersStep,
203-
pushContainerConfigurationStep,
204-
buildImageStep);
205-
206-
timer2.lap("Running push new image");
207-
pushImageStep.getFuture().get();
208-
}
89+
try (Caches caches = cachesInitializer.init()) {
90+
Cache baseLayersCache = caches.getBaseCache();
91+
Cache applicationLayersCache = caches.getApplicationCache();
92+
93+
new StepsRunner(
94+
buildConfiguration,
95+
sourceFilesConfiguration,
96+
baseLayersCache,
97+
applicationLayersCache)
98+
.runRetrieveTargetRegistryCredentialsStep()
99+
.runRetrieveBaseRegistryCredentialsStep()
100+
.runAuthenticatePushStep()
101+
.runAuthenticatePullStep()
102+
.runPullBaseImageStep()
103+
.runPullAndCacheBaseImageLayersStep()
104+
.runPushBaseImageLayersStep()
105+
.runBuildAndCacheApplicationLayerSteps()
106+
.runBuildImageStep(entrypoint)
107+
.runPushContainerConfigurationStep()
108+
.runPushApplicationLayersStep()
109+
.runFinalizingPushStep()
110+
.runPushImageStep()
111+
.waitOnPushImageStep();
209112
}
210113
}
211114

0 commit comments

Comments
 (0)