Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into gui/test-packages-for…
Browse files Browse the repository at this point in the history
…-docs
  • Loading branch information
Minivera committed Feb 28, 2024
2 parents 853b56d + 8085e2f commit 16f384c
Show file tree
Hide file tree
Showing 142 changed files with 4,504 additions and 546 deletions.
35 changes: 35 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ updates:
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/chroma
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/clickhouse
schedule:
Expand Down Expand Up @@ -149,6 +156,13 @@ updates:
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/milvus
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/minio
schedule:
Expand Down Expand Up @@ -205,6 +219,13 @@ updates:
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/opensearch
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/postgres
schedule:
Expand All @@ -219,6 +240,13 @@ updates:
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/qdrant
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/rabbitmq
schedule:
Expand Down Expand Up @@ -247,3 +275,10 @@ updates:
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/weaviate
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
matrix:
go-version: [1.20.x, 1.x]
platform: [ubuntu-latest]
module: [artemis, cassandra, clickhouse, cockroachdb, compose, consul, couchbase, elasticsearch, gcloud, inbucket, k3s, k6, kafka, localstack, mariadb, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, openldap, postgres, pulsar, rabbitmq, redis, redpanda, vault]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, elasticsearch, gcloud, inbucket, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, vault, weaviate]
exclude:
- go-version: 1.20.x
module: compose
Expand Down
22 changes: 21 additions & 1 deletion .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"name": "module / cassandra",
"path": "../modules/cassandra"
},
{
"name": "module / chroma",
"path": "../modules/chroma"
},
{
"name": "module / clickhouse",
"path": "../modules/clickhouse"
Expand Down Expand Up @@ -73,6 +77,10 @@
"name": "module / mariadb",
"path": "../modules/mariadb"
},
{
"name": "module / milvus",
"path": "../modules/milvus"
},
{
"name": "module / minio",
"path": "../modules/minio"
Expand Down Expand Up @@ -105,6 +113,10 @@
"name": "module / openldap",
"path": "../modules/openldap"
},
{
"name": "module / opensearch",
"path": "../modules/opensearch"
},
{
"name": "module / postgres",
"path": "../modules/postgres"
Expand All @@ -113,6 +125,10 @@
"name": "module / pulsar",
"path": "../modules/pulsar"
},
{
"name": "module / qdrant",
"path": "../modules/qdrant"
},
{
"name": "module / rabbitmq",
"path": "../modules/rabbitmq"
Expand All @@ -129,9 +145,13 @@
"name": "module / vault",
"path": "../modules/vault"
},
{
"name": "module / weaviate",
"path": "../modules/weaviate"
},
{
"name": "modulegen",
"path": "../modulegen"
}
]
}
}
53 changes: 51 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -49,6 +50,8 @@ const (
logStoppedForOutOfSyncMessage = "Stopping log consumer: Headers out of sync"
)

var createContainerFailDueToNameConflictRegex = regexp.MustCompile("Conflict. The container name .* is already in use by container .*")

// DockerContainer represents a container started using Docker
type DockerContainer struct {
// Container ID from Docker
Expand Down Expand Up @@ -1153,13 +1156,40 @@ func (p *DockerProvider) findContainerByName(ctx context.Context, name string) (
return nil, nil
}

func (p *DockerProvider) waitContainerCreation(ctx context.Context, name string) (*types.Container, error) {
var container *types.Container
return container, backoff.Retry(func() error {
c, err := p.findContainerByName(ctx, name)
if err != nil {
return err
}

if c == nil {
return fmt.Errorf("container %s not found", name)
}

container = c
return nil
}, backoff.WithContext(backoff.NewExponentialBackOff(), ctx))
}

func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req ContainerRequest) (Container, error) {
c, err := p.findContainerByName(ctx, req.Name)
if err != nil {
return nil, err
}
if c == nil {
return p.CreateContainer(ctx, req)
createdContainer, err := p.CreateContainer(ctx, req)
if err == nil {
return createdContainer, nil
}
if !createContainerFailDueToNameConflictRegex.MatchString(err.Error()) {
return nil, err
}
c, err = p.waitContainerCreation(ctx, req.Name)
if err != nil {
return nil, err
}
}

sessionID := core.SessionID()
Expand All @@ -1178,6 +1208,13 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain
}
}

// default hooks include logger hook and pre-create hook
defaultHooks := []ContainerLifecycleHooks{
DefaultLoggingHook(p.Logger),
defaultReadinessHook(),

Check failure on line 1214 in docker.go

View workflow job for this annotation

GitHub Actions / Test with Rootless Docker (1.x, ubuntu-latest) / ./ubuntu-latest/1.x

undefined: defaultReadinessHook

Check failure on line 1214 in docker.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest) / ./macos-latest/1.20.x

undefined: defaultReadinessHook

Check failure on line 1214 in docker.go

View workflow job for this annotation

GitHub Actions / test (1.x, ubuntu-latest) / ./ubuntu-latest/1.x

undefined: defaultReadinessHook

Check failure on line 1214 in docker.go

View workflow job for this annotation

GitHub Actions / Test with Rootless Docker (1.20.x, ubuntu-latest) / ./ubuntu-latest/1.20.x

undefined: defaultReadinessHook

Check failure on line 1214 in docker.go

View workflow job for this annotation

GitHub Actions / Test with Rootless Docker (1.20.x, ubuntu-latest) / ./ubuntu-latest/1.20.x

undefined: defaultReadinessHook

Check failure on line 1214 in docker.go

View workflow job for this annotation

GitHub Actions / Test with reaper off (1.x) / ./ubuntu-latest/1.x

undefined: defaultReadinessHook

Check failure on line 1214 in docker.go

View workflow job for this annotation

GitHub Actions / Test with reaper off (1.20.x) / ./ubuntu-latest/1.20.x

undefined: defaultReadinessHook

Check failure on line 1214 in docker.go

View workflow job for this annotation

GitHub Actions / Test with reaper off (1.20.x) / ./ubuntu-latest/1.20.x

undefined: defaultReadinessHook
defaultLogConsumersHook(req.LogConsumerCfg),

Check failure on line 1215 in docker.go

View workflow job for this annotation

GitHub Actions / Test with Rootless Docker (1.x, ubuntu-latest) / ./ubuntu-latest/1.x

undefined: defaultLogConsumersHook

Check failure on line 1215 in docker.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest) / ./macos-latest/1.20.x

undefined: defaultLogConsumersHook

Check failure on line 1215 in docker.go

View workflow job for this annotation

GitHub Actions / test (1.x, ubuntu-latest) / ./ubuntu-latest/1.x

undefined: defaultLogConsumersHook

Check failure on line 1215 in docker.go

View workflow job for this annotation

GitHub Actions / Test with Rootless Docker (1.20.x, ubuntu-latest) / ./ubuntu-latest/1.20.x

undefined: defaultLogConsumersHook

Check failure on line 1215 in docker.go

View workflow job for this annotation

GitHub Actions / Test with Rootless Docker (1.20.x, ubuntu-latest) / ./ubuntu-latest/1.20.x

undefined: defaultLogConsumersHook

Check failure on line 1215 in docker.go

View workflow job for this annotation

GitHub Actions / Test with reaper off (1.x) / ./ubuntu-latest/1.x

undefined: defaultLogConsumersHook

Check failure on line 1215 in docker.go

View workflow job for this annotation

GitHub Actions / Test with reaper off (1.20.x) / ./ubuntu-latest/1.20.x

undefined: defaultLogConsumersHook

Check failure on line 1215 in docker.go

View workflow job for this annotation

GitHub Actions / Test with reaper off (1.20.x) / ./ubuntu-latest/1.20.x

undefined: defaultLogConsumersHook
}

dc := &DockerContainer{
ID: c.ID,
WaitingFor: req.WaitingFor,
Expand All @@ -1187,7 +1224,19 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain
terminationSignal: termSignal,
stopLogProductionCh: nil,
logger: p.Logger,
isRunning: c.State == "running",
lifecycleHooks: []ContainerLifecycleHooks{combineContainerHooks(defaultHooks, req.LifecycleHooks)},

Check failure on line 1227 in docker.go

View workflow job for this annotation

GitHub Actions / Test with Rootless Docker (1.x, ubuntu-latest) / ./ubuntu-latest/1.x

undefined: combineContainerHooks

Check failure on line 1227 in docker.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest) / ./macos-latest/1.20.x

undefined: combineContainerHooks

Check failure on line 1227 in docker.go

View workflow job for this annotation

GitHub Actions / test (1.x, ubuntu-latest) / ./ubuntu-latest/1.x

undefined: combineContainerHooks

Check failure on line 1227 in docker.go

View workflow job for this annotation

GitHub Actions / Test with Rootless Docker (1.20.x, ubuntu-latest) / ./ubuntu-latest/1.20.x

undefined: combineContainerHooks) (typecheck)

Check failure on line 1227 in docker.go

View workflow job for this annotation

GitHub Actions / Test with reaper off (1.x) / ./ubuntu-latest/1.x

undefined: combineContainerHooks

Check failure on line 1227 in docker.go

View workflow job for this annotation

GitHub Actions / Test with reaper off (1.20.x) / ./ubuntu-latest/1.20.x

undefined: combineContainerHooks) (typecheck)
}

err = dc.startedHook(ctx)
if err != nil {
return nil, err
}

dc.isRunning = true

err = dc.readiedHook(ctx)
if err != nil {
return nil, err
}

return dc, nil
Expand Down
10 changes: 10 additions & 0 deletions docs/features/common_functional_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ _Testcontainers for Go_ exposes an interface to perform this operations: `ImageS

Using the `WithImageSubstitutors` options, you could define your own substitutions to the container images. E.g. adding a prefix to the images so that they can be pulled from a Docker registry other than Docker Hub. This is the usual mechanism for using Docker image proxies, caches, etc.

#### WithEnv

- 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>

If you need to either pass additional environment variables to a container or override them, you can use `testcontainers.WithEnv` for example:

```golang
postgres, err = postgresModule.RunContainer(ctx, testcontainers.WithEnv(map[string]string{"POSTGRES_INITDB_ARGS", "--no-sync"}))
```

#### WithLogConsumers

- Since testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go/releases/tag/v0.28.0"><span class="tc-version">:material-tag: v0.28.0</span></a>
Expand Down
84 changes: 84 additions & 0 deletions docs/modules/chroma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Chroma

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 Chroma.

## Adding this module to your project dependencies

Please run the following command to add the Chroma module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/chroma
```

## Usage example

<!--codeinclude-->
[Creating a Chroma container](../../modules/chroma/examples_test.go) inside_block:runChromaContainer
<!--/codeinclude-->

## Module reference

The Chroma module exposes one entrypoint function to create the Chroma container, and this function receives two parameters:

```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ChromaContainer, error)
```

- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the Chroma container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different Chroma Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for Chroma. E.g. `testcontainers.WithImage("chromadb/chroma:0.4.22.dev44")`.

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

### Container Methods

The Chroma container exposes the following methods:

#### REST Endpoint

This method returns the REST endpoint of the Chroma container, using the default `8000` port.

<!--codeinclude-->
[Get REST endpoint](../../modules/chroma/chroma_test.go) inside_block:restEndpoint
<!--/codeinclude-->

## Examples

### Getting a Chroma client

The following example demonstrates how to create a Chroma client using the Chroma module.

First of all, you need to import the Chroma module and the Swagger client:

```golang
import (
chromago "github.com/amikos-tech/chroma-go"
chromaopenapi "github.com/amikos-tech/chroma-go/swagger"
)
```

Then, you can create a Chroma client using the Chroma module:

<!--codeinclude-->
[Get the client](../../modules/chroma/examples_test.go) inside_block:createClient
<!--/codeinclude-->

### Working with Collections

<!--codeinclude-->
[Create Collection](../../modules/chroma/examples_test.go) inside_block:createCollection
[List Collections](../../modules/chroma/examples_test.go) inside_block:listCollections
[Delete Collection](../../modules/chroma/examples_test.go) inside_block:deleteCollection
<!--/codeinclude-->
65 changes: 65 additions & 0 deletions docs/modules/milvus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Milvus

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 Milvus.

## Adding this module to your project dependencies

Please run the following command to add the Milvus module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/milvus
```

## Usage example

<!--codeinclude-->
[Creating a Milvus container](../../modules/milvus/examples_test.go) inside_block:runMilvusContainer
<!--/codeinclude-->

## Module reference

The Milvus module exposes one entrypoint function to create the Milvus container, and this function receives two parameters:

```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MilvusContainer, error)
```

- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the Milvus container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different Milvus Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for Milvus. E.g. `testcontainers.WithImage("milvusdb/milvus:v2.3.9")`.

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

### Container Methods

The Milvus container exposes the following methods:

#### ConnectionString

This method returns the connection string to connect to the Milvus container, using the default `19530` port.

<!--codeinclude-->
[Get connection string](../../modules/milvus/milvus_test.go) inside_block:connectionString
<!--/codeinclude-->

## Examples

### Creating collections

This example shows the usage of the Milvus module to create and retrieve collections.

<!--codeinclude-->
[Create collections](../../modules/milvus/examples_test.go) inside_block:createCollections
<!--/codeinclude-->
Loading

0 comments on commit 16f384c

Please sign in to comment.