-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modules.cockroachdb) Adds cockroachdb module (#2131)
* modulegen cockroachdb init * start insecure crdb node * Method & options to docs * Use more standard naming for connection * Remove examples/cockroachdb * Cover changing default database * Drop ImageTag option to simplify * Set COCKROACH_DATABASE * Reduce API surface area * Supply user & password * Docs for password authn * Move to test-suite ahead of TLS * TLS support * Warn cant currently change user with TLS * Robust wait for by using SQL query Cockroach wasn't being consistent with log messages to use that as a reliable mechanism across the different authentication methods. This commit makes an actual SQL query to validate CRDB is correctly running. So we can make use of sql.DB driver and `wait.ForSQL` we've had to register a connection URL that includes TLS config, as there's no way to do that through standard connection strings. * Update docs/modules/cockroachdb.md Co-authored-by: Manuel de la Peña <[email protected]> * Use lifecycle to add TLS files * Bump pgx/v5 deps * Use clearer name for connection TLSConfig * Note about the possibility of a panic when starting * Update docs/modules/cockroachdb.md Co-authored-by: Manuel de la Peña <[email protected]> --------- Co-authored-by: Manuel de la Peña <[email protected]>
- Loading branch information
1 parent
8d33968
commit 7151628
Showing
18 changed files
with
823 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# CockroachDB | ||
|
||
Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
||
## Introduction | ||
|
||
The Testcontainers module for CockroachDB. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the CockroachDB module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/cockroachdb | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating a CockroachDB container](../../modules/cockroachdb/examples_test.go) inside_block:runCockroachDBContainer | ||
<!--/codeinclude--> | ||
|
||
## Module reference | ||
|
||
The CockroachDB module exposes one entrypoint function to create the CockroachDB container, and this function receives two parameters: | ||
|
||
```golang | ||
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CockroachDBContainer, error) | ||
``` | ||
|
||
- `context.Context`, the Go context. | ||
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
||
!!!warning | ||
When TLS is enabled there's a very small, unlikely chance that the underlying driver can panic when registering the driver as part of waiting for CockroachDB to be ready to accept connections. If this is repeatedly happening please open an issue. | ||
|
||
### Container Options | ||
|
||
When starting the CockroachDB container, you can pass options in a variadic way to configure it. | ||
|
||
#### Image | ||
|
||
If you need to set a different CockroachDB Docker image, you can use `testcontainers.WithImage` with a valid Docker image | ||
for CockroachDB. E.g. `testcontainers.WithImage("cockroachdb/cockroach:latest-v23.1")`. | ||
|
||
{% include "../features/common_functional_options.md" %} | ||
|
||
#### Database | ||
|
||
Set the database that is created & dialled with `cockroachdb.WithDatabase`. | ||
|
||
#### Password authentication | ||
|
||
Disable insecure mode and connect with password authentication by setting `cockroachdb.WithUser` and `cockroachdb.WithPassword`. | ||
|
||
#### Store size | ||
|
||
Control the maximum amount of memory used for storage, by default this is 100% but can be changed by provided a valid option to `WithStoreSize`. Checkout https://www.cockroachlabs.com/docs/stable/cockroach-start#store for the full range of options available. | ||
|
||
#### TLS authentication | ||
|
||
`cockroachdb.WithTLS` lets you provide the CA certificate along with the certicate and key for the node & clients to connect with. | ||
Internally CockroachDB requires a client certificate for the user to connect with. | ||
|
||
A helper `cockroachdb.NewTLSConfig` exists to generate all of this for you. | ||
|
||
### Container Methods | ||
|
||
The CockroachDB container exposes the following methods: | ||
|
||
#### ConnectionString | ||
|
||
Dial address to open a new connection. | ||
|
||
#### MustConnectionString | ||
|
||
Same as `ConnectionString` but any error to generate the address will raise a panic | ||
|
||
#### TLSConfig | ||
|
||
Returns `*tls.Config` setup to allow you to dial your client over TLS, if enabled, else this will error with `cockroachdb.ErrTLSNotEnabled`. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.