diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml
index 37609ce1424..406483c2d45 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yaml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yaml
@@ -50,6 +50,7 @@ body:
- ToxiProxy
- Trino
- Vault
+ - YugabyteDB
validations:
required: true
- type: input
diff --git a/.github/ISSUE_TEMPLATE/enhancement.yaml b/.github/ISSUE_TEMPLATE/enhancement.yaml
index 2bbca5db3ae..2f543615dee 100644
--- a/.github/ISSUE_TEMPLATE/enhancement.yaml
+++ b/.github/ISSUE_TEMPLATE/enhancement.yaml
@@ -50,6 +50,7 @@ body:
- ToxiProxy
- Trino
- Vault
+ - YugabyteDB
validations:
required: true
- type: textarea
diff --git a/.github/ISSUE_TEMPLATE/feature.yaml b/.github/ISSUE_TEMPLATE/feature.yaml
index d29d0178c39..85c44eba697 100644
--- a/.github/ISSUE_TEMPLATE/feature.yaml
+++ b/.github/ISSUE_TEMPLATE/feature.yaml
@@ -50,6 +50,7 @@ body:
- ToxiProxy
- Trino
- Vault
+ - YugabyteDB
- New Module
- type: textarea
id: problem
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 095257df4c1..121b8ab4b46 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -258,6 +258,11 @@ updates:
schedule:
interval: "monthly"
open-pull-requests-limit: 10
+ - package-ecosystem: "gradle"
+ directory: "/modules/yugabytedb"
+ schedule:
+ interval: "monthly"
+ open-pull-requests-limit: 10
# Examples
- package-ecosystem: "gradle"
diff --git a/.github/labeler.yml b/.github/labeler.yml
index fcbe0744bd8..2aff606e27b 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -87,5 +87,7 @@
- modules/trino/**/*
"modules/vault":
- modules/vault/**/*
+"modules/yugabytedb":
+ - modules/yugabytedb/**/*
"type/docs":
- docs/**/*.md
diff --git a/docs/modules/databases/yugabytedb.md b/docs/modules/databases/yugabytedb.md
new file mode 100644
index 00000000000..4ab3436b57c
--- /dev/null
+++ b/docs/modules/databases/yugabytedb.md
@@ -0,0 +1,59 @@
+# YugabyteDB Module
+
+!!! note
+ This module is INCUBATING. While it is ready for use and operational in the current version of Testcontainers, it is possible that it may receive breaking changes in the future. See [our contributing guidelines](/contributing/#incubating-modules) for more information on our incubating modules policy.
+
+See [Database containers](./index.md) for documentation and usage that is common to all database container types.
+
+YugabyteDB supports two APIs.
+- Yugabyte Structured Query Language [YSQL](https://docs.yugabyte.com/latest/api/ysql/) is a fully-relational API that is built by the PostgreSQL code
+- Yugabyte Cloud Query Language [YCQL](https://docs.yugabyte.com/latest/api/ycql/) is a semi-relational SQL API that has its roots in the Cassandra Query Language
+
+## Usage example
+
+### YSQL API
+
+
+[Creating a YSQL container](../../../modules/yugabytedb/src/test/java/org/testcontainers/junit/yugabytedb/YugabyteDBYSQLTest.java) inside_block:creatingYSQLContainer
+
+
+
+
+[Starting a YSQL container](../../../modules/yugabytedb/src/test/java/org/testcontainers/junit/yugabytedb/YugabyteDBYSQLTest.java) inside_block:startingYSQLContainer
+
+
+
+### YCQL API
+
+
+[Creating a YCQL container](../../../modules/yugabytedb/src/test/java/org/testcontainers/junit/yugabytedb/YugabyteDBYCQLTest.java) inside_block:creatingYCQLContainer
+
+
+
+
+[Starting a YCQL container](../../../modules/yugabytedb/src/test/java/org/testcontainers/junit/yugabytedb/YugabyteDBYCQLTest.java) inside_block:startingYCQLContainer
+
+
+
+## Adding this module to your project dependencies
+
+Add the following dependency to your `pom.xml`/`build.gradle` file:
+
+=== "Gradle"
+ ```groovy
+ testImplementation "org.testcontainers:yugabytedb:{{latest_version}}"
+ ```
+=== "Maven"
+ ```xml
+
+ org.testcontainers
+ yugabytedb
+ {{latest_version}}
+ test
+
+ ```
+
+!!! hint
+ Adding this Testcontainers library JAR will not automatically add the Yugabytedb driver JAR to your project.
+ You should ensure that your project has the Yugabytedb driver as a dependency, if you plan on using it.
+ Refer to the driver page [YSQL](https://docs.yugabyte.com/latest/integrations/jdbc-driver/) and [YCQL](https://docs.yugabyte.com/latest/reference/drivers/ycql-client-drivers/) for instructions.
diff --git a/modules/yugabytedb/build.gradle b/modules/yugabytedb/build.gradle
new file mode 100644
index 00000000000..8d0ba6ca3d0
--- /dev/null
+++ b/modules/yugabytedb/build.gradle
@@ -0,0 +1,10 @@
+description = "Testcontainers :: JDBC :: YugabyteDB"
+
+dependencies {
+ api project(':jdbc')
+ testImplementation project(':jdbc-test')
+ // YCQL driver
+ testImplementation 'com.yugabyte:java-driver-core:4.6.0-yb-11'
+ // YSQL driver
+ testImplementation 'com.yugabyte:jdbc-yugabytedb:42.3.4'
+}
diff --git a/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYCQLContainer.java b/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYCQLContainer.java
new file mode 100644
index 00000000000..af20ef9e157
--- /dev/null
+++ b/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYCQLContainer.java
@@ -0,0 +1,167 @@
+package org.testcontainers.containers;
+
+import com.github.dockerjava.api.command.InspectContainerResponse;
+import org.testcontainers.containers.delegate.YugabyteDBYCQLDelegate;
+import org.testcontainers.containers.strategy.YugabyteDBYCQLWaitStrategy;
+import org.testcontainers.ext.ScriptUtils;
+import org.testcontainers.utility.DockerImageName;
+
+import java.net.InetSocketAddress;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Testcontainers implementation for YugabyteDB YCQL API.
+ *
+ * @author srinivasa-vasu
+ * @see YCQL API
+ */
+public class YugabyteDBYCQLContainer extends GenericContainer {
+
+ private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("yugabytedb/yugabyte");
+
+ private static final Integer YCQL_PORT = 9042;
+
+ private static final Integer MASTER_DASHBOARD_PORT = 7000;
+
+ private static final Integer TSERVER_DASHBOARD_PORT = 9000;
+
+ private static final String ENTRYPOINT = "bin/yugabyted start --background=false";
+
+ private static final String LOCAL_DC = "datacenter1";
+
+ private String keyspace;
+
+ private String username;
+
+ private String password;
+
+ private String initScript;
+
+ /**
+ * @param imageName image name
+ */
+ public YugabyteDBYCQLContainer(final String imageName) {
+ this(DockerImageName.parse(imageName));
+ }
+
+ /**
+ * @param imageName image name
+ */
+ public YugabyteDBYCQLContainer(final DockerImageName imageName) {
+ super(imageName);
+ imageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
+ withExposedPorts(YCQL_PORT, MASTER_DASHBOARD_PORT, TSERVER_DASHBOARD_PORT);
+ waitingFor(new YugabyteDBYCQLWaitStrategy(this).withStartupTimeout(Duration.ofSeconds(60)));
+ withCommand(ENTRYPOINT);
+ }
+
+ @Override
+ public Set getLivenessCheckPortNumbers() {
+ return Collections.singleton(getMappedPort(YCQL_PORT));
+ }
+
+ /**
+ * Configures the environment variables. Setting up these variables would create the
+ * custom objects. Setting {@link #withKeyspaceName(String)},
+ * {@link #withUsername(String)}, {@link #withPassword(String)} these parameters will
+ * initilaize the database with those custom values
+ */
+ @Override
+ protected void configure() {
+ addEnv("YCQL_KEYSPACE", keyspace);
+ addEnv("YCQL_USER", username);
+ addEnv("YCQL_PASSWORD", password);
+ }
+
+ /**
+ * @param initScript path of the initialization script file
+ * @return {@link YugabyteDBYCQLContainer} instance
+ */
+ public YugabyteDBYCQLContainer withInitScript(String initScript) {
+ this.initScript = initScript;
+ return this;
+ }
+
+ /**
+ * Setting this would create the keyspace
+ * @param keyspace keyspace
+ * @return {@link YugabyteDBYCQLContainer} instance
+ */
+ public YugabyteDBYCQLContainer withKeyspaceName(final String keyspace) {
+ this.keyspace = keyspace;
+ return this;
+ }
+
+ /**
+ * Setting this would create the custom user role
+ * @param username user name
+ * @return {@link YugabyteDBYCQLContainer} instance
+ */
+ public YugabyteDBYCQLContainer withUsername(final String username) {
+ this.username = username;
+ return this;
+ }
+
+ /**
+ * Setting this along with {@link #withUsername(String)} would enable authentication
+ * @param password password
+ * @return {@link YugabyteDBYCQLContainer} instance
+ */
+ public YugabyteDBYCQLContainer withPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ /**
+ * Executes the initilization script
+ * @param containerInfo containerInfo
+ */
+ @Override
+ protected void containerIsStarted(InspectContainerResponse containerInfo) {
+ if (this.initScript != null) {
+ ScriptUtils.runInitScript(new YugabyteDBYCQLDelegate(this), initScript);
+ }
+ }
+
+ /**
+ * Returns a {@link InetSocketAddress} representation of YCQL's contact point info
+ * @return contactpoint
+ */
+ public InetSocketAddress getContactPoint() {
+ return new InetSocketAddress(getHost(), getMappedPort(YCQL_PORT));
+ }
+
+ /**
+ * Returns the local datacenter name
+ * @return localdc name
+ */
+ public String getLocalDc() {
+ return LOCAL_DC;
+ }
+
+ /**
+ * Username getter method
+ * @return username
+ */
+ public String getUsername() {
+ return this.username;
+ }
+
+ /**
+ * Password getter method
+ * @return password
+ */
+ public String getPassword() {
+ return this.password;
+ }
+
+ /**
+ * Keyspace getter method
+ * @return keyspace
+ */
+ public String getKeyspace() {
+ return this.keyspace;
+ }
+}
diff --git a/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYSQLContainer.java b/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYSQLContainer.java
new file mode 100644
index 00000000000..290269dfe79
--- /dev/null
+++ b/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYSQLContainer.java
@@ -0,0 +1,150 @@
+package org.testcontainers.containers;
+
+import org.testcontainers.containers.strategy.YugabyteDBYSQLWaitStrategy;
+import org.testcontainers.utility.DockerImageName;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Testcontainers implementation for YugabyteDB YSQL API.
+ *
+ * @author srinivasa-vasu
+ * @see YSQL API
+ */
+
+public class YugabyteDBYSQLContainer extends JdbcDatabaseContainer {
+
+ private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("yugabytedb/yugabyte");
+
+ private static final Integer YSQL_PORT = 5433;
+
+ private static final Integer MASTER_DASHBOARD_PORT = 7000;
+
+ private static final Integer TSERVER_DASHBOARD_PORT = 9000;
+
+ private static final String JDBC_DRIVER_CLASS = "com.yugabyte.Driver";
+
+ private static final String JDBC_CONNECT_PREFIX = "jdbc:yugabytedb";
+
+ private static final String ENTRYPOINT = "bin/yugabyted start --background=false";
+
+ private String database = "yugabyte";
+
+ private String username = "yugabyte";
+
+ private String password = "yugabyte";
+
+ /**
+ * @param imageName image name
+ */
+ public YugabyteDBYSQLContainer(final String imageName) {
+ this(DockerImageName.parse(imageName));
+ }
+
+ /**
+ * @param imageName image name
+ */
+ public YugabyteDBYSQLContainer(final DockerImageName imageName) {
+ super(imageName);
+ imageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
+ withExposedPorts(YSQL_PORT, MASTER_DASHBOARD_PORT, TSERVER_DASHBOARD_PORT);
+ waitingFor(new YugabyteDBYSQLWaitStrategy(this).withStartupTimeout(Duration.ofSeconds(60)));
+ withCommand(ENTRYPOINT);
+ }
+
+ @Override
+ public Set getLivenessCheckPortNumbers() {
+ return Collections.singleton(getMappedPort(YSQL_PORT));
+ }
+
+ /**
+ * Configures the environment variables. Setting up these variables would create the
+ * custom objects. Setting {@link #withDatabaseName(String)},
+ * {@link #withUsername(String)}, {@link #withPassword(String)} these parameters will
+ * initilaize the database with those custom values
+ */
+
+ @Override
+ protected void configure() {
+ addEnv("YSQL_DB", database);
+ addEnv("YSQL_USER", username);
+ addEnv("YSQL_PASSWORD", password);
+ }
+
+ @Override
+ public String getDriverClassName() {
+ return JDBC_DRIVER_CLASS;
+ }
+
+ @Override
+ public String getJdbcUrl() {
+ return (
+ JDBC_CONNECT_PREFIX +
+ "://" +
+ getHost() +
+ ":" +
+ getMappedPort(YSQL_PORT) +
+ "/" +
+ database +
+ constructUrlParameters("?", "&")
+ );
+ }
+
+ @Override
+ public String getDatabaseName() {
+ return database;
+ }
+
+ @Override
+ public String getUsername() {
+ return username;
+ }
+
+ @Override
+ public String getPassword() {
+ return password;
+ }
+
+ @Override
+ public String getTestQueryString() {
+ return "SELECT 1";
+ }
+
+ /**
+ * Setting this would create the keyspace
+ * @param database database name
+ * @return {@link YugabyteDBYSQLContainer} instance
+ */
+
+ @Override
+ public YugabyteDBYSQLContainer withDatabaseName(final String database) {
+ this.database = database;
+ return this;
+ }
+
+ /**
+ * Setting this would create the custom user role
+ * @param username user name
+ * @return {@link YugabyteDBYSQLContainer} instance
+ */
+
+ @Override
+ public YugabyteDBYSQLContainer withUsername(final String username) {
+ this.username = username;
+ return this;
+ }
+
+ /**
+ * Setting this along with {@link #withUsername(String)} would enable authentication
+ * @param password password
+ * @return {@link YugabyteDBYSQLContainer} instance
+ */
+
+ @Override
+ public YugabyteDBYSQLContainer withPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+}
diff --git a/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYSQLContainerProvider.java b/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYSQLContainerProvider.java
new file mode 100644
index 00000000000..71d8b583448
--- /dev/null
+++ b/modules/yugabytedb/src/main/java/org/testcontainers/containers/YugabyteDBYSQLContainerProvider.java
@@ -0,0 +1,42 @@
+package org.testcontainers.containers;
+
+import org.testcontainers.jdbc.ConnectionUrl;
+import org.testcontainers.utility.DockerImageName;
+
+/**
+ * YugabyteDB YSQL (Structured Query Language) JDBC container provider
+ *
+ * @author srinivasa-vasu
+ */
+public class YugabyteDBYSQLContainerProvider extends JdbcDatabaseContainerProvider {
+
+ private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("yugabytedb/yugabyte");
+
+ private static final String DEFAULT_TAG = "2.14.4.0-b26";
+
+ private static final String NAME = "yugabyte";
+
+ private static final String USER_PARAM = "user";
+
+ private static final String PASSWORD_PARAM = "password";
+
+ @Override
+ public boolean supports(String databaseType) {
+ return databaseType.equals(NAME);
+ }
+
+ @Override
+ public JdbcDatabaseContainer newInstance() {
+ return newInstance(DEFAULT_TAG);
+ }
+
+ @Override
+ public JdbcDatabaseContainer newInstance(String tag) {
+ return new YugabyteDBYSQLContainer(DEFAULT_IMAGE_NAME.withTag(tag));
+ }
+
+ @Override
+ public JdbcDatabaseContainer newInstance(ConnectionUrl connectionUrl) {
+ return newInstanceFromConnectionUrl(connectionUrl, USER_PARAM, PASSWORD_PARAM);
+ }
+}
diff --git a/modules/yugabytedb/src/main/java/org/testcontainers/containers/delegate/AbstractYCQLDelegate.java b/modules/yugabytedb/src/main/java/org/testcontainers/containers/delegate/AbstractYCQLDelegate.java
new file mode 100644
index 00000000000..c0e566c7ecf
--- /dev/null
+++ b/modules/yugabytedb/src/main/java/org/testcontainers/containers/delegate/AbstractYCQLDelegate.java
@@ -0,0 +1,27 @@
+package org.testcontainers.containers.delegate;
+
+import org.testcontainers.delegate.DatabaseDelegate;
+
+/**
+ * An abstract delegate do-nothing class
+ *
+ * @author srinivasa-vasu
+ */
+public abstract class AbstractYCQLDelegate implements DatabaseDelegate {
+
+ @Override
+ public void execute(
+ String statement,
+ String scriptPath,
+ int lineNumber,
+ boolean continueOnError,
+ boolean ignoreFailedDrops
+ ) {
+ // do nothing
+ }
+
+ @Override
+ public void close() {
+ // do nothing
+ }
+}
diff --git a/modules/yugabytedb/src/main/java/org/testcontainers/containers/delegate/YugabyteDBYCQLDelegate.java b/modules/yugabytedb/src/main/java/org/testcontainers/containers/delegate/YugabyteDBYCQLDelegate.java
new file mode 100644
index 00000000000..e324679713b
--- /dev/null
+++ b/modules/yugabytedb/src/main/java/org/testcontainers/containers/delegate/YugabyteDBYCQLDelegate.java
@@ -0,0 +1,57 @@
+package org.testcontainers.containers.delegate;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.testcontainers.containers.Container.ExecResult;
+import org.testcontainers.containers.YugabyteDBYCQLContainer;
+import org.testcontainers.ext.ScriptUtils.UncategorizedScriptException;
+
+import java.util.Collection;
+
+/**
+ * Query execution delegate class for YCQL API to delegate init-script statements. This
+ * invokes the in-built ycqlsh cli within the container to execute the
+ * statements at one go. It is recommended to use frameworks such as liquibase to manage
+ * this requirement. This functionality is kept to address the initialization requirements
+ * from standalone services that can't leverage liquibase or something similar.
+ *
+ * @author srinivasa-vasu
+ * @see YugabyteDBYCQLContainer
+ */
+@RequiredArgsConstructor
+@Slf4j
+public final class YugabyteDBYCQLDelegate extends AbstractYCQLDelegate {
+
+ private static final String BIN_PATH = "/home/yugabyte/tserver/bin/ycqlsh";
+
+ private final YugabyteDBYCQLContainer container;
+
+ @Override
+ public void execute(
+ Collection statements,
+ String scriptPath,
+ boolean continueOnError,
+ boolean ignoreFailedDrops
+ ) {
+ try {
+ ExecResult result = container.execInContainer(
+ BIN_PATH,
+ "-u",
+ container.getUsername(),
+ "-p",
+ container.getPassword(),
+ "-k",
+ container.getKeyspace(),
+ "-e",
+ StringUtils.join(statements, ";")
+ );
+ if (result.getExitCode() != 0) {
+ throw new RuntimeException(result.getStderr());
+ }
+ } catch (Exception e) {
+ log.debug(e.getMessage(), e);
+ throw new UncategorizedScriptException(e.getMessage(), e);
+ }
+ }
+}
diff --git a/modules/yugabytedb/src/main/java/org/testcontainers/containers/strategy/YugabyteDBYCQLWaitStrategy.java b/modules/yugabytedb/src/main/java/org/testcontainers/containers/strategy/YugabyteDBYCQLWaitStrategy.java
new file mode 100644
index 00000000000..dd775564941
--- /dev/null
+++ b/modules/yugabytedb/src/main/java/org/testcontainers/containers/strategy/YugabyteDBYCQLWaitStrategy.java
@@ -0,0 +1,82 @@
+package org.testcontainers.containers.strategy;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.testcontainers.containers.Container.ExecResult;
+import org.testcontainers.containers.YugabyteDBYCQLContainer;
+import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;
+import org.testcontainers.containers.wait.strategy.WaitStrategyTarget;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess;
+
+/**
+ * Custom wait strategy for YCQL API.
+ *
+ *
+ * Though we can either use HTTP or PORT based wait strategy, when we create a custom
+ * keyspace/role, it gets executed asynchronously. As the wait on container.start() on a
+ * specific port wouldn't fully guarantee the custom object execution. It's better to
+ * check the DB status with this way with a smoke test query that uses the underlying
+ * custom objects and wait for the operation to complete.
+ *
+ * Though we can either use HTTP or PORT based wait strategy, when we create a custom
+ * database/role, it gets executed asynchronously. As the wait on container.start() on a
+ * specific port wouldn't fully guarantee the custom object execution. It's better to
+ * check the DB status with this way with a smoke test query that uses the underlying
+ * custom objects and wait for the operation to complete.
+ *