|
50 | 50 | import org.xwiki.test.integration.maven.MavenResolver;
|
51 | 51 | import org.xwiki.test.integration.maven.RepositoryResolver;
|
52 | 52 |
|
| 53 | +import com.github.dockerjava.api.command.InspectImageResponse; |
53 | 54 | import com.github.dockerjava.api.model.Image;
|
54 | 55 |
|
55 | 56 | import static java.time.temporal.ChronoUnit.SECONDS;
|
@@ -375,18 +376,39 @@ private String getDockerImageTag(TestConfiguration testConfiguration)
|
375 | 376 | : (testConfiguration.getServletEngine().equals(ServletEngine.TOMCAT) ? "9-jdk17" : LATEST);
|
376 | 377 | }
|
377 | 378 |
|
378 |
| - private GenericContainer<?> createServletContainer() throws Exception |
| 379 | + private String getDockerImageHash(TestConfiguration testConfiguration) |
| 380 | + { |
| 381 | + // Not using try-with-resources since the global docker client should never be closed (triggers an |
| 382 | + // IllegalStateException) |
| 383 | + InspectImageResponse inspectImageResponse = |
| 384 | + DockerClientFactory.instance().client().inspectImageCmd(getBaseImageName(testConfiguration)).exec(); |
| 385 | + String imageId = inspectImageResponse.getId(); |
| 386 | + String prefix = "sha256:"; |
| 387 | + if (imageId.startsWith(prefix)) { |
| 388 | + imageId = imageId.substring(prefix.length()); |
| 389 | + } |
| 390 | + return imageId; |
| 391 | + } |
| 392 | + |
| 393 | + private String getBaseImageName(TestConfiguration testConfiguration) |
379 | 394 | {
|
380 |
| - String baseImageName = String.format("%s:%s", |
| 395 | + return String.format("%s:%s", |
381 | 396 | this.testConfiguration.getServletEngine().getDockerImageName(), getDockerImageTag(this.testConfiguration));
|
| 397 | + } |
| 398 | + |
| 399 | + private GenericContainer<?> createServletContainer() throws Exception |
| 400 | + { |
| 401 | + String baseImageName = getBaseImageName(testConfiguration); |
| 402 | + LOGGER.info("Get base image name: {}", baseImageName); |
382 | 403 | GenericContainer<?> container;
|
383 | 404 |
|
384 | 405 | if (this.testConfiguration.isOffice()) {
|
385 | 406 | // We only build the image once for performance reason.
|
386 | 407 | // So we compute a name for the image we will build, and we check that the image does not exist yet.
|
387 |
| - String imageName = String.format("xwiki-%s-office:%s", |
| 408 | + String imageName = String.format("xwiki-%s-%s-office:%s", |
388 | 409 | this.testConfiguration.getServletEngine().name().toLowerCase(),
|
389 |
| - getDockerImageTag(this.testConfiguration)); |
| 410 | + getDockerImageTag(testConfiguration), |
| 411 | + getDockerImageHash(this.testConfiguration)); |
390 | 412 |
|
391 | 413 | // We rebuild every time the LibreOffice version changes
|
392 | 414 | String officeVersion = this.mavenResolver.getPropertyFromCurrentPOM("libreoffice.version");
|
|
0 commit comments