From dc0955988d2ee789f1f2f369eaa459b710b56337 Mon Sep 17 00:00:00 2001 From: Clive Jevons Date: Fri, 7 Oct 2022 16:20:26 +0200 Subject: [PATCH 1/6] fix container NetworkMode usage (#560) docker cannot do container network mode with exposed ports. in order to make it work, only calculate the default exposed ports if the NetworkMode is NOT container. --- docker.go | 2 +- docker_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docker.go b/docker.go index d8be4bcfcc..8438a4db6d 100644 --- a/docker.go +++ b/docker.go @@ -993,7 +993,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque } exposedPorts := req.ExposedPorts - if len(exposedPorts) == 0 { + if len(exposedPorts) == 0 && !req.NetworkMode.IsContainer() { image, _, err := p.client.ImageInspectWithRaw(ctx, tag) if err != nil { return nil, err diff --git a/docker_test.go b/docker_test.go index 427289bd62..95f71ed40d 100644 --- a/docker_test.go +++ b/docker_test.go @@ -2323,6 +2323,33 @@ func TestProviderHasConfig(t *testing.T) { assert.NotNil(t, provider.Config(), "expecting DockerProvider to provide the configuration") } +func TestNetworkModeWithContainerReference(t *testing.T) { + ctx := context.Background() + nginxA, err := GenericContainer(ctx, GenericContainerRequest{ + ProviderType: providerType, + ContainerRequest: ContainerRequest{ + Image: nginxAlpineImage, + }, + Started: true, + }) + + require.NoError(t, err) + terminateContainerOnEnd(t, ctx, nginxA) + + networkMode := fmt.Sprintf("container:%v", nginxA.GetContainerID()) + nginxB, err := GenericContainer(ctx, GenericContainerRequest{ + ProviderType: providerType, + ContainerRequest: ContainerRequest{ + Image: nginxAlpineImage, + NetworkMode: container.NetworkMode(networkMode), + }, + Started: true, + }) + + require.NoError(t, err) + terminateContainerOnEnd(t, ctx, nginxB) +} + // creates a temporary dir in which the files will be extracted. Then it will compare the bytes of each file in the source with the bytes from the copied-from-container file func assertExtractedFiles(t *testing.T, ctx context.Context, container Container, hostFilePath string, containerFilePath string) { // create all copied files into a temporary dir From 917b257b550b7945e52aa6207d9fd26089a56194 Mon Sep 17 00:00:00 2001 From: Daniel Huckins Date: Fri, 7 Oct 2022 10:51:46 -0400 Subject: [PATCH 2/6] Support for cap-add/cap-drop (#555) * pass cap-add/cap-drop from container request to docker host config Signed-off-by: Daniel Huckins * add test Signed-off-by: Daniel Huckins Signed-off-by: Daniel Huckins --- container.go | 4 +++- docker.go | 2 ++ docker_test.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/container.go b/container.go index ddb78da94a..01f38f4534 100644 --- a/container.go +++ b/container.go @@ -116,7 +116,9 @@ 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 bytes) + ShmSize int64 // Amount of memory shared with the host (in bytes) + CapAdd []string // Add Linux capabilities + CapDrop []string // Drop Linux capabilities } type ( diff --git a/docker.go b/docker.go index 8438a4db6d..f8ab69ebb0 100644 --- a/docker.go +++ b/docker.go @@ -1033,6 +1033,8 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque NetworkMode: req.NetworkMode, Resources: req.Resources, ShmSize: req.ShmSize, + CapAdd: req.CapAdd, + CapDrop: req.CapDrop, } endpointConfigs := map[string]*network.EndpointSettings{} diff --git a/docker_test.go b/docker_test.go index 95f71ed40d..723566541b 100644 --- a/docker_test.go +++ b/docker_test.go @@ -17,6 +17,7 @@ import ( "time" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/strslice" "github.com/docker/go-units" "github.com/go-redis/redis/v8" "github.com/stretchr/testify/assert" @@ -2214,6 +2215,39 @@ func TestContainerWithReaperNetwork(t *testing.T) { assert.NotNil(t, cnt.NetworkSettings.Networks[networks[1]]) } +func TestContainerCapAdd(t *testing.T) { + if providerType == ProviderPodman { + t.Skip("Rootless Podman does not support setting cap-add/cap-drop") + } + + ctx := context.Background() + + expected := "IPC_LOCK" + + nginx, err := GenericContainer(ctx, GenericContainerRequest{ + ProviderType: providerType, + ContainerRequest: ContainerRequest{ + Image: nginxAlpineImage, + ExposedPorts: []string{nginxDefaultPort}, + WaitingFor: wait.ForListeningPort(nginxDefaultPort), + CapAdd: []string{expected}, + }, + Started: true, + }) + require.NoError(t, err) + terminateContainerOnEnd(t, ctx, nginx) + + dockerClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + require.NoError(t, err) + defer dockerClient.Close() + + containerID := nginx.GetContainerID() + resp, err := dockerClient.ContainerInspect(ctx, containerID) + require.NoError(t, err) + + assert.Equal(t, strslice.StrSlice{expected}, resp.HostConfig.CapAdd) +} + func TestContainerRunningCheckingStatusCode(t *testing.T) { ctx := context.Background() req := ContainerRequest{ From d118f89ddddcba83eff6237f001d7e6beb1b0d0f Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Mon, 10 Oct 2022 11:17:39 +0530 Subject: [PATCH 3/6] Add system requirements parent docs page for podman and colima (#562) * add system requirements Signed-off-by: Gaurav Gahlot * remove duplicate entries Signed-off-by: Gaurav Gahlot Signed-off-by: Gaurav Gahlot --- mkdocs.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index dd4ab1c983..71d7db108e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -36,8 +36,6 @@ nav: - features/follow_logs.md - features/override_container_command.md - features/copy_file.md - - features/using_podman.md - - features/using_colima.md - Wait Strategies: - Introduction: features/wait/introduction.md - Exec: features/wait/exec.md @@ -52,6 +50,9 @@ nav: - examples/cockroachdb.md - examples/nginx.md - examples/redis.md + - System Requirements: + - features/using_colima.md + - features/using_podman.md - Contributing: - contributing.md - contributing_docs.md From 0865beaa467c4ffcfd9812c3b8d20b8275fc226b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Tue, 11 Oct 2022 21:05:19 -0500 Subject: [PATCH 4/6] Upgrade python version to 3.8 --- runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.txt b/runtime.txt index 475ba515c0..cc1923a40b 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -3.7 +3.8 From 98606474db3b9b938ef47870c415f6f8e0893e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez=20Gonzales?= Date: Thu, 13 Oct 2022 00:20:25 -0500 Subject: [PATCH 5/6] Update testcontainers/ryuk version to 0.3.4 (#564) --- reaper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reaper.go b/reaper.go index 10c35978ef..a969960d53 100644 --- a/reaper.go +++ b/reaper.go @@ -21,7 +21,7 @@ const ( TestcontainerLabelSessionID = TestcontainerLabel + ".sessionId" TestcontainerLabelIsReaper = TestcontainerLabel + ".reaper" - ReaperDefaultImage = "docker.io/testcontainers/ryuk:0.3.3" + ReaperDefaultImage = "docker.io/testcontainers/ryuk:0.3.4" ) type reaperContextKey string From c0d73a6d92de6b827b68ba9ef0a0111aa2bddb74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 13 Oct 2022 15:23:11 +0200 Subject: [PATCH 6/6] docs: add general Docker requirements (#565) * chore: move system requirements to its own folder * docs: add a general Docker requirements overview page --- docs/system_requirements/index.md | 12 ++++++++++++ .../using_colima.md | 0 .../using_podman.md | 0 mkdocs.yml | 5 +++-- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 docs/system_requirements/index.md rename docs/{features => system_requirements}/using_colima.md (100%) rename docs/{features => system_requirements}/using_podman.md (100%) diff --git a/docs/system_requirements/index.md b/docs/system_requirements/index.md new file mode 100644 index 0000000000..6df288ec3c --- /dev/null +++ b/docs/system_requirements/index.md @@ -0,0 +1,12 @@ +# General Docker requirements + +## Overview + +Testcontainers requires a Docker-API compatible container runtime. +During development, Testcontainers is actively tested against recent versions of Docker on Linux, as well as against Docker Desktop on Mac and Windows. +These Docker environments are automatically detected and used by Testcontainers without any additional configuration being necessary. + +It is possible to configure Testcontainers to work for other Docker setups, such as a remote Docker host or Docker alternatives. +However, these are not actively tested in the main development workflow, so not all Testcontainers features might be available and additional manual configuration might be necessary. +If you have further questions about configuration details for your setup or whether it supports running Testcontainers-based tests, +please contact the Testcontainers team and other users from the Testcontainers community on [Slack](https://slack.testcontainers.org/). diff --git a/docs/features/using_colima.md b/docs/system_requirements/using_colima.md similarity index 100% rename from docs/features/using_colima.md rename to docs/system_requirements/using_colima.md diff --git a/docs/features/using_podman.md b/docs/system_requirements/using_podman.md similarity index 100% rename from docs/features/using_podman.md rename to docs/system_requirements/using_podman.md diff --git a/mkdocs.yml b/mkdocs.yml index 71d7db108e..a9a9ef7f11 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -51,8 +51,9 @@ nav: - examples/nginx.md - examples/redis.md - System Requirements: - - features/using_colima.md - - features/using_podman.md + - system_requirements/index.md + - system_requirements/using_colima.md + - system_requirements/using_podman.md - Contributing: - contributing.md - contributing_docs.md