Skip to content

Commit

Permalink
Allow any image to be used in DevServices
Browse files Browse the repository at this point in the history
We trust the user that they have supplied an appropriate image.

Fixes quarkusio#15919
  • Loading branch information
stuartwdouglas authored and gsmet committed Mar 23, 2021
1 parent 3a8c2ea commit ad9be98
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Optional;

import org.testcontainers.containers.Db2Container;
import org.testcontainers.utility.DockerImageName;

import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
Expand All @@ -21,10 +22,11 @@ DevServicesDatasourceProviderBuildItem setupDB2() {
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties) {
Db2Container container = new Db2Container(
imageName.orElse("ibmcom/db2:" + Db2Container.DEFAULT_TAG))
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
DockerImageName.parse(imageName.orElse("ibmcom/db2:" + Db2Container.DEFAULT_TAG))
.asCompatibleSubstituteFor(DockerImageName.parse("ibmcom/db2")))
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
additionalProperties.forEach(container::withUrlParam);
container.start();
return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Optional;

import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.utility.DockerImageName;

import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
Expand All @@ -21,10 +22,11 @@ DevServicesDatasourceProviderBuildItem setupMariaDB() {
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties) {
MariaDBContainer container = new MariaDBContainer(
imageName.orElse(MariaDBContainer.IMAGE + ":" + MariaDBContainer.DEFAULT_TAG))
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
DockerImageName.parse(imageName.orElse(MariaDBContainer.IMAGE + ":" + MariaDBContainer.DEFAULT_TAG))
.asCompatibleSubstituteFor(DockerImageName.parse(MariaDBContainer.IMAGE)))
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
additionalProperties.forEach(container::withUrlParam);
container.start();
return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.utility.DockerImageName;

import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
Expand All @@ -22,8 +23,10 @@ DevServicesDatasourceProviderBuildItem setupMSSQL() {
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties) {
JdbcDatabaseContainer container = new MSSQLServerContainer(
imageName.orElse(MSSQLServerContainer.IMAGE + ":" + MSSQLServerContainer.DEFAULT_TAG))
.withPassword(password.orElse("Quarkuspassword1"));
DockerImageName
.parse(imageName.orElse(MSSQLServerContainer.IMAGE + ":" + MSSQLServerContainer.DEFAULT_TAG))
.asCompatibleSubstituteFor(MSSQLServerContainer.IMAGE))
.withPassword(password.orElse("Quarkuspassword1"));
additionalProperties.forEach(container::withUrlParam);
container.start();
return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Optional;

import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.utility.DockerImageName;

import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
Expand All @@ -21,10 +22,11 @@ DevServicesDatasourceProviderBuildItem setupMysql() {
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties) {
MySQLContainer container = new MySQLContainer(
imageName.orElse(MySQLContainer.IMAGE + ":" + MySQLContainer.DEFAULT_TAG))
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
DockerImageName.parse(imageName.orElse(MySQLContainer.IMAGE + ":" + MySQLContainer.DEFAULT_TAG))
.asCompatibleSubstituteFor(DockerImageName.parse(MySQLContainer.IMAGE)))
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
additionalProperties.forEach(container::withUrlParam);
container.start();
return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Optional;

import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceProvider;
Expand All @@ -14,17 +15,20 @@

public class PostgresqlDevServicesProcessor {

public static final String DEFAULT = PostgreSQLContainer.IMAGE + ":" + PostgreSQLContainer.DEFAULT_TAG;

@BuildStep
DevServicesDatasourceProviderBuildItem setupPostgres() {
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) {
PostgreSQLContainer container = new PostgreSQLContainer(
imageName.orElse(PostgreSQLContainer.IMAGE + ":" + PostgreSQLContainer.DEFAULT_TAG))
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
DockerImageName.parse(imageName.orElse(DEFAULT))
.asCompatibleSubstituteFor(DockerImageName.parse(PostgreSQLContainer.IMAGE)))
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
additionalProperties.forEach(container::withUrlParam);
container.start();
return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
Expand Down

0 comments on commit ad9be98

Please sign in to comment.