Skip to content

Commit

Permalink
Merge branch 'main' into surrealdb
Browse files Browse the repository at this point in the history
* main:
  chore: bump Go version to 1.21 (testcontainers#2292)
  chore(deps): bump github.com/ClickHouse/clickhouse-go/v2 (testcontainers#2226)
  feat: WithLogger ContainerCustomizer support (testcontainers#2259)
  chore(deps): bump github.com/jackc/pgx/v5 in /modules/cockroachdb (testcontainers#2217)
  Move the file and mounts tests into a test package (testcontainers#2270)
  Fix Dockerfile not located when added to dockerignore (testcontainers#2272)
  • Loading branch information
mdelapenya committed Mar 1, 2024
2 parents 5d300e2 + 20929ae commit c12fb18
Show file tree
Hide file tree
Showing 97 changed files with 809 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
"image": "mcr.microsoft.com/devcontainers/go:0-1.20-bullseye",
"image": "mcr.microsoft.com/devcontainers/go:0-1.21-bullseye",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.state != 'approved' && github.triggering_actor == 'dependabot[bot]') }}
strategy:
matrix:
go-version: [1.20.x, 1.x]
go-version: [1.21.x, 1.x]
platform: [ubuntu-latest, macos-latest]
uses: ./.github/workflows/ci-test-go.yml
with:
Expand All @@ -48,7 +48,7 @@ jobs:
name: "Test with reaper off"
strategy:
matrix:
go-version: [1.20.x, 1.x]
go-version: [1.21.x, 1.x]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand All @@ -67,7 +67,7 @@ jobs:
name: "Test with Rootless Docker"
strategy:
matrix:
go-version: [1.20.x, 1.x]
go-version: [1.21.x, 1.x]
platform: [ubuntu-latest]
uses: ./.github/workflows/ci-test-go.yml
with:
Expand All @@ -84,7 +84,7 @@ jobs:
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.state != 'approved' && github.triggering_actor == 'dependabot[bot]') }}
strategy:
matrix:
go-version: [1.20.x, 1.x]
go-version: [1.21.x, 1.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
uses: ./.github/workflows/ci-test-go.yml
with:
Expand All @@ -102,12 +102,9 @@ jobs:
needs: test
strategy:
matrix:
go-version: [1.20.x, 1.x]
go-version: [1.21.x, 1.x]
platform: [ubuntu-latest]
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, surrealdb, vault, weaviate]
exclude:
- go-version: 1.20.x
module: compose
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand All @@ -127,7 +124,7 @@ jobs:
module: [nginx, toxiproxy]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: "1.20.x"
go-version: "1.21.x"
fail-fast: true
platform: 'ubuntu-latest'
project-directory: examples/${{ matrix.module }}
Expand Down
11 changes: 10 additions & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ func (c *ContainerRequest) Validate() error {

// GetContext retrieve the build context for the request
func (c *ContainerRequest) GetContext() (io.Reader, error) {
var includes []string = []string{"."}

if c.ContextArchive != nil {
return c.ContextArchive, nil
}
Expand All @@ -209,7 +211,14 @@ func (c *ContainerRequest) GetContext() (io.Reader, error) {
if err != nil {
return nil, err
}
buildContext, err := archive.TarWithOptions(c.Context, &archive.TarOptions{ExcludePatterns: excluded})

dockerIgnoreLocation := filepath.Join(abs, ".dockerignore")
includes = append(includes, dockerIgnoreLocation, c.GetDockerfile())

buildContext, err := archive.TarWithOptions(
c.Context,
&archive.TarOptions{ExcludePatterns: excluded, IncludeFiles: includes},
)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func TestParseDockerIgnore(t *testing.T) {
{
filePath: "./testdata",
expectedErr: nil,
expectedExcluded: []string(nil),
expectedExcluded: []string{"Dockerfile", "echo.Dockerfile"},
},
}

Expand Down
49 changes: 29 additions & 20 deletions docker_files_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testcontainers
package testcontainers_test

import (
"context"
Expand All @@ -8,6 +8,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)

Expand All @@ -21,10 +22,10 @@ func TestCopyFileToContainer(t *testing.T) {
t.Fatal(err)
}

container, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash",
Files: []ContainerFile{
Files: []testcontainers.ContainerFile{
{
HostFilePath: absPath,
ContainerFilePath: "/hello.sh",
Expand Down Expand Up @@ -57,10 +58,10 @@ func TestCopyFileToRunningContainer(t *testing.T) {
t.Fatal(err)
}

container, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash:5.2.26",
Files: []ContainerFile{
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
ContainerFilePath: "/waitForHello.sh",
Expand Down Expand Up @@ -98,10 +99,10 @@ func TestCopyDirectoryToContainer(t *testing.T) {
t.Fatal(err)
}

container, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash",
Files: []ContainerFile{
Files: []testcontainers.ContainerFile{
{
HostFilePath: dataDirectory,
// ContainerFile cannot create the parent directory, so we copy the scripts
Expand Down Expand Up @@ -136,10 +137,10 @@ func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {
t.Fatal(err)
}

container, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash",
Files: []ContainerFile{
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
ContainerFilePath: "/waitForHello.sh",
Expand All @@ -150,11 +151,15 @@ func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {
},
Started: true,
})
require.NoError(t, err)
if err != nil {
t.Fatal(err)
}

// as the container is started, we can create the directory first
_, _, err = container.Exec(ctx, []string{"mkdir", "-p", "/scripts"})
require.NoError(t, err)
if err != nil {
t.Fatal(err)
}

// because the container path is a directory, it will use the copy dir method as fallback
err = container.CopyFileToContainer(ctx, dataDirectory, "/scripts", 0o700)
Expand Down Expand Up @@ -182,10 +187,10 @@ func TestCopyDirectoryToRunningContainerAsDir(t *testing.T) {
t.Fatal(err)
}

container, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash",
Files: []ContainerFile{
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
ContainerFilePath: "/waitForHello.sh",
Expand All @@ -196,11 +201,15 @@ func TestCopyDirectoryToRunningContainerAsDir(t *testing.T) {
},
Started: true,
})
require.NoError(t, err)
if err != nil {
t.Fatal(err)
}

// as the container is started, we can create the directory first
_, _, err = container.Exec(ctx, []string{"mkdir", "-p", "/scripts"})
require.NoError(t, err)
if err != nil {
t.Fatal(err)
}

err = container.CopyDirToContainer(ctx, dataDirectory, "/scripts", 0o700)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions docker_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func (s DockerTmpfsMountSource) GetTmpfsOptions() *mount.TmpfsOptions {
return s.TmpfsOptions
}

// PrepareMounts maps the given []ContainerMount to the corresponding
// []mount.Mount for further processing
func (m ContainerMounts) PrepareMounts() []mount.Mount {
return mapToDockerMounts(m)
}

// mapToDockerMounts maps the given []ContainerMount to the corresponding
// []mount.Mount for further processing
func mapToDockerMounts(containerMounts ContainerMounts) []mount.Mount {
Expand Down
23 changes: 23 additions & 0 deletions docs/features/common_functional_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ func (g *TestLogConsumer) Accept(l Log) {
}
```

#### WithLogger

- 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 logger to a container, you can use `testcontainers.WithLogger`.

!!!info
Consider calling this before other "With" functions as these may generate logs.

In this example we also use `TestLogger` which writes to the passed in `testing.TB` using `Logf`.
The result is that we capture all logging from the container into the test context meaning its
hidden behind `go test -v` and is associated with the relevant test, providing the user with
useful context instead of appearing out of band.

```golang
func TestHandler(t *testing.T) {
logger := TestLogger(t)
_, err := postgresModule.RunContainer(ctx, testcontainers.WithLogger(logger))
require.NoError(t, err)
// Do something with container.
}
```

Please read the [Following Container Logs](/features/follow_logs) documentation for more information about creating log consumers.

#### Wait Strategies
Expand Down
2 changes: 1 addition & 1 deletion docs/system_requirements/ci/aws_codebuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version: 0.2
phases:
install:
runtime-versions:
golang: 1.20
golang: 1.21
build:
commands:
- go test ./...
Expand Down
2 changes: 1 addition & 1 deletion docs/system_requirements/ci/concourse_ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
start_docker
cd repo
docker run -it --rm -v "$PWD:$PWD" -w "$PWD" -v /var/run/docker.sock:/var/run/docker.sock golang:1.20 go test ./...
docker run -it --rm -v "$PWD:$PWD" -w "$PWD" -v /var/run/docker.sock:/var/run/docker.sock golang:1.21 go test ./...
```
Finally, you can use Concourse's [fly CLI](https://concourse-ci.org/fly.html) to set the pipeline and trigger the job:
Expand Down
4 changes: 2 additions & 2 deletions docs/system_requirements/ci/dind_patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $ tree .
└── platform
└── integration_test.go

$ docker run -it --rm -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock golang:1.20 go test ./... -v
$ docker run -it --rm -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock golang:1.21 go test ./... -v
```

Where:
Expand All @@ -45,7 +45,7 @@ The same can be achieved with Docker Compose:

```yaml
tests:
image: golang:1.20
image: golang:1.21
stop_signal: SIGKILL
stdin_open: true
tty: true
Expand Down
2 changes: 1 addition & 1 deletion docs/system_requirements/ci/gitlab_ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ variables:
DOCKER_DRIVER: overlay2
test:
image: golang:1.20
image: golang:1.21
stage: test
script: go test ./... -v
```
2 changes: 1 addition & 1 deletion docs/system_requirements/ci/tekton.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
- name: source
steps:
- name: read
image: golang:1.20
image: golang:1.21
workingDir: $(workspaces.source.path)
script: go test ./... -v
volumeMounts:
Expand Down
2 changes: 1 addition & 1 deletion docs/system_requirements/ci/travis.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ is the minimal required config.
language: go
go:
- 1.x
- "1.20"
- "1.21"

services:
- docker
Expand Down
2 changes: 1 addition & 1 deletion examples/nginx/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/testcontainers/testcontainers-go/examples/nginx

go 1.20
go 1.21

require github.com/testcontainers/testcontainers-go v0.28.0

Expand Down
Loading

0 comments on commit c12fb18

Please sign in to comment.