Skip to content

Commit 1c2cd3b

Browse files
committed
Merge branch 'main' into fix-reuse-stopped-container
* main: feat(postgres): add WithOrderedInitScripts for Postgres testcontainers (testcontainers#3121) feat(redis): add TLS support (testcontainers#3115) feat: add Docker Model Runner module (testcontainers#3106) feat: add toxiproxy module (testcontainers#3092) chore(ci): run core tests on Testcontainers Cloud (testcontainers#3117) deps(aerospike): replace core module in go.mod (testcontainers#3116)
2 parents 18b92af + 66401ba commit 1c2cd3b

56 files changed

Lines changed: 3006 additions & 437 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ updates:
1414
directories:
1515
- /
1616
- /examples/nginx
17-
- /examples/toxiproxy
1817
- /modulegen
1918
- /modules/aerospike
2019
- /modules/arangodb
@@ -30,6 +29,7 @@ updates:
3029
- /modules/couchbase
3130
- /modules/databend
3231
- /modules/dind
32+
- /modules/dockermodelrunner
3333
- /modules/dolt
3434
- /modules/dynamodb
3535
- /modules/elasticsearch
@@ -67,6 +67,7 @@ updates:
6767
- /modules/scylladb
6868
- /modules/socat
6969
- /modules/surrealdb
70+
- /modules/toxiproxy
7071
- /modules/valkey
7172
- /modules/vault
7273
- /modules/vearch

.github/workflows/ci-test-go.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ on:
1818
type: string
1919
default: "."
2020
description: "The directory where the Go project is located."
21+
testcontainers-cloud:
22+
required: false
23+
type: boolean
24+
default: false
25+
description: "Run the tests on Testcontainers Cloud"
2126
rootless-docker:
2227
required: false
2328
type: boolean
@@ -81,6 +86,13 @@ jobs:
8186
echo "No dependencies script found at $SCRIPT_PATH - skipping installation"
8287
fi
8388
89+
# Setup Testcontainers Cloud Client right before your Testcontainers tests
90+
- name: Setup Testcontainers Cloud Client
91+
if: ${{ inputs.testcontainers-cloud }}
92+
uses: atomicjar/testcontainers-cloud-setup-action@c335bdbb570ec7c48f72c7d450c077f0a002293e # v1.3
93+
with:
94+
token: ${{ secrets.TCC_TOKEN }}
95+
8496
- name: go test
8597
working-directory: ./${{ inputs.project-directory }}
8698
timeout-minutes: 30
@@ -90,6 +102,13 @@ jobs:
90102
run: |
91103
./scripts/check_environment.sh
92104
105+
# (Optionally) When you don't need Testcontainers Cloud anymore, you could terminate sessions eagerly
106+
- name: Terminate Testcontainers Cloud Client active sessions
107+
if: ${{ inputs.testcontainers-cloud }}
108+
uses: atomicjar/testcontainers-cloud-setup-action@c335bdbb570ec7c48f72c7d450c077f0a002293e # v1.3
109+
with:
110+
action: terminate
111+
93112
- name: Test Summary
94113
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
95114
with:

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,31 @@ jobs:
7171
go-version: ${{ matrix.go-version }}
7272
platforms: ${{ matrix.module == 'modulegen' && '["ubuntu-latest", "macos-latest", "windows-latest"]' || '["ubuntu-latest"]' }}
7373
project-directory: "${{ matrix.module }}"
74+
testcontainers-cloud: false
7475
rootless-docker: false
7576
ryuk-disabled: false
7677
secrets: inherit
7778

79+
# The job below is a copy of the job above, but using Docker Cloud.
80+
test-testcontainers-cloud:
81+
# the core module is identified by the empty string (the root path)
82+
if: ${{ contains(fromJSON(needs.detect-modules.outputs.modules), '') }}
83+
needs:
84+
- detect-modules
85+
- lint
86+
name: "Test using Testcontainers Cloud"
87+
strategy:
88+
matrix:
89+
go-version: [1.23.x, 1.24.x]
90+
uses: ./.github/workflows/ci-test-go.yml
91+
with:
92+
go-version: ${{ matrix.go-version }}
93+
platforms: '["ubuntu-latest"]'
94+
project-directory: "."
95+
testcontainers-cloud: true
96+
rootless-docker: false
97+
ryuk-disabled: false
98+
7899
# The job below is a copy of the job above, but with ryuk disabled.
79100
# It's executed in the first stage to avoid concurrency issues.
80101
test-reaper-off:
@@ -92,6 +113,7 @@ jobs:
92113
go-version: ${{ matrix.go-version }}
93114
platforms: '["ubuntu-latest"]'
94115
project-directory: "."
116+
testcontainers-cloud: false
95117
rootless-docker: false
96118
ryuk-disabled: true
97119

@@ -112,6 +134,7 @@ jobs:
112134
go-version: ${{ matrix.go-version }}
113135
platforms: '["ubuntu-latest"]'
114136
project-directory: "."
137+
testcontainers-cloud: false
115138
rootless-docker: true
116139
ryuk-disabled: false
117140

.vscode/.testcontainers-go.code-workspace

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"path": "../examples/nginx"
1111
},
1212
{
13-
"name": "example / toxiproxy",
14-
"path": "../examples/toxiproxy"
13+
"name": "module / aerospike",
14+
"path": "../modules/aerospike"
1515
},
1616
{
1717
"name": "module / arangodb",
@@ -65,6 +65,10 @@
6565
"name": "module / dind",
6666
"path": "../modules/dind"
6767
},
68+
{
69+
"name": "module / dockermodelrunner",
70+
"path": "../modules/dockermodelrunner"
71+
},
6872
{
6973
"name": "module / dolt",
7074
"path": "../modules/dolt"
@@ -213,6 +217,10 @@
213217
"name": "module / surrealdb",
214218
"path": "../modules/surrealdb"
215219
},
220+
{
221+
"name": "module / toxiproxy",
222+
"path": "../modules/toxiproxy"
223+
},
216224
{
217225
"name": "module / valkey",
218226
"path": "../modules/valkey"

docs/examples/toxiproxy.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/modules/dockermodelrunner.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Docker Model Runner
2+
3+
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>
4+
5+
## Introduction
6+
7+
The Testcontainers module for DockerModelRunner.
8+
9+
## Adding this module to your project dependencies
10+
11+
Please run the following command to add the DockerModelRunner module to your Go dependencies:
12+
13+
```
14+
go get github.com/testcontainers/testcontainers-go/modules/dockermodelrunner
15+
```
16+
17+
## Usage example
18+
19+
<!--codeinclude-->
20+
[Creating a DockerModelRunner container](../../modules/dockermodelrunner/examples_test.go) inside_block:runWithModel
21+
<!--/codeinclude-->
22+
23+
## Module Reference
24+
25+
### Run function
26+
27+
- 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>
28+
29+
The Docker Model Runner module exposes two entrypoint functions to create the Docker Model Runner container:
30+
31+
#### Run
32+
33+
This function receives two parameters:
34+
35+
```golang
36+
func Run(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error)
37+
```
38+
39+
- `context.Context`, the Go context.
40+
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.
41+
42+
!!! info
43+
This function will use the default `socat` image under the hood. Please refer to the [socat module](../socat.md) for more information.
44+
45+
### Container Options
46+
47+
When starting the Docker Model Runner container, you can pass options in a variadic way to configure it.
48+
49+
#### Image
50+
51+
Use the second argument in the `Run` function to set a valid Docker image.
52+
In example: `Run(context.Background(), "alpine/socat:1.8.0.1")`.
53+
54+
{% include "../features/common_functional_options.md" %}
55+
56+
#### WithModel
57+
58+
- 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>
59+
60+
Use the `WithModel` option to set the model to pull when the container is started. Please be aware, that only Models as OCI Artifacts are compatible with Docker Model Runner.
61+
62+
```golang
63+
dockermodelrunner.WithModel("ai/llama3.2:latest")
64+
```
65+
66+
!!! warning
67+
Multiple calls to this function overrides the previous value.
68+
69+
You can find a curated collection of cutting-edge AI models as OCI Artifacts, from lightweight on-device models to high-performance LLMs on [Docker Hub](https://hub.docker.com/u/ai).
70+
71+
### Container Methods
72+
73+
The Docker Model Runner container exposes the following methods:
74+
75+
#### PullModel
76+
77+
- 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>
78+
79+
Use the `PullModel` method to pull a model from the Docker Model Runner.
80+
81+
<!--codeinclude-->
82+
[Pulling a model at runtime](../../modules/dockermodelrunner/examples_test.go) inside_block:runPullModel
83+
<!--/codeinclude-->
84+
85+
!!! info
86+
You can find a curated collection of cutting-edge AI models as OCI Artifacts, from lightweight on-device models to high-performance LLMs on [Docker Hub](https://hub.docker.com/u/ai).
87+
88+
#### InspectModel
89+
90+
- 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>
91+
92+
Use the `InspectModel` method to inspect a model from the Docker Model Runner, by providing the model namespace and name.
93+
94+
<!--codeinclude-->
95+
[Getting a model at runtime](../../modules/dockermodelrunner/examples_test.go) inside_block:runInspectModel
96+
<!--/codeinclude-->
97+
98+
The namespace and name of the model is in the format of `<name>:<tag>`, which defines Models as OCI Artifacts in Docker Hub, therefore the namespace is the organization and the name is the repository.
99+
100+
E.g. `ai/smollm2:360M-Q4_K_M`. See [Models as OCI Artifacts](https://hub.docker.com/u/ai) for more information.
101+
102+
#### ListModels
103+
104+
- 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>
105+
106+
Use the `ListModels` method to list all models that are already pulled locally, using the Docker Model Runner format.
107+
108+
<!--codeinclude-->
109+
[Listing all models](../../modules/dockermodelrunner/examples_test.go) inside_block:runListModels
110+
<!--/codeinclude-->

docs/modules/postgres.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ An example of a `*.sh` script that creates a user and database is shown below:
7070
[Init script content](../../modules/postgres/testdata/init-user-db.sh)
7171
<!--/codeinclude-->
7272
73+
#### Ordered Init Scripts
74+
75+
If you would like to run the init scripts in a specific order, you can use the `WithOrderedInitScripts` function, which copies the given scripts in the order they are provided to the container, prefixed with the order number so that Postgres executes them in the correct order.
76+
77+
<!--codeinclude-->
78+
[Ordered init scripts](../../modules/postgres/postgres_test.go) inside_block:orderedInitScripts
79+
<!--/codeinclude-->
80+
7381
#### Database configuration
7482
7583
In the case you have a custom config file for Postgres, it's possible to copy that file into the container before it's started, using the `WithConfigFile(cfgPath string)` function.

docs/modules/redis.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ By default Redis saves snapshots of the dataset on disk, in a binary file called
6262

6363
#### Log Level
6464

65-
By default Redis saves snapshots of the dataset on disk, in a binary file called dump.rdb. You can configure Redis to have it save the dataset every N seconds if there are at least M changes in the dataset. E.g. `WithLogLevel(LogLevelDebug)`.
65+
By default Redis produces a log message to the standard Redis log, the format accepts printf-alike specifiers, while level is a string describing the log level to use when emitting the log, and must be one of the following: `LogLevelDebug`, `LogLevelVerbose`, `LogLevelNotice`, `LogLevelWarning`. E.g. `WithLogLevel(LogLevelDebug)`. If the specified log level is invalid, verbose is used by default.
6666

6767
!!!tip
6868
Please check [Redis docs on logging](https://redis.io/docs/reference/modules/modules-api-ref/#redismodule_log) for more information.
@@ -71,24 +71,33 @@ By default Redis saves snapshots of the dataset on disk, in a binary file called
7171

7272
In the case you have a custom config file for Redis, it's possible to copy that file into the container before it's started. E.g. `WithConfigFile(filepath.Join("testdata", "redis7.conf"))`.
7373

74+
#### WithTLS
75+
76+
In the case you want to enable TLS for the Redis container, you can use the `WithTLS()` option. This options enables TLS on the `6379/tcp` port and uses a secure URL (e.g. `rediss://host:port`).
77+
78+
!!!info
79+
In case you want to use Non-mutual TLS (i.e. client authentication is not required), you can customize the CMD arguments by using the `WithCmdArgs` option. E.g. `WithCmdArgs("--tls-auth-clients no")`.
80+
81+
The module automatically generates three certificates, a CA certificate, a client certificate and a Redis certificate. Please use the `TLSConfig()` container method to get the TLS configuration and use it to configure the Redis client. See more details in the [TLSConfig](#tlsconfig) section.
82+
7483
### Container Methods
7584

7685
#### ConnectionString
7786

78-
This method returns the connection string to connect to the Redis container, using the default `6379` port.
87+
This method returns the connection string to connect to the Redis container, using the default `6379` port, and `redis` schema.
7988

8089
<!--codeinclude-->
8190
[Get connection string](../../modules/redis/redis_test.go) inside_block:connectionString
8291
<!--/codeinclude-->
8392

84-
### Redis variants
93+
If the container is started with TLS enabled, the connection string is `rediss://host:port`, using the `rediss` schema.
8594

86-
It's possible to use the Redis container with Redis-Stack. You simply need to update the image name.
95+
#### TLSConfig
8796

88-
<!--codeinclude-->
89-
[Image for Redis-Stack](../../modules/redis/redis_test.go) inside_block:redisStackImage
90-
<!--/codeinclude-->
97+
This method returns the TLS configuration for the Redis container, nil if TLS is not enabled.
9198

9299
<!--codeinclude-->
93-
[Image for Redis-Stack Server](../../modules/redis/redis_test.go) inside_block:redisStackServerImage
100+
[Get TLS config](../../modules/redis/redis_test.go) inside_block:tlsConfig
94101
<!--/codeinclude-->
102+
103+
In the above example, the options are used to configure a Redis client with TLS enabled.

docs/modules/socat.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ When starting the Socat container, you can pass options in a variadic way to con
4747

4848
#### Image
4949

50+
The module exposes a default image:
51+
52+
<!--codeinclude-->
53+
[Default Image](../../modules/socat/socat.go) inside_block:defaultImage
54+
<!--/codeinclude-->
55+
5056
Use the second argument in the `Run` function to set a valid Docker image.
51-
In example: `Run(context.Background(), "alpine/socat:1.8.0.1")`.
57+
In example: `Run(context.Background(), DefaultImage)`.
5258

5359
{% include "../features/common_functional_options.md" %}
5460

0 commit comments

Comments
 (0)