From 6b130f8dbde90f2109643dadf0a795f64ad5527c Mon Sep 17 00:00:00 2001 From: Zoran Regvart Date: Mon, 13 Jun 2022 14:38:37 +0200 Subject: [PATCH 1/4] feat: support binds in addition to mounts This is needed for providing additional options, such as SELinux label. --- container.go | 1 + docker.go | 1 + 2 files changed, 2 insertions(+) diff --git a/container.go b/container.go index 22d2d0609c..605d79f976 100644 --- a/container.go +++ b/container.go @@ -104,6 +104,7 @@ type ContainerRequest struct { AutoRemove bool // if set to true, the container will be removed from the host when stopped AlwaysPullImage bool // Always pull image ImagePlatform string // ImagePlatform describes the platform which the image runs on. + Binds []string } type ( diff --git a/docker.go b/docker.go index 466b538d30..5ae5cb4a62 100644 --- a/docker.go +++ b/docker.go @@ -865,6 +865,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque hostConfig := &container.HostConfig{ ExtraHosts: req.ExtraHosts, PortBindings: exposedPortMap, + Binds: req.Binds, Mounts: mounts, Tmpfs: req.Tmpfs, AutoRemove: req.AutoRemove, From 25da222bfcf6f818cc5bf8189adacae06f00464c Mon Sep 17 00:00:00 2001 From: "v.funtikov" Date: Mon, 13 Jun 2022 18:49:08 +0300 Subject: [PATCH 2/4] fix: temp fix of flaky test --- logconsumer_test.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/logconsumer_test.go b/logconsumer_test.go index bfc837f084..76cd616fe8 100644 --- a/logconsumer_test.go +++ b/logconsumer_test.go @@ -2,6 +2,7 @@ package testcontainers import ( "context" + "errors" "fmt" "net/http" "testing" @@ -201,13 +202,29 @@ func TestContainerLogWithErrClosed(t *testing.T) { }, }) if err != nil { - t.Fatal(err) + t.Fatal("create generic container:", err) } defer dind.Terminate(ctx) - remoteDocker, err := dind.Endpoint(ctx, "2375/tcp") + var remoteDocker string + + ctxEndpoint, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + // todo: remove this temporary fix (test is flaky). + for { + remoteDocker, err = dind.Endpoint(ctxEndpoint, "2375/tcp") + if err == nil { + break + } + if errors.Is(err, context.DeadlineExceeded) { + break + } + time.Sleep(100 * time.Microsecond) + t.Log("retrying get endpoint") + } if err != nil { - t.Fatal(err) + t.Fatal("get endpoint:", err) } client, err := client.NewClientWithOpts(client.WithHost(remoteDocker)) From 43d121db88e2bf05aa523881d8ec2b015223e8cb Mon Sep 17 00:00:00 2001 From: Jop Zitman Date: Tue, 14 Jun 2022 20:22:12 +0200 Subject: [PATCH 3/4] Add shm size --- container.go | 1 + docker.go | 1 + 2 files changed, 2 insertions(+) diff --git a/container.go b/container.go index 605d79f976..696e7c5937 100644 --- a/container.go +++ b/container.go @@ -105,6 +105,7 @@ type ContainerRequest struct { AlwaysPullImage bool // Always pull image ImagePlatform string // ImagePlatform describes the platform which the image runs on. Binds []string + ShmSize int64 // Amount of memory shared with the host (in MB) } type ( diff --git a/docker.go b/docker.go index 5ae5cb4a62..053e1c1814 100644 --- a/docker.go +++ b/docker.go @@ -872,6 +872,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque Privileged: req.Privileged, NetworkMode: req.NetworkMode, Resources: req.Resources, + ShmSize: req.ShmSize, } endpointConfigs := map[string]*network.EndpointSettings{} From 4f15dd04aa48a366149be02103d30b5b2b4c3553 Mon Sep 17 00:00:00 2001 From: Jop Zitman Date: Thu, 16 Jun 2022 09:42:21 +0200 Subject: [PATCH 4/4] Fix docstring for ShmSize --- container.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container.go b/container.go index 696e7c5937..a82bbe8e8f 100644 --- a/container.go +++ b/container.go @@ -105,7 +105,7 @@ type ContainerRequest struct { AlwaysPullImage bool // Always pull image ImagePlatform string // ImagePlatform describes the platform which the image runs on. Binds []string - ShmSize int64 // Amount of memory shared with the host (in MB) + ShmSize int64 // Amount of memory shared with the host (in bytes) } type (