Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/moby/patternmatcher/ignorefile"

tcexec "github.com/testcontainers/testcontainers-go/exec"
"github.com/testcontainers/testcontainers-go/internal/config"
"github.com/testcontainers/testcontainers-go/internal/core"
"github.com/testcontainers/testcontainers-go/log"
"github.com/testcontainers/testcontainers-go/wait"
Expand Down Expand Up @@ -176,7 +177,7 @@ func (c *ContainerRequest) sessionID() string {
return sessionID
}

return core.SessionID()
return config.Read().SessionID
}

// containerOptions functional options for a container
Expand Down
2 changes: 1 addition & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ func (c *DockerContainer) connectReaper(ctx context.Context) error {
return nil
}

reaper, err := spawner.reaper(context.WithValue(ctx, core.DockerHostContextKey, c.provider.host), core.SessionID(), c.provider)
reaper, err := spawner.reaper(context.WithValue(ctx, core.DockerHostContextKey, c.provider.host), c.provider.config.SessionID, c.provider)
if err != nil {
return fmt.Errorf("reaper: %w", err)
}
Expand Down
9 changes: 7 additions & 2 deletions docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import (
"github.com/docker/docker/client"

"github.com/testcontainers/testcontainers-go/internal"
"github.com/testcontainers/testcontainers-go/internal/config"
"github.com/testcontainers/testcontainers-go/internal/core"
"github.com/testcontainers/testcontainers-go/internal/core/bootstrap"
"github.com/testcontainers/testcontainers-go/log"
)

// DockerClient is a wrapper around the docker client that is used by testcontainers-go.
// It implements the SystemAPIClient interface in order to cache the docker info and reuse it.
type DockerClient struct {
*client.Client // client is embedded into our own client

config config.Config
}

var (
Expand Down Expand Up @@ -82,8 +86,8 @@ func (c *DockerClient) Info(ctx context.Context) (system.Info, error) {
internal.Version,
core.MustExtractDockerHost(ctx),
core.MustExtractDockerSocket(ctx),
core.SessionID(),
core.ProcessID(),
c.config.SessionID,
bootstrap.ProcessID(),
)

return dockerInfo, nil
Expand Down Expand Up @@ -122,6 +126,7 @@ func NewDockerClientWithOpts(ctx context.Context, opt ...client.Opt) (*DockerCli

tcClient := DockerClient{
Client: dockerClient,
config: config.Read(),
}

if _, err = tcClient.Info(ctx); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"sync"

"github.com/testcontainers/testcontainers-go/internal/config"
"github.com/testcontainers/testcontainers-go/internal/core"
"github.com/testcontainers/testcontainers-go/log"
)
Expand Down Expand Up @@ -109,7 +110,7 @@ type GenericProvider interface {
// reaper is enabled, otherwise this is excluded to prevent resources being
// incorrectly reaped.
func GenericLabels() map[string]string {
return core.DefaultLabels(core.SessionID())
return core.DefaultLabels(config.Read().SessionID)
}

// AddGenericLabels adds the generic labels to target.
Expand Down
16 changes: 16 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"

"github.com/magiconair/properties"

"github.com/testcontainers/testcontainers-go/internal/core/bootstrap"
)

const ReaperDefaultImage = "testcontainers/ryuk:0.12.0"
Expand Down Expand Up @@ -52,6 +54,13 @@ type Config struct {
// Environment variable: TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX
HubImageNamePrefix string `properties:"hub.image.name.prefix,default="`

// SessionID is the ID of the testing session.
// Setting this value will preclude runs from creating more than one reaper. Therefore,
// changes to ryuk settings past its creation will be ignored.
//
// Environment variable: TESTCONTAINERS_SESSION_ID
SessionID string `properties:"session.id,default="`

// RyukDisabled is a flag to enable or disable the Garbage Collector.
// Setting this to true will prevent testcontainers from automatically cleaning up
// resources, which is particularly important in tests which timeout as they
Expand Down Expand Up @@ -121,6 +130,13 @@ func read() Config {
config.HubImageNamePrefix = hubImageNamePrefix
}

sessionID := os.Getenv("TESTCONTAINERS_SESSION_ID")
if sessionID != "" {
config.SessionID = sessionID
} else if config.SessionID == "" {
config.SessionID = bootstrap.SessionID()
}

ryukPrivilegedEnv := os.Getenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED")
if parseBool(ryukPrivilegedEnv) {
config.RyukPrivileged = ryukPrivilegedEnv == "true"
Expand Down
Loading
Loading