Skip to content

Commit

Permalink
refactor: read RYUK_CONTAINER_PRIVILEGED once
Browse files Browse the repository at this point in the history
Now the environment variable `TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED`
is read only once, right after the `.testcontainers.properties` is read
in the Docker client creation.
  • Loading branch information
zregvart committed Jul 1, 2022
1 parent f93cdb4 commit cf12297
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ func WithDefaultBridgeNetwork(bridgeNetworkName string) DockerProviderOption {

func NewDockerClient() (cli *client.Client, host string, tcConfig TestContainersConfig, err error) {
tcConfig = readTCPropsFile()
if !tcConfig.RyukPrivileged && os.Getenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED") == "true" {
tcConfig.RyukPrivileged = true
}

host = tcConfig.Host

opts := []client.Opt{client.FromEnv}
Expand Down
4 changes: 1 addition & 3 deletions reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ func NewReaper(ctx context.Context, sessionID string, provider ReaperProvider, r
}

tcConfig := provider.Config()
if tcConfig.RyukPrivileged || os.Getenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED") == "true" {
req.Privileged = true
}
req.Privileged = tcConfig.RyukPrivileged

// Attach reaper container to a requested network if it is specified
if p, ok := provider.(*DockerProvider); ok {
Expand Down

0 comments on commit cf12297

Please sign in to comment.