diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesSharedNetworkBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesSharedNetworkBuildItem.java index 68542d1b2813b..56de94e6edb04 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesSharedNetworkBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/DevServicesSharedNetworkBuildItem.java @@ -8,16 +8,41 @@ import io.quarkus.builder.BuildChainBuilder; import io.quarkus.builder.BuildStepBuilder; -import io.quarkus.builder.item.SimpleBuildItem; +import io.quarkus.builder.item.BuildItem; +import io.quarkus.builder.item.MultiBuildItem; import io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabled; /** - * A marker build item that if present during the build, then the containers started by DevServices - * will use a shared network. + * A marker build item that, if any instances are provided during the build, the containers started by DevServices + * will use a shared network and be accessible across the Docker network. The default is that containers started by + * DevServices will only be accessible from the Docker host. * This is mainly useful in integration tests where the application container needs to be able * to communicate with the services containers */ -public final class DevServicesSharedNetworkBuildItem extends SimpleBuildItem { +public final class DevServicesSharedNetworkBuildItem extends MultiBuildItem { + + private boolean exposeOnDockerHost; + + /** + * Construct the {@link BuildItem} exposing services only on the shared network. + */ + public DevServicesSharedNetworkBuildItem() { + this(false); + } + + /** + * Construct the {@link BuildItem} exposing services on both the shared network and Docker host. + * This is mainly used by {@see DevServicesKafkaProcessor}. + * + * @param exposeOnDockerHost + */ + public DevServicesSharedNetworkBuildItem(boolean exposeOnDockerHost) { + this.exposeOnDockerHost = exposeOnDockerHost; + } + + public boolean isExposedOnDockerHost() { + return exposeOnDockerHost; + } /** * Generates a {@link List> build chain builder} which creates a build step diff --git a/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java b/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java index d73f5bad48f0e..ae450b9c24993 100644 --- a/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java +++ b/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java @@ -1,7 +1,7 @@ package io.quarkus.apicurio.registry.avro; import java.time.Duration; -import java.util.Collections; +import java.util.List; import java.util.Objects; import java.util.Optional; @@ -9,8 +9,6 @@ import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.logging.Logger; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; -import org.testcontainers.utility.Base58; import org.testcontainers.utility.DockerImageName; import io.quarkus.deployment.IsDockerWorking; @@ -25,6 +23,7 @@ import io.quarkus.deployment.console.StartupLogCompressor; import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; import io.quarkus.deployment.logging.LoggingSetupBuildItem; +import io.quarkus.devservices.common.ConfigureUtil; import io.quarkus.devservices.common.ContainerLocator; import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.configuration.ConfigUtils; @@ -60,7 +59,7 @@ public class DevServicesApicurioRegistryProcessor { @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) public void startApicurioRegistryDevService(LaunchModeBuildItem launchMode, ApicurioRegistryDevServicesBuildTimeConfig apicurioRegistryDevServices, - Optional devServicesSharedNetworkBuildItem, + List devServicesSharedNetworkBuildItem, BuildProducer devServicesConfiguration, Optional consoleInstalledBuildItem, CuratedApplicationShutdownBuildItem closeBuildItem, @@ -82,7 +81,7 @@ public void startApicurioRegistryDevService(LaunchModeBuildItem launchMode, consoleInstalledBuildItem, loggingSetupBuildItem); try { apicurioRegistry = startApicurioRegistry(configuration, launchMode, - devServicesSharedNetworkBuildItem.isPresent(), devServicesConfig.timeout); + !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (apicurioRegistry == null) { compressor.close(); return; @@ -254,7 +253,7 @@ public int hashCode() { } private static final class ApicurioRegistryContainer extends GenericContainer { - private final int port; + private final int fixedExposedPort; private final boolean useSharedNetwork; private String hostName = null; @@ -262,15 +261,9 @@ private static final class ApicurioRegistryContainer extends GenericContainer 0 && !useSharedNetwork) { - addFixedExposedPort(port, APICURIO_REGISTRY_PORT); + + if (useSharedNetwork) { + hostName = ConfigureUtil.configureSharedNetwork(this, "kafka"); + return; + } + + if (fixedExposedPort > 0) { + addFixedExposedPort(fixedExposedPort, APICURIO_REGISTRY_PORT); + } else { + addExposedPorts(APICURIO_REGISTRY_PORT); } } diff --git a/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceProvider.java b/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceProvider.java index 69a0fe31bdb98..55cf064b852f4 100644 --- a/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceProvider.java +++ b/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceProvider.java @@ -13,8 +13,7 @@ public interface DevServicesDatasourceProvider { RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt port, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork); + OptionalInt port, LaunchMode launchMode, Optional startupTimeout); default boolean isDockerRequired() { return true; diff --git a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java index d39a388c54781..606f4b0e36dc7 100644 --- a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java +++ b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java @@ -267,8 +267,7 @@ private DevServicesDatasourceResultBuildItem.DbResult startDevDb(String dbName, ConfigProvider.getConfig().getOptionalValue(prefix + "password", String.class), Optional.ofNullable(dbName), dataSourceBuildTimeConfig.devservices.imageName, dataSourceBuildTimeConfig.devservices.properties, - dataSourceBuildTimeConfig.devservices.port, launchMode, globalDevServicesConfig.timeout, - dataSourceBuildTimeConfig.devservices.useTestContainersSharedNetwork); + dataSourceBuildTimeConfig.devservices.port, launchMode, globalDevServicesConfig.timeout); closeableList.add(datasource.getCloseTask()); propertiesMap.put(prefix + "db-kind", dataSourceBuildTimeConfig.dbKind.orElse(null)); diff --git a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java index 09aef269b15e0..62e422722c29c 100644 --- a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java +++ b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java @@ -55,12 +55,4 @@ public class DevServicesBuildTimeConfig { @ConfigItem public OptionalInt port; - /** - * Whether this particular data source's container should join TestContainers Shared Network. - *

- * By default, the data source container will join Docker's default network. - */ - @ConfigItem(defaultValue = "false") - public boolean useTestContainersSharedNetwork; - } diff --git a/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java b/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java index eecec7bb41b96..8e650a49a15c3 100644 --- a/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java +++ b/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java @@ -3,13 +3,13 @@ import java.io.Closeable; import java.io.IOException; import java.time.Duration; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalInt; import org.jboss.logging.Logger; import org.testcontainers.containers.Db2Container; -import org.testcontainers.containers.Network; import org.testcontainers.utility.DockerImageName; import io.quarkus.datasource.common.runtime.DatabaseKind; @@ -31,15 +31,14 @@ public class DB2DevServicesProcessor { @BuildStep DevServicesDatasourceProviderBuildItem setupDB2( - Optional devServicesSharedNetworkBuildItem) { + List devServicesSharedNetworkBuildItem) { return new DevServicesDatasourceProviderBuildItem(DatabaseKind.DB2, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork) { + OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout) { QuarkusDb2Container container = new QuarkusDb2Container(imageName, fixedExposedPort, - devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork); + !devServicesSharedNetworkBuildItem.isEmpty()); startupTimeout.ifPresent(container::withStartupTimeout); container.withPassword(password.orElse("quarkus")) .withUsername(username.orElse("quarkus")) @@ -69,15 +68,11 @@ private static class QuarkusDb2Container extends Db2Container { private String hostName = null; - public QuarkusDb2Container(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork, - boolean useTestContainersSharedNetwork) { + public QuarkusDb2Container(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork) { super(DockerImageName.parse(imageName.orElse("ibmcom/db2:" + DB2DevServicesProcessor.TAG)) .asCompatibleSubstituteFor(DockerImageName.parse("ibmcom/db2"))); this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; - if (useTestContainersSharedNetwork) { - withNetwork(Network.SHARED); - } } @Override @@ -91,6 +86,8 @@ protected void configure() { if (fixedExposedPort.isPresent()) { addFixedExposedPort(fixedExposedPort.getAsInt(), DB2_PORT); + } else { + addExposedPorts(DB2_PORT); } } diff --git a/extensions/devservices/derby/src/main/java/io/quarkus/devservices/derby/deployment/DerbyDevServicesProcessor.java b/extensions/devservices/derby/src/main/java/io/quarkus/devservices/derby/deployment/DerbyDevServicesProcessor.java index fe56b8b715b15..6e54a2f66072e 100644 --- a/extensions/devservices/derby/src/main/java/io/quarkus/devservices/derby/deployment/DerbyDevServicesProcessor.java +++ b/extensions/devservices/derby/src/main/java/io/quarkus/devservices/derby/deployment/DerbyDevServicesProcessor.java @@ -31,8 +31,7 @@ DevServicesDatasourceProviderBuildItem setupDerby() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork) { + OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout) { try { int port = fixedExposedPort.isPresent() ? fixedExposedPort.getAsInt() : 1527 + (launchMode == LaunchMode.TEST ? 0 : 1); diff --git a/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java b/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java index 690816cfdc986..b5b40af18706c 100644 --- a/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java +++ b/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java @@ -30,8 +30,7 @@ DevServicesDatasourceProviderBuildItem setupH2() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt port, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork) { + OptionalInt port, LaunchMode launchMode, Optional startupTimeout) { try { final Server tcpServer = Server.createTcpServer("-tcpPort", port.isPresent() ? String.valueOf(port.getAsInt()) : "0"); diff --git a/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java b/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java index 201172d171a11..4f0a25daed7c3 100644 --- a/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java +++ b/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java @@ -3,13 +3,13 @@ import java.io.Closeable; import java.io.IOException; import java.time.Duration; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalInt; import org.jboss.logging.Logger; import org.testcontainers.containers.MariaDBContainer; -import org.testcontainers.containers.Network; import org.testcontainers.utility.DockerImageName; import io.quarkus.datasource.common.runtime.DatabaseKind; @@ -29,15 +29,14 @@ public class MariaDBDevServicesProcessor { @BuildStep DevServicesDatasourceProviderBuildItem setupMariaDB( - Optional devServicesSharedNetworkBuildItem) { + List devServicesSharedNetworkBuildItem) { return new DevServicesDatasourceProviderBuildItem(DatabaseKind.MARIADB, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork) { + OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout) { QuarkusMariaDBContainer container = new QuarkusMariaDBContainer(imageName, fixedExposedPort, - devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork); + !devServicesSharedNetworkBuildItem.isEmpty()); startupTimeout.ifPresent(container::withStartupTimeout); container.withPassword(password.orElse("quarkus")) .withUsername(username.orElse("quarkus")) @@ -67,15 +66,11 @@ private static class QuarkusMariaDBContainer extends MariaDBContainer { private String hostName = null; - public QuarkusMariaDBContainer(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork, - boolean useTestContainersSharedNetwork) { + public QuarkusMariaDBContainer(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork) { super(DockerImageName.parse(imageName.orElse(MariaDBContainer.IMAGE + ":" + MariaDBDevServicesProcessor.TAG)) .asCompatibleSubstituteFor(DockerImageName.parse(MariaDBContainer.IMAGE))); this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; - if (useTestContainersSharedNetwork) { - withNetwork(Network.SHARED); - } } @Override @@ -89,6 +84,8 @@ protected void configure() { if (fixedExposedPort.isPresent()) { addFixedExposedPort(fixedExposedPort.getAsInt(), PORT); + } else { + addExposedPort(PORT); } } diff --git a/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java b/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java index a3dc2eccfbb4d..adbd64ef93a58 100644 --- a/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java +++ b/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java @@ -3,13 +3,13 @@ import java.io.Closeable; import java.io.IOException; import java.time.Duration; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalInt; import org.jboss.logging.Logger; import org.testcontainers.containers.MSSQLServerContainer; -import org.testcontainers.containers.Network; import org.testcontainers.utility.DockerImageName; import io.quarkus.datasource.common.runtime.DatabaseKind; @@ -31,15 +31,14 @@ public class MSSQLDevServicesProcessor { @BuildStep DevServicesDatasourceProviderBuildItem setupMSSQL( - Optional devServicesSharedNetworkBuildItem) { + List devServicesSharedNetworkBuildItem) { return new DevServicesDatasourceProviderBuildItem(DatabaseKind.MSSQL, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork) { + OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout) { QuarkusMSSQLServerContainer container = new QuarkusMSSQLServerContainer(imageName, fixedExposedPort, - devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork); + !devServicesSharedNetworkBuildItem.isEmpty()); startupTimeout.ifPresent(container::withStartupTimeout); container.withPassword(password.orElse("Quarkuspassword1")); additionalProperties.forEach(container::withUrlParam); @@ -67,16 +66,12 @@ private static class QuarkusMSSQLServerContainer extends MSSQLServerContainer { private String hostName = null; - public QuarkusMSSQLServerContainer(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork, - boolean useTestContainersSharedNetwork) { + public QuarkusMSSQLServerContainer(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork) { super(DockerImageName .parse(imageName.orElse(MSSQLServerContainer.IMAGE + ":" + MSSQLDevServicesProcessor.TAG)) .asCompatibleSubstituteFor(MSSQLServerContainer.IMAGE)); this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; - if (useTestContainersSharedNetwork) { - withNetwork(Network.SHARED); - } } @Override @@ -90,6 +85,8 @@ protected void configure() { if (fixedExposedPort.isPresent()) { addFixedExposedPort(fixedExposedPort.getAsInt(), MSSQLServerContainer.MS_SQL_SERVER_PORT); + } else { + addExposedPort(MS_SQL_SERVER_PORT); } } diff --git a/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java b/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java index e00700a9029bd..428340bc4d88f 100644 --- a/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java +++ b/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java @@ -3,13 +3,13 @@ import java.io.Closeable; import java.io.IOException; import java.time.Duration; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalInt; import org.jboss.logging.Logger; import org.testcontainers.containers.MySQLContainer; -import org.testcontainers.containers.Network; import org.testcontainers.utility.DockerImageName; import io.quarkus.datasource.common.runtime.DatabaseKind; @@ -28,15 +28,14 @@ public class MySQLDevServicesProcessor { @BuildStep DevServicesDatasourceProviderBuildItem setupMysql( - Optional devServicesSharedNetworkBuildItem) { + List devServicesSharedNetworkBuildItem) { return new DevServicesDatasourceProviderBuildItem(DatabaseKind.MYSQL, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork) { + OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout) { QuarkusMySQLContainer container = new QuarkusMySQLContainer(imageName, fixedExposedPort, - devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork); + !devServicesSharedNetworkBuildItem.isEmpty()); startupTimeout.ifPresent(container::withStartupTimeout); container.withPassword(password.orElse("quarkus")) .withUsername(username.orElse("quarkus")) @@ -66,15 +65,11 @@ private static class QuarkusMySQLContainer extends MySQLContainer { private String hostName = null; - public QuarkusMySQLContainer(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork, - boolean useTestContainersSharedNetwork) { + public QuarkusMySQLContainer(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork) { super(DockerImageName.parse(imageName.orElse(MySQLContainer.IMAGE + ":" + MySQLDevServicesProcessor.TAG)) .asCompatibleSubstituteFor(DockerImageName.parse(MySQLContainer.IMAGE))); this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; - if (useTestContainersSharedNetwork) { - withNetwork(Network.SHARED); - } } @Override @@ -88,6 +83,8 @@ protected void configure() { if (fixedExposedPort.isPresent()) { addFixedExposedPort(fixedExposedPort.getAsInt(), MySQLContainer.MYSQL_PORT); + } else { + addExposedPort(MYSQL_PORT); } } diff --git a/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java b/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java index dffa2f8b0e031..3fa22faf9b505 100644 --- a/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java +++ b/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java @@ -3,12 +3,12 @@ import java.io.Closeable; import java.io.IOException; import java.time.Duration; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalInt; import org.jboss.logging.Logger; -import org.testcontainers.containers.Network; import org.testcontainers.containers.OracleContainer; import org.testcontainers.utility.DockerImageName; @@ -33,15 +33,14 @@ public class OracleDevServicesProcessor { @BuildStep DevServicesDatasourceProviderBuildItem setupOracle( - Optional devServicesSharedNetworkBuildItem) { + List devServicesSharedNetworkBuildItem) { return new DevServicesDatasourceProviderBuildItem(DatabaseKind.ORACLE, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork) { + OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout) { QuarkusOracleServerContainer container = new QuarkusOracleServerContainer(imageName, fixedExposedPort, - devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork); + !devServicesSharedNetworkBuildItem.isEmpty()); startupTimeout.ifPresent(container::withStartupTimeout); container.withUsername(username.orElse(DEFAULT_DATABASE_USER)) .withPassword(password.orElse(DEFAULT_DATABASE_PASSWORD)) @@ -72,15 +71,12 @@ private static class QuarkusOracleServerContainer extends OracleContainer { private String hostName = null; public QuarkusOracleServerContainer(Optional imageName, OptionalInt fixedExposedPort, - boolean useSharedNetwork, boolean useTestContainersSharedNetwork) { + boolean useSharedNetwork) { super(DockerImageName .parse(imageName.orElse(OracleDevServicesProcessor.IMAGE + ":" + OracleDevServicesProcessor.TAG)) .asCompatibleSubstituteFor(OracleDevServicesProcessor.IMAGE)); this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; - if (useTestContainersSharedNetwork) { - withNetwork(Network.SHARED); - } } @Override @@ -93,7 +89,9 @@ protected void configure() { } if (fixedExposedPort.isPresent()) { - addFixedExposedPort(fixedExposedPort.getAsInt(), OracleDevServicesProcessor.PORT); + addFixedExposedPort(fixedExposedPort.getAsInt(), PORT); + } else { + addExposedPort(PORT); } } @@ -110,4 +108,4 @@ public String getEffectiveJdbcUrl() { } } } -} \ No newline at end of file +} diff --git a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java index f1965445fc05f..279ae17ce0c93 100644 --- a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java +++ b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java @@ -3,12 +3,12 @@ import java.io.Closeable; import java.io.IOException; import java.time.Duration; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalInt; import org.jboss.logging.Logger; -import org.testcontainers.containers.Network; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.utility.DockerImageName; @@ -28,15 +28,14 @@ public class PostgresqlDevServicesProcessor { @BuildStep DevServicesDatasourceProviderBuildItem setupPostgres( - Optional devServicesSharedNetworkBuildItem) { + List devServicesSharedNetworkBuildItem) { return new DevServicesDatasourceProviderBuildItem(DatabaseKind.POSTGRESQL, new DevServicesDatasourceProvider() { @Override public RunningDevServicesDatasource startDatabase(Optional username, Optional password, Optional datasourceName, Optional imageName, Map additionalProperties, - OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout, - boolean useTestContainersSharedNetwork) { + OptionalInt fixedExposedPort, LaunchMode launchMode, Optional startupTimeout) { QuarkusPostgreSQLContainer container = new QuarkusPostgreSQLContainer(imageName, fixedExposedPort, - devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork); + !devServicesSharedNetworkBuildItem.isEmpty()); startupTimeout.ifPresent(container::withStartupTimeout); container.withPassword(password.orElse("quarkus")) .withUsername(username.orElse("quarkus")) @@ -67,15 +66,11 @@ private static class QuarkusPostgreSQLContainer extends PostgreSQLContainer { private String hostName = null; - public QuarkusPostgreSQLContainer(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork, - boolean useTestContainersSharedNetwork) { + public QuarkusPostgreSQLContainer(Optional imageName, OptionalInt fixedExposedPort, boolean useSharedNetwork) { super(DockerImageName.parse(imageName.orElse(PostgreSQLContainer.IMAGE + ":" + PostgresqlDevServicesProcessor.TAG)) .asCompatibleSubstituteFor(DockerImageName.parse(PostgreSQLContainer.IMAGE))); this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; - if (useTestContainersSharedNetwork) { - withNetwork(Network.SHARED); - } } @Override @@ -89,6 +84,8 @@ protected void configure() { if (fixedExposedPort.isPresent()) { addFixedExposedPort(fixedExposedPort.getAsInt(), PostgreSQLContainer.POSTGRESQL_PORT); + } else { + addExposedPort(POSTGRESQL_PORT); } } diff --git a/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java b/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java index 549c14c796e10..129d117d5adf4 100644 --- a/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java +++ b/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java @@ -5,7 +5,6 @@ import java.io.Closeable; import java.time.Duration; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.OptionalInt; @@ -14,8 +13,6 @@ import org.infinispan.client.hotrod.impl.ConfigurationProperties; import org.infinispan.server.test.core.InfinispanContainer; import org.jboss.logging.Logger; -import org.testcontainers.containers.Network; -import org.testcontainers.utility.Base58; import io.quarkus.deployment.IsDockerWorking; import io.quarkus.deployment.IsNormal; @@ -29,6 +26,7 @@ import io.quarkus.deployment.console.StartupLogCompressor; import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; import io.quarkus.deployment.logging.LoggingSetupBuildItem; +import io.quarkus.devservices.common.ConfigureUtil; import io.quarkus.devservices.common.ContainerLocator; import io.quarkus.infinispan.client.deployment.InfinispanClientDevServiceBuildTimeConfig; import io.quarkus.runtime.LaunchMode; @@ -56,7 +54,7 @@ public class InfinispanDevServiceProcessor { @BuildStep(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class }) public void startInfinispanContainers(LaunchModeBuildItem launchMode, - Optional devServicesSharedNetworkBuildItem, + List devServicesSharedNetworkBuildItem, BuildProducer devConfigProducer, InfinispanClientDevServiceBuildTimeConfig config, Optional consoleInstalledBuildItem, CuratedApplicationShutdownBuildItem closeBuildItem, @@ -89,7 +87,7 @@ public void startInfinispanContainers(LaunchModeBuildItem launchMode, try { StartResult startResult = startContainer(config.devService.devservices, launchMode.getLaunchMode(), - devServicesSharedNetworkBuildItem.isPresent(), devServicesConfig.timeout); + !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (startResult == null) { compressor.close(); return; @@ -217,12 +215,7 @@ protected void configure() { super.configure(); if (useSharedNetwork) { - // When a shared network is requested for the launched containers, we need to configure - // the container to use it. We also need to create a hostname that will be applied to the returned - // Infinispan URL - setNetwork(Network.SHARED); - hostName = "infinispan-" + Base58.randomString(5); - setNetworkAliases(Collections.singletonList(hostName)); + hostName = ConfigureUtil.configureSharedNetwork(this, "infinispan"); return; } diff --git a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java index afb838d18e829..d42c2c74f0bb0 100644 --- a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java +++ b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java @@ -3,7 +3,7 @@ import java.io.Closeable; import java.nio.charset.StandardCharsets; import java.time.Duration; -import java.util.Collections; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,10 +26,8 @@ import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.logging.Logger; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.images.builder.Transferable; -import org.testcontainers.utility.Base58; import org.testcontainers.utility.DockerImageName; import com.github.dockerjava.api.command.InspectContainerResponse; @@ -46,6 +44,7 @@ import io.quarkus.deployment.console.StartupLogCompressor; import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; import io.quarkus.deployment.logging.LoggingSetupBuildItem; +import io.quarkus.devservices.common.ConfigureUtil; import io.quarkus.devservices.common.ContainerAddress; import io.quarkus.devservices.common.ContainerLocator; import io.quarkus.runtime.LaunchMode; @@ -78,7 +77,7 @@ public class DevServicesKafkaProcessor { public DevServicesKafkaBrokerBuildItem startKafkaDevService( LaunchModeBuildItem launchMode, KafkaBuildTimeConfig kafkaClientBuildTimeConfig, - Optional devServicesSharedNetworkBuildItem, + List devServicesSharedNetworkBuildItem, BuildProducer devServicePropertiesProducer, Optional consoleInstalledBuildItem, CuratedApplicationShutdownBuildItem closeBuildItem, @@ -101,7 +100,10 @@ public DevServicesKafkaBrokerBuildItem startKafkaDevService( consoleInstalledBuildItem, loggingSetupBuildItem); try { - kafkaBroker = startKafka(configuration, launchMode, devServicesSharedNetworkBuildItem.isPresent(), + kafkaBroker = startKafka(configuration, launchMode, + !devServicesSharedNetworkBuildItem.isEmpty(), + devServicesSharedNetworkBuildItem.stream() + .anyMatch(DevServicesSharedNetworkBuildItem::isExposedOnDockerHost), devServicesConfig.timeout); bootstrapServers = null; if (kafkaBroker != null) { @@ -200,7 +202,7 @@ private void shutdownBroker() { } private KafkaBroker startKafka(KafkaDevServiceCfg config, - LaunchModeBuildItem launchMode, boolean useSharedNetwork, Optional timeout) { + LaunchModeBuildItem launchMode, boolean useSharedNetwork, boolean exposeOnDockerHost, Optional timeout) { if (!config.devServicesEnabled) { // explicitly disabled log.debug("Not starting dev services for Kafka, as it has been disabled in the config."); @@ -235,7 +237,8 @@ private KafkaBroker startKafka(KafkaDevServiceCfg config, DockerImageName.parse(config.imageName), config.fixedExposedPort, launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT ? config.serviceName : null, - useSharedNetwork); + useSharedNetwork, + exposeOnDockerHost); timeout.ifPresent(container::withStartupTimeout); container.start(); @@ -338,24 +341,25 @@ public int hashCode() { */ private static final class RedPandaKafkaContainer extends GenericContainer { - private final int port; - private final String hostName; + private final Integer fixedExposedPort; private final boolean useSharedNetwork; + private final boolean exposeOnDockerHost; + + private String hostName = null; private static final String STARTER_SCRIPT = "/var/lib/redpanda/redpanda.sh"; private RedPandaKafkaContainer(DockerImageName dockerImageName, int fixedExposedPort, String serviceName, - boolean useSharedNetwork) { + boolean useSharedNetwork, boolean exposeOnDockerHost) { super(dockerImageName); - this.port = fixedExposedPort; - this.hostName = "kafka-" + Base58.randomString(5); + this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; - withNetwork(Network.SHARED); - withExposedPorts(KAFKA_PORT); - setNetworkAliases(Collections.singletonList(hostName)); + this.exposeOnDockerHost = exposeOnDockerHost; + if (serviceName != null) { // Only adds the label in dev mode. withLabel(DEV_SERVICE_LABEL, serviceName); } + // For redpanda, we need to start the broker - see https://vectorized.io/docs/quick-start-docker/ if (dockerImageName.getRepository().equals("vectorized/redpanda")) { withCreateContainerCmdModifier(cmd -> { @@ -376,11 +380,8 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole String command = "#!/bin/bash\n"; command += "/usr/bin/rpk redpanda start --check=false --node-id 0 --smp 1 "; command += "--memory 1G --overprovisioned --reserve-memory 0M "; - command += "--kafka-addr PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092 "; - command += String.format("--advertise-kafka-addr PLAINTEXT://%s:29092,OUTSIDE://%s:%d ", - hostName, - getHostToUse(), - getPortToUse()); + command += String.format("--kafka-addr %s ", getKafkaAddresses()); + command += String.format("--advertise-kafka-addr %s ", getKafkaAdvertisedAddresses()); //noinspection OctalInteger copyFileToContainer( @@ -388,24 +389,43 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole STARTER_SCRIPT); } + private String getKafkaAddresses() { + List addresses = new ArrayList<>(); + if (useSharedNetwork) { + addresses.add("PLAINTEXT://0.0.0.0:29092"); + } + if (exposeOnDockerHost || !useSharedNetwork) { + addresses.add("OUTSIDE://0.0.0.0:9092"); + } + return String.join(",", addresses); + } + + private String getKafkaAdvertisedAddresses() { + List addresses = new ArrayList<>(); + if (useSharedNetwork) { + addresses.add(String.format("PLAINTEXT://%s:29092", hostName)); + } + if (exposeOnDockerHost || !useSharedNetwork) { + addresses.add(String.format("OUTSIDE://%s:%d", getHost(), getMappedPort(KAFKA_PORT))); + } + return String.join(",", addresses); + } + @Override protected void configure() { super.configure(); - if ((port > 0) && !useSharedNetwork) { - addFixedExposedPort(port, KAFKA_PORT); + + addExposedPort(KAFKA_PORT); + hostName = ConfigureUtil.configureSharedNetwork(this, "kafka"); + + if (fixedExposedPort != null) { + addFixedExposedPort(fixedExposedPort, KAFKA_PORT); } } public String getBootstrapServers() { - return String.format("PLAINTEXT://%s:%d", getHostToUse(), getPortToUse()); - } - - private String getHostToUse() { - return useSharedNetwork ? hostName : getHost(); + return getKafkaAdvertisedAddresses(); } - private int getPortToUse() { - return useSharedNetwork ? KAFKA_PORT : getMappedPort(KAFKA_PORT); - } } } diff --git a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java index 85ba149af11bd..d7b2ab60da959 100644 --- a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java +++ b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java @@ -50,7 +50,7 @@ public class DevServicesMongoProcessor { @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class) public void startMongo(List mongoConnections, MongoClientBuildTimeConfig mongoClientBuildTimeConfig, - Optional devServicesSharedNetworkBuildItem, + List devServicesSharedNetworkBuildItem, BuildProducer devServices, Optional consoleInstalledBuildItem, CuratedApplicationShutdownBuildItem closeBuildItem, @@ -102,7 +102,7 @@ public void startMongo(List mongoConnections, loggingSetupBuildItem); try { startResult = startMongo(connectionName, currentCapturedProperties.get(connectionName), - devServicesSharedNetworkBuildItem.isPresent(), globalDevServicesConfig.timeout); + !devServicesSharedNetworkBuildItem.isEmpty(), globalDevServicesConfig.timeout); compressor.close(); } catch (Throwable t) { compressor.closeAndDumpCaptured(); @@ -314,6 +314,8 @@ protected void configure() { if (fixedExposedPort != null) { addFixedExposedPort(fixedExposedPort, MONGODB_INTERNAL_PORT); + } else { + addExposedPort(MONGODB_INTERNAL_PORT); } } diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java index 248179f41ab0b..cc85b295f192b 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java @@ -33,9 +33,7 @@ import org.keycloak.util.JsonSerialization; import org.testcontainers.containers.BindMode; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.utility.Base58; import org.testcontainers.utility.DockerImageName; import io.quarkus.deployment.IsDockerWorking; @@ -50,6 +48,7 @@ import io.quarkus.deployment.console.StartupLogCompressor; import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; import io.quarkus.deployment.logging.LoggingSetupBuildItem; +import io.quarkus.devservices.common.ConfigureUtil; import io.quarkus.devservices.common.ContainerAddress; import io.quarkus.devservices.common.ContainerLocator; import io.quarkus.oidc.deployment.OidcBuildStep.IsEnabled; @@ -118,7 +117,7 @@ public class KeycloakDevServicesProcessor { @BuildStep(onlyIfNot = IsNormal.class, onlyIf = { IsEnabled.class, GlobalDevServicesConfig.Enabled.class }) public KeycloakDevServicesConfigBuildItem startKeycloakContainer( - Optional devServicesSharedNetworkBuildItem, + List devServicesSharedNetworkBuildItem, BuildProducer devServices, Optional oidcProviderBuildItem, KeycloakBuildTimeConfig config, @@ -168,7 +167,7 @@ public KeycloakDevServicesConfigBuildItem startKeycloakContainer( (launchMode.isTest() ? "(test) " : "") + "KeyCloak Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem); try { - startResult = startContainer(devServicesSharedNetworkBuildItem.isPresent(), devServicesConfig.timeout); + startResult = startContainer(!devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (startResult == null) { compressor.close(); return null; @@ -383,13 +382,9 @@ public QuarkusOidcContainer(DockerImageName dockerImageName, OptionalInt fixedEx @Override protected void configure() { super.configure(); + if (useSharedNetwork) { - // When a shared network is requested for the launched containers, we need to configure - // the container to use it. We also need to create a hostname that will be applied to the returned - // Keycloak URL - setNetwork(Network.SHARED); - hostName = "keycloak-" + Base58.randomString(5); - setNetworkAliases(Collections.singletonList(hostName)); + hostName = ConfigureUtil.configureSharedNetwork(this, "keycloak"); } else { if (fixedExposedPort.isPresent()) { addFixedExposedPort(fixedExposedPort.getAsInt(), KEYCLOAK_PORT); diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java index 5c446cb9558e9..42384b1cb2e23 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java @@ -6,7 +6,6 @@ import java.io.Closeable; import java.time.Duration; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -17,8 +16,6 @@ import org.jboss.logging.Logger; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; -import org.testcontainers.utility.Base58; import org.testcontainers.utility.DockerImageName; import io.quarkus.deployment.IsDockerWorking.IsDockerRunningSilent; @@ -33,6 +30,7 @@ import io.quarkus.deployment.console.StartupLogCompressor; import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; import io.quarkus.deployment.logging.LoggingSetupBuildItem; +import io.quarkus.devservices.common.ConfigureUtil; import io.quarkus.devservices.common.ContainerLocator; import io.quarkus.redis.client.deployment.RedisBuildTimeConfig.DevServiceConfiguration; import io.quarkus.redis.client.runtime.RedisClientUtil; @@ -63,7 +61,7 @@ public class DevServicesRedisProcessor { @BuildStep(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class }) public void startRedisContainers(LaunchModeBuildItem launchMode, - Optional devServicesSharedNetworkBuildItem, + List devServicesSharedNetworkBuildItem, BuildProducer devConfigProducer, RedisBuildTimeConfig config, Optional consoleInstalledBuildItem, CuratedApplicationShutdownBuildItem closeBuildItem, @@ -102,7 +100,7 @@ public void startRedisContainers(LaunchModeBuildItem launchMode, String connectionName = entry.getKey(); StartResult startResult = startContainer(connectionName, entry.getValue().devservices, launchMode.getLaunchMode(), - devServicesSharedNetworkBuildItem.isPresent(), devServicesConfig.timeout); + !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (startResult == null) { continue; } @@ -217,6 +215,7 @@ public QuarkusPortRedisContainer(DockerImageName dockerImageName, OptionalInt fi super(dockerImageName); this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; + if (serviceName != null) { withLabel(DEV_SERVICE_LABEL, serviceName); } @@ -227,12 +226,7 @@ protected void configure() { super.configure(); if (useSharedNetwork) { - // When a shared network is requested for the launched containers, we need to configure - // the container to use it. We also need to create a hostname that will be applied to the returned - // Redis URL - setNetwork(Network.SHARED); - hostName = "redis-" + Base58.randomString(5); - setNetworkAliases(Collections.singletonList(hostName)); + hostName = ConfigureUtil.configureSharedNetwork(this, "redis"); return; }