diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesConfig.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesConfig.java index c10d481a5f84e..0a6fcb9c87206 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesConfig.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesConfig.java @@ -34,6 +34,33 @@ public class DevServicesConfig { @ConfigItem public OptionalInt port; + /** + * Indicates if the Redis server managed by Quarkus Dev Services is shared. + * When shared, Quarkus looks for running containers using label-based service discovery. + * If a matching container is found, it is used, and so a second one is not started. + * Otherwise, Dev Services for Redis starts a new container. + *
+ * The discovery uses the {@code quarkus-dev-service-redis} label. + * The value is configured using the {@code service-name} property. + *
+ * Container sharing is only used in dev mode. + */ + @ConfigItem(defaultValue = "true") + public boolean shared; + + /** + * The value of the {@code quarkus-dev-service-redis} label attached to the started container. + * This property is used when {@code shared} is set to {@code true}. + * In this case, before starting a container, Dev Services for Redis looks for a container with the + * {@code quarkus-dev-service-redis} label + * set to the configured value. If found, it will use this container instead of starting a new one. Otherwise it + * starts a new container with the {@code quarkus-dev-service-redis} label set to the specified value. + *
+ * This property is used when you need multiple shared Redis servers.
+ */
+ @ConfigItem(defaultValue = "redis")
+ public String serviceName;
+
@Override
public boolean equals(Object o) {
if (this == o)
@@ -43,11 +70,13 @@ public boolean equals(Object o) {
DevServicesConfig that = (DevServicesConfig) o;
return enabled == that.enabled &&
Objects.equals(imageName, that.imageName) &&
- Objects.equals(port, that.port);
+ Objects.equals(port, that.port) &&
+ Objects.equals(shared, that.shared) &&
+ Objects.equals(serviceName, that.serviceName);
}
@Override
public int hashCode() {
- return Objects.hash(enabled, imageName, port);
+ return Objects.hash(enabled, imageName, port, shared, serviceName);
}
}
diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesProcessor.java
index 3a2840336aa57..27755729cbdc6 100644
--- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesProcessor.java
+++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesProcessor.java
@@ -1,6 +1,7 @@
package io.quarkus.redis.client.deployment;
import static io.quarkus.redis.client.runtime.RedisClientUtil.isDefault;
+import static io.quarkus.runtime.LaunchMode.DEVELOPMENT;
import java.io.Closeable;
import java.util.ArrayList;
@@ -10,7 +11,10 @@
import java.util.Map.Entry;
import java.util.OptionalInt;
+import com.github.dockerjava.api.model.Container;
+import com.github.dockerjava.api.model.ContainerPort;
import org.jboss.logging.Logger;
+import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;
@@ -35,6 +39,13 @@ public class DevServicesProcessor {
private static final String REDIS_6_ALPINE = "redis:6-alpine";
private static final int REDIS_EXPOSED_PORT = 6379;
private static final String REDIS_SCHEME = "redis://";
+
+ /**
+ * Label to add to shared Dev Service for Redis running in containers.
+ * This allows other applications to discover the running service and use it instead of starting a new instance.
+ */
+ private static final String DEV_SERVICE_LABEL = "quarkus-dev-service-redis";
+
private static final String QUARKUS = "quarkus.";
private static final String DOT = ".";
private static volatile List