|
20 | 20 | import java.io.FileWriter;
|
21 | 21 | import java.io.IOException;
|
22 | 22 | import java.io.PrintWriter;
|
| 23 | +import java.time.Duration; |
23 | 24 | import java.util.ArrayList;
|
24 | 25 | import java.util.List;
|
25 | 26 | import java.util.function.Consumer;
|
@@ -262,7 +263,7 @@ void plainWarApp() throws Exception {
|
262 | 263 | writeServletInitializerClass();
|
263 | 264 | String imageName = "paketo-integration/" + this.gradleBuild.getProjectDir().getName();
|
264 | 265 | ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
|
265 |
| - BuildResult result = buildImage(imageName); |
| 266 | + BuildResult result = buildImageWithRetry(imageName); |
266 | 267 | assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
267 | 268 | try (GenericContainer<?> container = new GenericContainer<>(imageName)) {
|
268 | 269 | container.withExposedPorts(8080);
|
@@ -375,6 +376,30 @@ void classDataSharingApp() throws Exception {
|
375 | 376 | }
|
376 | 377 | }
|
377 | 378 |
|
| 379 | + private BuildResult buildImageWithRetry(String imageName, String... arguments) { |
| 380 | + long start = System.nanoTime(); |
| 381 | + while (true) { |
| 382 | + try { |
| 383 | + return buildImage(imageName, arguments); |
| 384 | + } |
| 385 | + catch (Exception ex) { |
| 386 | + if (Duration.ofNanos(System.nanoTime() - start).toMinutes() > 6) { |
| 387 | + throw ex; |
| 388 | + } |
| 389 | + sleep(500); |
| 390 | + } |
| 391 | + } |
| 392 | + } |
| 393 | + |
| 394 | + private void sleep(long time) { |
| 395 | + try { |
| 396 | + Thread.sleep(time); |
| 397 | + } |
| 398 | + catch (InterruptedException ex) { |
| 399 | + Thread.currentThread().interrupt(); |
| 400 | + } |
| 401 | + } |
| 402 | + |
378 | 403 | private BuildResult buildImage(String imageName, String... arguments) {
|
379 | 404 | String[] buildImageArgs = { "bootBuildImage", "--imageName=" + imageName, "--pullPolicy=IF_NOT_PRESENT" };
|
380 | 405 | String[] args = StringUtils.concatenateStringArrays(arguments, buildImageArgs);
|
|
0 commit comments