Skip to content

Commit

Permalink
Merge branch 'main' into container-ips
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya authored Oct 14, 2022
2 parents 81dfe5d + c0d73a6 commit 1bcf925
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 6 deletions.
4 changes: 3 additions & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,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 (
Expand Down
4 changes: 3 additions & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,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
Expand Down Expand Up @@ -1050,6 +1050,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{}
Expand Down
61 changes: 61 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2262,6 +2263,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{
Expand Down Expand Up @@ -2371,6 +2405,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
Expand Down
12 changes: 12 additions & 0 deletions docs/system_requirements/index.md
Original file line number Diff line number Diff line change
@@ -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/).
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,6 +50,10 @@ nav:
- examples/cockroachdb.md
- examples/nginx.md
- examples/redis.md
- System Requirements:
- system_requirements/index.md
- system_requirements/using_colima.md
- system_requirements/using_podman.md
- Contributing:
- contributing.md
- contributing_docs.md
Expand Down
2 changes: 1 addition & 1 deletion reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7
3.8

0 comments on commit 1bcf925

Please sign in to comment.