-
Notifications
You must be signed in to change notification settings - Fork 36
Description
Enhancement Description
Using Testcontainers with Podman requires some configuration and does not work out of the box.
Podman is a popular container runtime alternative to Docker, especially on RedHat based systems.
See the following links:
- https://java.testcontainers.org/supported_docker_environment/#podman
- https://podman-desktop.io/tutorial/testcontainers-with-podman
- https://stackoverflow.com/questions/71549856/testcontainers-with-podman-in-java-tests
Investigate if we can implement some heuristic to detect Podman and configure Testcontainers automatically.
Testcontainers has an SPI org.testcontainers.dockerclient.DockerClientProviderStrategy that can be implemented to customize the configuration of the docker client.
This would be an ad-hoc test dependency added explicitly by users in their projects.
Or, we could provide some utility that generates testcontainers.properties in the class-path.
This can be done with some Maven plugin/extension.
When Podman is used in rootless mode, Ryuk needs to be disabled. It can only be disabled with an environment variable:
TESTCONTAINERS_RYUK_DISABLED=true
This means that disabling Ryuk programmatically is challenging, we should do this only if "rootless" mode is the default.
We could use Maven to inject configuration to surefire and failsafe (via profile, or programmatically with a Maven extension) to define the value of the environment variable to point at a Maven property. That Maven property can be set programmatically before the test executions.
However this approach for IDEs that don't use Maven to execute the tests (E.g. IntelliJ)
Modifying the value of an environment variable in-flight is not pretty and should be avoided, see https://github.com/junit-pioneer/junit-pioneer/blob/ef5ccff6ea9b12b82698aee24e6661de13d242df/src/main/java/org/junitpioneer/jupiter/EnvironmentVariableUtils.java#L36.
We could also pre initialize the ResourceReaper instance to bypass the environment variable:
https://github.com/testcontainers/testcontainers-java/blob/7209ff67f85fa7ef80f3e2e7f9c08db57769fe1d/core/src/main/java/org/testcontainers/utility/ResourceReaper.java#L58
This would require reflection to modify a private field.
This hack can be implemented as part of the DockerClientProviderStrategy
implementation as the ResourceReaper
initialization happens after.