Skip to content

Commit 592d2c3

Browse files
committed
XWIKI-22796: Office tests are using outdated images
* Ensure to use image hash instead of image tag for the tag of built office images (cherry picked from commit 83a9cbf)
1 parent 383cec9 commit 592d2c3

File tree

1 file changed

+26
-4
lines changed
  • xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-docker/src/main/java/org/xwiki/test/docker/internal/junit5/servletengine

1 file changed

+26
-4
lines changed

xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-docker/src/main/java/org/xwiki/test/docker/internal/junit5/servletengine/ServletContainerExecutor.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.xwiki.test.integration.maven.MavenResolver;
5151
import org.xwiki.test.integration.maven.RepositoryResolver;
5252

53+
import com.github.dockerjava.api.command.InspectImageResponse;
5354
import com.github.dockerjava.api.model.Image;
5455

5556
import static java.time.temporal.ChronoUnit.SECONDS;
@@ -375,18 +376,39 @@ private String getDockerImageTag(TestConfiguration testConfiguration)
375376
: (testConfiguration.getServletEngine().equals(ServletEngine.TOMCAT) ? "9-jdk17" : LATEST);
376377
}
377378

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)
379394
{
380-
String baseImageName = String.format("%s:%s",
395+
return String.format("%s:%s",
381396
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);
382403
GenericContainer<?> container;
383404

384405
if (this.testConfiguration.isOffice()) {
385406
// We only build the image once for performance reason.
386407
// 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",
388409
this.testConfiguration.getServletEngine().name().toLowerCase(),
389-
getDockerImageTag(this.testConfiguration));
410+
getDockerImageTag(testConfiguration),
411+
getDockerImageHash(this.testConfiguration));
390412

391413
// We rebuild every time the LibreOffice version changes
392414
String officeVersion = this.mavenResolver.getPropertyFromCurrentPOM("libreoffice.version");

0 commit comments

Comments
 (0)