[12826] Configuring Postgres and MariaDb version

This commit is contained in:
nchopra 2022-07-15 14:21:31 +01:00 committed by Bruno Oliveira da Silva
parent 15a04021e0
commit 4fd3049c85
3 changed files with 20 additions and 5 deletions

View file

@ -104,4 +104,8 @@ These tests are disabled by default. They using Quarkus development mode predefi
mvn clean install -Dkc.test.storage.database=true -Dtest=MariaDBStartDatabaseTest
to spin up a MariaDB container and start Keycloak with it.
to spin up a MariaDB container and start Keycloak with it.
To use a specific database container image, use the option -Dkc.db.postgresql.container.image to specify the image tag of the postgres image to use or -Dkc.db.mariadb.container.image=<name:tag> for mariadb.
Example:
mvn clean install -Dkc.test.storage.database=true -Dtest=PostgreSQLDistTest -Dkc.db.postgresql.container.image=postgres:

View file

@ -116,9 +116,12 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1024m -XX:MaxMetaspaceSize=512m</argLine>
<systemProperties>
<systemPropertyVariables>
<kc.test.storage.database>true</kc.test.storage.database>
</systemProperties>
<!--DB Container -->
<kc.db.postgresql.container.image>postgres:alpine</kc.db.postgresql.container.image>
<kc.db.mariadb.container.image>mariadb:10.5.9</kc.db.mariadb.container.image>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>

View file

@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;
public class DatabaseContainer {
@ -66,11 +67,18 @@ public class DatabaseContainer {
}
private JdbcDatabaseContainer createContainer() {
String POSTGRES_IMAGE = System.getProperty("kc.db.postgresql.container.image");
String MARIADB_IMAGE = System.getProperty("kc.db.mariadb.container.image");
DockerImageName POSTGRES = DockerImageName.parse(POSTGRES_IMAGE).asCompatibleSubstituteFor("postgres");
DockerImageName MARIADB = DockerImageName.parse(MARIADB_IMAGE).asCompatibleSubstituteFor("mariadb");
switch (alias) {
case "postgres":
return new PostgreSQLContainer("postgres:alpine");
return new PostgreSQLContainer(POSTGRES);
case "mariadb":
return new MariaDBContainer("mariadb:10.5.9");
return new MariaDBContainer(MARIADB);
default:
throw new RuntimeException("Unsupported database: " + alias);
}