|
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);
|
@@ -336,6 +337,30 @@ void nativeApp() throws Exception {
|
336 | 337 | }
|
337 | 338 | }
|
338 | 339 |
|
| 340 | + private BuildResult buildImageWithRetry(String imageName, String... arguments) { |
| 341 | + long start = System.nanoTime(); |
| 342 | + while (true) { |
| 343 | + try { |
| 344 | + return buildImage(imageName, arguments); |
| 345 | + } |
| 346 | + catch (Exception ex) { |
| 347 | + if (Duration.ofNanos(System.nanoTime() - start).toMinutes() > 6) { |
| 348 | + throw ex; |
| 349 | + } |
| 350 | + sleep(500); |
| 351 | + } |
| 352 | + } |
| 353 | + } |
| 354 | + |
| 355 | + private void sleep(long time) { |
| 356 | + try { |
| 357 | + Thread.sleep(time); |
| 358 | + } |
| 359 | + catch (InterruptedException ex) { |
| 360 | + Thread.currentThread().interrupt(); |
| 361 | + } |
| 362 | + } |
| 363 | + |
339 | 364 | private BuildResult buildImage(String imageName, String... arguments) {
|
340 | 365 | String[] buildImageArgs = { "bootBuildImage", "--imageName=" + imageName, "--pullPolicy=IF_NOT_PRESENT" };
|
341 | 366 | String[] args = StringUtils.concatenateStringArrays(arguments, buildImageArgs);
|
|
0 commit comments