Skip to content

Commit 5f655d4

Browse files
authored
Merge branch 'main' into refactor-ryuk
2 parents 15b6462 + 9860647 commit 5f655d4

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

container.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ type ContainerRequest struct {
118118
AlwaysPullImage bool // Always pull image
119119
ImagePlatform string // ImagePlatform describes the platform which the image runs on.
120120
Binds []string
121-
ShmSize int64 // Amount of memory shared with the host (in bytes)
121+
ShmSize int64 // Amount of memory shared with the host (in bytes)
122+
CapAdd []string // Add Linux capabilities
123+
CapDrop []string // Drop Linux capabilities
122124
}
123125

124126
type (

docker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
950950
}
951951

952952
exposedPorts := req.ExposedPorts
953-
if len(exposedPorts) == 0 {
953+
if len(exposedPorts) == 0 && !req.NetworkMode.IsContainer() {
954954
image, _, err := p.client.ImageInspectWithRaw(ctx, tag)
955955
if err != nil {
956956
return nil, err
@@ -990,6 +990,8 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
990990
NetworkMode: req.NetworkMode,
991991
Resources: req.Resources,
992992
ShmSize: req.ShmSize,
993+
CapAdd: req.CapAdd,
994+
CapDrop: req.CapDrop,
993995
}
994996

995997
endpointConfigs := map[string]*network.EndpointSettings{}

docker_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"time"
1818

1919
"github.com/docker/docker/api/types/container"
20+
"github.com/docker/docker/api/types/strslice"
2021
"github.com/docker/go-units"
2122
"github.com/go-redis/redis/v8"
2223
"github.com/stretchr/testify/assert"
@@ -1959,6 +1960,39 @@ func TestContainerWithReaperNetwork(t *testing.T) {
19591960
assert.NotNil(t, cnt.NetworkSettings.Networks[networks[1]])
19601961
}
19611962

1963+
func TestContainerCapAdd(t *testing.T) {
1964+
if providerType == ProviderPodman {
1965+
t.Skip("Rootless Podman does not support setting cap-add/cap-drop")
1966+
}
1967+
1968+
ctx := context.Background()
1969+
1970+
expected := "IPC_LOCK"
1971+
1972+
nginx, err := GenericContainer(ctx, GenericContainerRequest{
1973+
ProviderType: providerType,
1974+
ContainerRequest: ContainerRequest{
1975+
Image: nginxAlpineImage,
1976+
ExposedPorts: []string{nginxDefaultPort},
1977+
WaitingFor: wait.ForListeningPort(nginxDefaultPort),
1978+
CapAdd: []string{expected},
1979+
},
1980+
Started: true,
1981+
})
1982+
require.NoError(t, err)
1983+
terminateContainerOnEnd(t, ctx, nginx)
1984+
1985+
dockerClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
1986+
require.NoError(t, err)
1987+
defer dockerClient.Close()
1988+
1989+
containerID := nginx.GetContainerID()
1990+
resp, err := dockerClient.ContainerInspect(ctx, containerID)
1991+
require.NoError(t, err)
1992+
1993+
assert.Equal(t, strslice.StrSlice{expected}, resp.HostConfig.CapAdd)
1994+
}
1995+
19621996
func TestContainerRunningCheckingStatusCode(t *testing.T) {
19631997
ctx := context.Background()
19641998
req := ContainerRequest{
@@ -2068,6 +2102,33 @@ func TestProviderHasConfig(t *testing.T) {
20682102
assert.NotNil(t, provider.Config(), "expecting DockerProvider to provide the configuration")
20692103
}
20702104

2105+
func TestNetworkModeWithContainerReference(t *testing.T) {
2106+
ctx := context.Background()
2107+
nginxA, err := GenericContainer(ctx, GenericContainerRequest{
2108+
ProviderType: providerType,
2109+
ContainerRequest: ContainerRequest{
2110+
Image: nginxAlpineImage,
2111+
},
2112+
Started: true,
2113+
})
2114+
2115+
require.NoError(t, err)
2116+
terminateContainerOnEnd(t, ctx, nginxA)
2117+
2118+
networkMode := fmt.Sprintf("container:%v", nginxA.GetContainerID())
2119+
nginxB, err := GenericContainer(ctx, GenericContainerRequest{
2120+
ProviderType: providerType,
2121+
ContainerRequest: ContainerRequest{
2122+
Image: nginxAlpineImage,
2123+
NetworkMode: container.NetworkMode(networkMode),
2124+
},
2125+
Started: true,
2126+
})
2127+
2128+
require.NoError(t, err)
2129+
terminateContainerOnEnd(t, ctx, nginxB)
2130+
}
2131+
20712132
// 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
20722133
func assertExtractedFiles(t *testing.T, ctx context.Context, container Container, hostFilePath string, containerFilePath string) {
20732134
// create all copied files into a temporary dir

mkdocs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ nav:
3636
- features/follow_logs.md
3737
- features/override_container_command.md
3838
- features/copy_file.md
39-
- features/using_podman.md
40-
- features/using_colima.md
4139
- Wait Strategies:
4240
- Introduction: features/wait/introduction.md
4341
- Exec: features/wait/exec.md
@@ -52,6 +50,9 @@ nav:
5250
- examples/cockroachdb.md
5351
- examples/nginx.md
5452
- examples/redis.md
53+
- System Requirements:
54+
- features/using_colima.md
55+
- features/using_podman.md
5556
- Contributing:
5657
- contributing.md
5758
- contributing_docs.md

reaper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
TestcontainerLabelSessionID = TestcontainerLabel + ".sessionId"
2323
TestcontainerLabelIsReaper = TestcontainerLabel + ".reaper"
2424

25-
ReaperDefaultImage = "docker.io/testcontainers/ryuk:0.3.3"
25+
ReaperDefaultImage = "docker.io/testcontainers/ryuk:0.3.4"
2626
)
2727

2828
type reaperContextKey string

runtime.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.7
1+
3.8

0 commit comments

Comments
 (0)