Skip to content

Commit

Permalink
QUARKUS-1490: Use BuildItem to enable use of TestContainers shared ne…
Browse files Browse the repository at this point in the history
…twork
  • Loading branch information
manstis committed Dec 1, 2021
1 parent d6d3a91 commit e19bb68
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public interface DevServicesDatasourceProvider {
RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName,
Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt port, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork);
OptionalInt port, LaunchMode launchMode, Optional<Duration> startupTimeout);

default boolean isDockerRequired() {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.datasource.deployment.spi;

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.deployment.annotations.BuildStep;

/**
* Marker used by {@link BuildStep}'s that launch TestContainers' containers to ensure that they join TestContainers shared network.
*/
public final class DevServicesUseTestContainersSharedNetworkBuildItem extends MultiBuildItem {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,4 @@ public class DevServicesBuildTimeConfig {
@ConfigItem
public OptionalInt port;

/**
* Whether this particular data source's container should join TestContainers Shared Network.
* <p>
* By default, the data source container will join Docker's default network.
*/
@ConfigItem(defaultValue = "false")
public boolean useTestContainersSharedNetwork;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProviderBuildItem;
import io.quarkus.datasource.deployment.spi.DevServicesUseTestContainersSharedNetworkBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem;
import io.quarkus.devservices.common.ConfigureUtil;
Expand All @@ -31,15 +32,16 @@ public class DB2DevServicesProcessor {

@BuildStep
DevServicesDatasourceProviderBuildItem setupDB2(
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem) {
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem,
Optional<DevServicesUseTestContainersSharedNetworkBuildItem> devServicesUseTestContainersSharedNetworkBuildItem) {
return new DevServicesDatasourceProviderBuildItem(DatabaseKind.DB2, new DevServicesDatasourceProvider() {
@Override
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork) {
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout) {
QuarkusDb2Container container = new QuarkusDb2Container(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork);
devServicesSharedNetworkBuildItem.isPresent(),
devServicesUseTestContainersSharedNetworkBuildItem.isPresent());
startupTimeout.ifPresent(container::withStartupTimeout);
container.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ DevServicesDatasourceProviderBuildItem setupDerby() {
@Override
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork) {
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout) {
try {
int port = fixedExposedPort.isPresent() ? fixedExposedPort.getAsInt()
: 1527 + (launchMode == LaunchMode.TEST ? 0 : 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ DevServicesDatasourceProviderBuildItem setupH2() {
@Override
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt port, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork) {
OptionalInt port, LaunchMode launchMode, Optional<Duration> startupTimeout) {
try {
final Server tcpServer = Server.createTcpServer("-tcpPort",
port.isPresent() ? String.valueOf(port.getAsInt()) : "0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProviderBuildItem;
import io.quarkus.datasource.deployment.spi.DevServicesUseTestContainersSharedNetworkBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem;
import io.quarkus.devservices.common.ConfigureUtil;
Expand All @@ -29,15 +30,16 @@ public class MariaDBDevServicesProcessor {

@BuildStep
DevServicesDatasourceProviderBuildItem setupMariaDB(
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem) {
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem,
Optional<DevServicesUseTestContainersSharedNetworkBuildItem> devServicesUseTestContainersSharedNetworkBuildItem) {
return new DevServicesDatasourceProviderBuildItem(DatabaseKind.MARIADB, new DevServicesDatasourceProvider() {
@Override
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork) {
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout) {
QuarkusMariaDBContainer container = new QuarkusMariaDBContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork);
devServicesSharedNetworkBuildItem.isPresent(),
devServicesUseTestContainersSharedNetworkBuildItem.isPresent());
startupTimeout.ifPresent(container::withStartupTimeout);
container.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProviderBuildItem;
import io.quarkus.datasource.deployment.spi.DevServicesUseTestContainersSharedNetworkBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem;
import io.quarkus.devservices.common.ConfigureUtil;
Expand All @@ -31,15 +32,16 @@ public class MSSQLDevServicesProcessor {

@BuildStep
DevServicesDatasourceProviderBuildItem setupMSSQL(
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem) {
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem,
Optional<DevServicesUseTestContainersSharedNetworkBuildItem> devServicesUseTestContainersSharedNetworkBuildItem) {
return new DevServicesDatasourceProviderBuildItem(DatabaseKind.MSSQL, new DevServicesDatasourceProvider() {
@Override
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork) {
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout) {
QuarkusMSSQLServerContainer container = new QuarkusMSSQLServerContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork);
devServicesSharedNetworkBuildItem.isPresent(),
devServicesUseTestContainersSharedNetworkBuildItem.isPresent());
startupTimeout.ifPresent(container::withStartupTimeout);
container.withPassword(password.orElse("Quarkuspassword1"));
additionalProperties.forEach(container::withUrlParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProviderBuildItem;
import io.quarkus.datasource.deployment.spi.DevServicesUseTestContainersSharedNetworkBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem;
import io.quarkus.devservices.common.ConfigureUtil;
Expand All @@ -28,15 +29,16 @@ public class MySQLDevServicesProcessor {

@BuildStep
DevServicesDatasourceProviderBuildItem setupMysql(
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem) {
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem,
Optional<DevServicesUseTestContainersSharedNetworkBuildItem> devServicesUseTestContainersSharedNetworkBuildItem) {
return new DevServicesDatasourceProviderBuildItem(DatabaseKind.MYSQL, new DevServicesDatasourceProvider() {
@Override
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork) {
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout) {
QuarkusMySQLContainer container = new QuarkusMySQLContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork);
devServicesSharedNetworkBuildItem.isPresent(),
devServicesUseTestContainersSharedNetworkBuildItem.isPresent());
startupTimeout.ifPresent(container::withStartupTimeout);
container.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProviderBuildItem;
import io.quarkus.datasource.deployment.spi.DevServicesUseTestContainersSharedNetworkBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem;
import io.quarkus.devservices.common.ConfigureUtil;
Expand All @@ -33,15 +34,16 @@ public class OracleDevServicesProcessor {

@BuildStep
DevServicesDatasourceProviderBuildItem setupOracle(
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem) {
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem,
Optional<DevServicesUseTestContainersSharedNetworkBuildItem> devServicesUseTestContainersSharedNetworkBuildItem) {
return new DevServicesDatasourceProviderBuildItem(DatabaseKind.ORACLE, new DevServicesDatasourceProvider() {
@Override
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork) {
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout) {
QuarkusOracleServerContainer container = new QuarkusOracleServerContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork);
devServicesSharedNetworkBuildItem.isPresent(),
devServicesUseTestContainersSharedNetworkBuildItem.isPresent());
startupTimeout.ifPresent(container::withStartupTimeout);
container.withUsername(username.orElse(DEFAULT_DATABASE_USER))
.withPassword(password.orElse(DEFAULT_DATABASE_PASSWORD))
Expand Down Expand Up @@ -110,4 +112,4 @@ public String getEffectiveJdbcUrl() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProviderBuildItem;
import io.quarkus.datasource.deployment.spi.DevServicesUseTestContainersSharedNetworkBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem;
import io.quarkus.devservices.common.ConfigureUtil;
Expand All @@ -28,15 +29,16 @@ public class PostgresqlDevServicesProcessor {

@BuildStep
DevServicesDatasourceProviderBuildItem setupPostgres(
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem) {
Optional<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem,
Optional<DevServicesUseTestContainersSharedNetworkBuildItem> devServicesUseTestContainersSharedNetworkBuildItem) {
return new DevServicesDatasourceProviderBuildItem(DatabaseKind.POSTGRESQL, new DevServicesDatasourceProvider() {
@Override
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout,
boolean useTestContainersSharedNetwork) {
OptionalInt fixedExposedPort, LaunchMode launchMode, Optional<Duration> startupTimeout) {
QuarkusPostgreSQLContainer container = new QuarkusPostgreSQLContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent(), useTestContainersSharedNetwork);
devServicesSharedNetworkBuildItem.isPresent(),
devServicesUseTestContainersSharedNetworkBuildItem.isPresent());
startupTimeout.ifPresent(container::withStartupTimeout);
container.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
Expand Down

0 comments on commit e19bb68

Please sign in to comment.