Skip to content

Commit

Permalink
HSEARCH-4674 Enable reusable testcontainers on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Nov 8, 2023
1 parent 4422c26 commit e264052
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ jobs:
version: 17
},
maven: {
args: ''
# Since we only start an Elasticsearch container on Linux we add the profile to enable container reuse here:
args: '-Pci-build'
}
}
# We can't start Linux containers on GitHub Actions' Windows VMs,
Expand Down
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,22 @@ Or more simply, if your AWS credentials are already stored in `~/.aws/credential
-Dtest.elasticsearch.connection.aws.region=<Your AWS region ID>
```

### Testcontainers

Hibernate Search uses Testcontainers in its integration tests.
By default, testcontainers are not reusable, i.e. a container is started at the beginning of an executed test suite,
and then stopped; each execution of failsafe plugin will start/stop their own containers as well as each test module.
With [reusable testcontainers](https://java.testcontainers.org/features/reuse/) required containers will start as needed
but will not be terminated, staying available between different failsafe executions and test modules
and even after the maven build is finished.
Reusable containers must be stopped manually, if needed (e.g. with `docker stop <container name>`
or `docker kill <container name>`).

There are a few ways to enable reusable testcontainers:

1. Enable reusable testcontainers in `~/.testcontainers.properties`, by adding `testcontainers.reuse.enable=true`
2. Build with `ci-build` Maven profile: `./mvnw clean install -Pci-build`

### JQAssistant

You can request static analysis and sanity checks with the `jqassistant` profile.
Expand Down
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ stage('Default build') {
${commonMavenArgs} \
-DskipSurefireTests \
-Pskip-checks \
-Pci-build \
-Pci-rebuild \
${incrementalBuild ? """ \
-Dincremental \
Expand Down Expand Up @@ -938,7 +939,7 @@ void mavenNonDefaultBuild(BuildEnvironment buildEnv, String args, List<String> a
def testSuffix = buildEnv.tag.replaceAll('[^a-zA-Z0-9_\\-+]+', '_')

sh """ \
mvn clean install -Dsurefire.environment=$testSuffix \
mvn clean install -Pci-build -Dsurefire.environment=$testSuffix \
${toTestJdkArg(buildEnv)} \
--fail-at-end \
$args \
Expand Down
7 changes: 7 additions & 0 deletions build/container/ryuk.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ryuk
# See https://hub.docker.com/r/testcontainers/ryuk/tags
#
# IMPORTANT! When updating the version for Ryuk in this Dockerfile,
# make sure to update `TESTCONTAINERS_RYUK_CONTAINER_IMAGE` env variable set as part of maven-failsafe-plugin configuration.
#
FROM docker.io/testcontainers/ryuk:0.5.1
30 changes: 30 additions & 0 deletions build/parents/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,17 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<environmentVariables>
<!-- Just to be sure that we are pulling/using the Ryuk from docker.io -->
<TESTCONTAINERS_RYUK_CONTAINER_IMAGE>docker.io/testcontainers/ryuk:0.5.1</TESTCONTAINERS_RYUK_CONTAINER_IMAGE>
<!--
Startup checks might want to test whether the images can be pulled (e.g. see `tinyimage.container.image` config property).
To prevent that and speedup the startup a bit the checks are disabled.
In case there are any issues, the checks can be enabled.
Also for debugging purposes consider enabling testcontainers debug logs (https://java.testcontainers.org/supported_docker_environment/logging_config/).
-->
<TESTCONTAINERS_CHECKS_DISABLE>true</TESTCONTAINERS_CHECKS_DISABLE>
</environmentVariables>
<systemPropertyVariables>
<org.hibernate.search.version>${project.version}</org.hibernate.search.version>
<org.hibernate.search.enable_performance_tests>${test.performance.enable}</org.hibernate.search.enable_performance_tests>
Expand Down Expand Up @@ -1311,6 +1322,25 @@
</build>

<profiles>
<profile>
<id>ci-build</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<environmentVariables>
<!-- To make Testcontainers reusable on CI, where ~/.testcontainers.properties is not necessarily defined -->
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<!-- Profile used when testing dependency updates on CI -->
<profile>
<id>dependency-update</id>
Expand Down
2 changes: 1 addition & 1 deletion ci/dependency-update/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pipeline {
withMavenWorkspace {
pullContainerImages()
sh """ \
mvn clean install -U -Pdependency-update -Pdist -Dsurefire.environment=${normalize(env.DEPENDENCY_UPDATE_NAME)} \
mvn clean install -U -Pdependency-update -Pdist -Pci-build -Dsurefire.environment=${normalize(env.DEPENDENCY_UPDATE_NAME)} \
--fail-at-end \
${env[qualify('ADDITIONAL_MAVEN_ARGS')]} \
"""
Expand Down
16 changes: 11 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -953,13 +953,19 @@
def images = []
def isTrueString = { string -> string && Boolean.parseBoolean( string ) }
def isNotBlankString = { string -> string?.trim() }
def parseImage = { file ->
{
def dockerFileContent = new File(file).text
if ((match = dockerFileContent =~ /FROM (.+)/)) {
return match.group(1).trim()
}
return ''
}
}
images += parseImage( './build/container/ryuk.Dockerfile' )
if ( isNotBlankString( '${test.database.run.kind}' ) && '${test.database.run.kind}' != 'h2') {
def dockerFileContent = new File('./build/container/${test.database.run.kind}.Dockerfile').text
if ((match = dockerFileContent =~ /FROM (.+)/)) {
def image = match.group(1).trim()
images += image
}
images += parseImage( './build/container/${test.database.run.kind}.Dockerfile' )
}
if ( isTrueString( '${test.elasticsearch.run.image.pull}' ) && isNotBlankString( '${test.elasticsearch.run.image.name}' ) ) {
images += '${test.elasticsearch.run.image.name}:${test.elasticsearch.run.image.tag}'
Expand Down

0 comments on commit e264052

Please sign in to comment.