|
22 | 22 | import com.google.cloud.tools.jib.cache.CacheMetadataCorruptedException; |
23 | 23 | import com.google.cloud.tools.jib.cache.Caches; |
24 | 24 | import com.google.common.collect.ImmutableList; |
25 | | -import com.google.common.util.concurrent.ListeningExecutorService; |
26 | | -import com.google.common.util.concurrent.MoreExecutors; |
27 | 25 | import java.io.IOException; |
28 | | -import java.util.Arrays; |
29 | | -import java.util.Collections; |
30 | 26 | import java.util.concurrent.ExecutionException; |
31 | | -import java.util.concurrent.Executors; |
32 | 27 |
|
33 | 28 | /** All the steps to build an image. */ |
34 | 29 | public class BuildImageSteps implements BuildSteps { |
@@ -91,121 +86,29 @@ public void run() |
91 | 86 | buildConfiguration.getBuildLogger().lifecycle(""); |
92 | 87 |
|
93 | 88 | 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(); |
209 | 112 | } |
210 | 113 | } |
211 | 114 |
|
|
0 commit comments