Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HSEARCH-4674 Use test containers #3796

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
84da276
HSEARCH-4674 Use test containers for Elasticsearch/OpenSearch
marko-bekhta Dec 1, 2022
51f0eb9
HSEARCH-4674 Use test containers for databases
marko-bekhta Dec 1, 2022
455a68c
HSEARCH-4674 Remove maven docker plugin
marko-bekhta Dec 1, 2022
3437731
HSEARCH-4674 Update groovy script to list containers
marko-bekhta Dec 2, 2022
a190982
HSEARCH-4674 Use image name/tag defined in pom files to start containers
marko-bekhta Dec 2, 2022
eeef0e2
HSEARCH-4674 Remove some redundant properties
marko-bekhta Dec 2, 2022
ad273a0
HSEARCH-4674 Change how spring receives properties for test execution
marko-bekhta Dec 6, 2022
36a3b09
HSEARCH-4674 Make batch test that doesn't use helpers aware of contai…
marko-bekhta Dec 6, 2022
12678bc
HSEARCH-4674 Make showcase and v5 tests aware of testcontainers
marko-bekhta Dec 7, 2022
8a8ff28
HSEARCH-4674 Make java modules tests aware of testcontainers
marko-bekhta Dec 7, 2022
bf018a3
HSEARCH-4674 Make documentation tests aware of testcontainers
marko-bekhta Dec 7, 2022
4a603cd
HSEARCH-4674 Use Dockerfiles to create database test containers
marko-bekhta Oct 19, 2023
8468eb1
HSEARCH-4674 Add dependabot config for dockerfiles
marko-bekhta Oct 19, 2023
4422c26
HSEARCH-4674 Simplify tests configuration
marko-bekhta Oct 23, 2023
e264052
HSEARCH-4674 Enable reusable testcontainers on CI
marko-bekhta Oct 24, 2023
a2ef989
HSEARCH-4674 Rework Elasticsearch/OpenSearch container integration
marko-bekhta Oct 24, 2023
642cf6b
HSEARCH-4674 Allow custom wait conditions for database containers
marko-bekhta Oct 26, 2023
bf4343b
HSEARCH-4674 Switch to IBM registry for DB2
marko-bekhta Nov 2, 2023
8918af4
HSEARCH-4674 Update comments on TestRunner classes
yrodiere Nov 7, 2023
9860481
HSEARCH-4674 Use groups for Docker updates in Dependabot config and G…
yrodiere Nov 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
registries:
dockerhub:
type: docker-registry
url: https://registry.hub.docker.com
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}
replaces-base: true
ibm:
type: docker-registry
url: https://icr.io
updates:
- package-ecosystem: "maven"
directory: "/"
Expand Down Expand Up @@ -99,3 +109,56 @@ updates:
# See https://github.com/dependabot/dependabot-core/issues/4028
# And, additionally, it is only for performance testing.
- dependency-name: "org.bsc.maven:maven-processor-plugin"
- package-ecosystem: "docker"
registries:
- dockerhub
- ibm
# For dependabot to find Docker files they all should be in the same directory.
# Dependabot is picking any files that has `dockerfile` in them.
#
# This includes only Ryuk container, hence we want it to be checked/updated at the same time when our regular java dependencies are updated
directory: "/build/container/"
schedule:
interval: "weekly"
day: "tuesday"
assignees: ["yrodiere"]
marko-bekhta marked this conversation as resolved.
Show resolved Hide resolved
groups:
# This group combines all build containers dependencies.
build-containers:
patterns:
# Include all:
- "*"
- package-ecosystem: "docker"
registries:
- dockerhub
# For dependabot to find Docker files they all should be in the same directory.
# Dependabot is picking any files that has `dockerfile` in them.
#
# This will only include database containers, hence we check for updates only once a month:
directory: "/build/container/database"
schedule:
interval: "monthly"
assignees: ["yrodiere"]
groups:
# This group combines all database containers dependencies.
database-containers:
patterns:
# Include all:
- "*"
- package-ecosystem: "docker"
registries:
- dockerhub
# For dependabot to find Docker files they all should be in the same directory.
# Dependabot is picking any files that has `dockerfile` in them.
directory: "/build/container/search-backend"
schedule:
interval: "daily"
assignees: ["yrodiere"]
groups:
# This group combines all search backends containers dependencies.
# We will still need to create specific tickets to address these updates and do some code changes,
# so we just want to get a notification from the bot that the new versions are available.
search-backend-containers:
patterns:
# Include all:
- "*"
11 changes: 5 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ on:
# we'll reject such dependant PRs and send a PR ourselves.
- '!dependabot/**'
- 'dependabot/maven/build-dependencies-**'
- 'dependabot/docker/build-containers-**'
- 'dependabot/docker/database-containers-**'

concurrency:
group: "workflow = ${{ github.workflow }}, ref = ${{ github.event.ref }}, pr = ${{ github.event.pull_request.id }}"
Expand Down Expand Up @@ -60,24 +62,21 @@ 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,
# so we can't run Elasticsearch tests.
# See https://github.com/actions/runner-images/issues/1143#issuecomment-972929995
# For some reason docker-maven-plugin will error out with "All pipe instances are busy"
# on GitHub Actions' Windows VMs (when using Bash?),
# so we also explicitly disable docker-maven-plugin.
# See https://github.com/fabric8io/docker-maven-plugin/issues/548#issuecomment-255477600
- {
name: "Windows JDK 17",
runs-on: 'windows-latest',
java: {
version: 17
},
maven: {
args: '-Dtest.elasticsearch.skip=true -Dtest.containers.run.skip=true'
args: '-Dtest.elasticsearch.skip=true'
yrodiere marked this conversation as resolved.
Show resolved Hide resolved
}
}
steps:
Expand Down
26 changes: 18 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ and run unit tests and integration tests.
```

Note: on Windows, you will need a Docker install able to run Linux containers.
If you don't have that, you can skip the Elasticsearch tests and all container startups:
`./mvnw clean install -Dtest.elasticsearch.skip=true -Dtest.containers.run.skip=true`.
If you don't have that, you can skip the Elasticsearch tests and only run tests against H2 database (without using DB containers):
`./mvnw clean install -Dtest.elasticsearch.skip=true`.

Note: the produced JARs are compatible with Java 8 and later,
regardless of the JDK used to build Hibernate Search.
Expand Down Expand Up @@ -346,12 +346,6 @@ you can skip all Elasticsearch tests (and thus the Elasticsearch container start
./mvnw clean install -Dtest.elasticsearch.skip=true
```

On Windows, you might need to also skip all docker container features:

```bash
./mvnw clean install -Dtest.elasticsearch.skip=true -Dtest.containers.run.skip=true
```

Alternatively, you can prevent the build from launching an Elasticsearch server automatically
and run Elasticsearch-related tests against your own server using the
`test.elasticsearch.connection.uris` property:
Expand Down Expand Up @@ -403,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
27 changes: 2 additions & 25 deletions 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 @@ -540,30 +541,6 @@ stage('Non-default environments') {
'''
String mavenDockerArgs = ""
def startedContainers = false
// DB2 setup is super slow (~5 to 15 minutes).
// We can't afford to do that once per module,
// so we start DB2 here, once and for all.
if ( buildEnv.dbName == 'db2' ) {
// Prevent the actual build from starting the DB container
mavenBuildAdditionalArgs += " -Dtest.database.run.db2.skip=true"
// Pick a module that doesn't normally execute the docker-maven-plugin,
// but that has the configuration necessary to start the DB container:
// that way, the maven-docker-plugin won't try to remove our container
// when we execute maven another time to run the tests.
// (This works because maven-docker-plugin filters containers to stop
// based on the Maven GAV coordinates of the Maven project that started that container,
// which are attached to the container thanks to a container label).
mavenDockerArgs = """ \
-pl build/parents/integrationtest \
-P$buildEnv.mavenProfile \
-Dtest.database.run.db2.skip=false \
"""
// Cleanup just in case some containers were left over from a previous build.
sh "mvn docker:stop $mavenDockerArgs"
pullContainerImages mavenDockerArgs
sh "mvn docker:start $mavenDockerArgs"
startedContainers = true
}
try {
mavenNonDefaultBuild buildEnv, """ \
-Pdist \
Expand Down Expand Up @@ -962,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
3 changes: 3 additions & 0 deletions build/container/database/cockroachdb.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CockroachDB
# See https://hub.docker.com/r/cockroachdb/cockroach/tags
FROM docker.io/cockroachdb/cockroach:v23.1.11
3 changes: 3 additions & 0 deletions build/container/database/db2.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DB2
# See https://icr.io/v2/db2_community/db2/tags/list
FROM icr.io/db2_community/db2:11.5.8.0
3 changes: 3 additions & 0 deletions build/container/database/mariadb.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# MariaDB
# See https://hub.docker.com/_/mariadb/tags
FROM docker.io/mariadb:11.1.2
3 changes: 3 additions & 0 deletions build/container/database/mssql.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# MS SQL Server
# See https://hub.docker.com/_/microsoft-mssql-server
FROM docker.io/mcr.microsoft.com/mssql/server:2022-CU9-ubuntu-20.04
3 changes: 3 additions & 0 deletions build/container/database/mysql.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# MySQL
# See https://hub.docker.com/_/mysql/tags
FROM docker.io/mysql:8.1.0
3 changes: 3 additions & 0 deletions build/container/database/oracle.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Oracle
# See https://hub.docker.com/r/gvenzl/oracle-free/tags
FROM docker.io/gvenzl/oracle-free:23.3-slim-faststart
3 changes: 3 additions & 0 deletions build/container/database/postgresql.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# PostgreSQL
# See https://hub.docker.com/_/postgres
FROM docker.io/postgres:16.0
5 changes: 0 additions & 5 deletions build/container/elasticsearch/env-7.10.properties

This file was deleted.

5 changes: 0 additions & 5 deletions build/container/elasticsearch/env-7.11.properties

This file was deleted.

5 changes: 0 additions & 5 deletions build/container/elasticsearch/env-7.12.properties

This file was deleted.

5 changes: 0 additions & 5 deletions build/container/elasticsearch/env-7.13.properties

This file was deleted.

5 changes: 0 additions & 5 deletions build/container/elasticsearch/env-7.14.properties

This file was deleted.

5 changes: 0 additions & 5 deletions build/container/elasticsearch/env-7.15.properties

This file was deleted.

7 changes: 0 additions & 7 deletions build/container/elasticsearch/env-7.16.properties

This file was deleted.

7 changes: 0 additions & 7 deletions build/container/elasticsearch/env-7.17.properties

This file was deleted.

8 changes: 0 additions & 8 deletions build/container/elasticsearch/env-8.0.properties

This file was deleted.

8 changes: 0 additions & 8 deletions build/container/elasticsearch/env-8.1.properties

This file was deleted.

10 changes: 0 additions & 10 deletions build/container/elasticsearch/env-8.10.properties

This file was deleted.

8 changes: 0 additions & 8 deletions build/container/elasticsearch/env-8.2.properties

This file was deleted.

8 changes: 0 additions & 8 deletions build/container/elasticsearch/env-8.3.properties

This file was deleted.

8 changes: 0 additions & 8 deletions build/container/elasticsearch/env-8.4.properties

This file was deleted.

8 changes: 0 additions & 8 deletions build/container/elasticsearch/env-8.5.properties

This file was deleted.

8 changes: 0 additions & 8 deletions build/container/elasticsearch/env-8.6.properties

This file was deleted.

8 changes: 0 additions & 8 deletions build/container/elasticsearch/env-8.7.properties

This file was deleted.

Loading
Loading