Skip to content

Commit

Permalink
fix: mark volumes to be cleaned up automatically
Browse files Browse the repository at this point in the history
Adds the labels required for Ryuk (and other cleanup mechanisms) to pick up
volumes and clean them up, similar to containers and networks.

Closes camunda-community-hub#656
  • Loading branch information
lenaschoenburg committed Mar 8, 2024
1 parent 59a479d commit 00c85a6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/src/main/java/io/zeebe/containers/ZeebeVolume.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@
import io.zeebe.containers.util.TinyContainer;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.UnaryOperator;
import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.ResourceReaper;

/**
* A simple wrapper to create Docker volumes which are managed by Testcontainers. The created object
Expand Down Expand Up @@ -160,9 +164,14 @@ public static ZeebeVolume newVolume() {
*/
public static ZeebeVolume newVolume(final UnaryOperator<CreateVolumeCmd> configurator) {
final DockerClient client = DockerClientFactory.instance().client();
try (final CreateVolumeCmd command = client.createVolumeCmd()) {
final Map<String, String> labels = new HashMap<>();
labels.putAll(DockerClientFactory.DEFAULT_LABELS);
//noinspection deprecation
labels.putAll(ResourceReaper.instance().getLabels());

try (final CreateVolumeCmd command = client.createVolumeCmd().withLabels(labels)) {
final CreateVolumeResponse response =
configurator.apply(command.withLabels(DockerClientFactory.DEFAULT_LABELS)).exec();
configurator.apply(command).exec();
return new ZeebeVolume(response.getName(), client);
}
}
Expand Down

0 comments on commit 00c85a6

Please sign in to comment.