Skip to content

Commit

Permalink
Modified RyukResourceReaper to register shutdown hook only when the v…
Browse files Browse the repository at this point in the history
…alue of new configuration property 'ryuk.container.shutdownhook' has been set to true (discussion testcontainers#7454).
  • Loading branch information
Alex Arana committed Apr 6, 2024
1 parent 5969b0f commit a0fcbdf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ subprojects {
apply plugin: 'checkstyle'

group = "org.testcontainers"
version = rootProject["testcontainers.version"]

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,20 @@ private synchronized void maybeStart() {

ryukContainer.start();

Runtime
.getRuntime()
.addShutdownHook(
new Thread(
DockerClientFactory.TESTCONTAINERS_THREAD_GROUP,
() -> {
this.dockerClient.killContainerCmd(this.ryukContainer.getContainerId())
.withSignal("SIGTERM")
.exec();
}
)
);
if (TestcontainersConfiguration.getInstance().isRyukShutdownHookEnabled()) {
Runtime
.getRuntime()
.addShutdownHook(
new Thread(
DockerClientFactory.TESTCONTAINERS_THREAD_GROUP,
() -> {
this.dockerClient.killContainerCmd(this.ryukContainer.getContainerId())
.withSignal("SIGTERM")
.exec();
}
)
);
}

CountDownLatch ryukScheduledLatch = new CountDownLatch(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public boolean isRyukPrivileged() {
return Boolean.parseBoolean(getEnvVarOrProperty("ryuk.container.privileged", "true"));
}

public boolean isRyukShutdownHookEnabled() {
return Boolean.parseBoolean(getEnvVarOrProperty("ryuk.container.shutdownhook", "false"));
}

@Deprecated
public String getRyukImage() {
return getImage(RYUK_IMAGE).asCanonicalNameString();
Expand Down

0 comments on commit a0fcbdf

Please sign in to comment.