Skip to content

Commit a053ad0

Browse files
committed
chore: use new ryuk variables, with a deprecation path
1 parent aecf00e commit a053ad0

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

docs/features/configuration.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ Please read more about customizing images in the [Image name substitution](image
5050
1. If your environment already implements automatic cleanup of containers after the execution,
5151
but does not allow starting privileged containers, you can turn off the Ryuk container by setting
5252
`TESTCONTAINERS_RYUK_DISABLED` **environment variable** , or the `ryuk.disabled` **property** to `true`.
53-
1. You can specify the connection timeout for Ryuk by setting the `TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT` **environment variable**, or the `ryuk.connection.timeout` **property**. The default value is 1 minute.
54-
1. You can specify the reconnection timeout for Ryuk by setting the `TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT` **environment variable**, or the `ryuk.reconnection.timeout` **property**. The default value is 10 seconds.
55-
1. You can configure Ryuk to run in verbose mode by setting any of the `ryuk.verbose` **property** or the `TESTCONTAINERS_RYUK_VERBOSE` **environment variable**. The default value is `false`.
53+
1. You can specify the connection timeout for Ryuk by setting the `RYUK_CONNECTION_TIMEOUT` **environment variable**, or the `ryuk.connection.timeout` **property**. The default value is 1 minute.
54+
1. You can specify the reconnection timeout for Ryuk by setting the `RYUK_RECONNECTION_TIMEOUT` **environment variable**, or the `ryuk.reconnection.timeout` **property**. The default value is 10 seconds.
55+
1. You can configure Ryuk to run in verbose mode by setting any of the `ryuk.verbose` **property** or the `RYUK_VERBOSE` **environment variable**. The default value is `false`.
5656

5757
!!!info
5858
For more information about Ryuk, see [Garbage Collector](garbage_collector.md).
@@ -62,6 +62,12 @@ but does not allow starting privileged containers, you can turn off the Ryuk con
6262
This is because the Compose module may take longer to start all the services. Besides, the `ryuk.reconnection.timeout`
6363
should be increased to at least 30 seconds. For further information, please check [https://github.com/testcontainers/testcontainers-go/pull/2485](https://github.com/testcontainers/testcontainers-go/pull/2485).
6464

65+
!!!warn
66+
The following environment variables for configuring Ryuk have been deprecated:
67+
`TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT`, `TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT` and
68+
`TESTCONTAINERS_RYUK_VERBOSE` have been replaced by `RYUK_CONNECTION_TIMEOUT`
69+
`RYUK_RECONNECTION_TIMEOUT` and `RYUK_VERBOSE` respectively.
70+
6571
## Docker host detection
6672

6773
_Testcontainers for Go_ will attempt to detect the Docker environment and configure everything to work automatically.

internal/config/config.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ type Config struct {
6868

6969
// RyukReconnectionTimeout is the time to wait before attempting to reconnect to the Garbage Collector container.
7070
//
71-
// Environment variable: TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT
71+
// Environment variable: RYUK_RECONNECTION_TIMEOUT
7272
RyukReconnectionTimeout time.Duration `properties:"ryuk.reconnection.timeout,default=10s"`
7373

7474
// RyukConnectionTimeout is the time to wait before timing out when connecting to the Garbage Collector container.
7575
//
76-
// Environment variable: TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT
76+
// Environment variable: RYUK_CONNECTION_TIMEOUT
7777
RyukConnectionTimeout time.Duration `properties:"ryuk.connection.timeout,default=1m"`
7878

7979
// RyukVerbose is a flag to enable or disable verbose logging for the Garbage Collector.
8080
//
81-
// Environment variable: TESTCONTAINERS_RYUK_VERBOSE
81+
// Environment variable: RYUK_VERBOSE
8282
RyukVerbose bool `properties:"ryuk.verbose,default=false"`
8383

8484
// TestcontainersHost is the address of the Testcontainers host.
@@ -126,17 +126,17 @@ func read() Config {
126126
config.RyukPrivileged = ryukPrivilegedEnv == "true"
127127
}
128128

129-
ryukVerboseEnv := os.Getenv("TESTCONTAINERS_RYUK_VERBOSE")
129+
ryukVerboseEnv := readTestcontainersEnv("RYUK_VERBOSE")
130130
if parseBool(ryukVerboseEnv) {
131131
config.RyukVerbose = ryukVerboseEnv == "true"
132132
}
133133

134-
ryukReconnectionTimeoutEnv := os.Getenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT")
134+
ryukReconnectionTimeoutEnv := readTestcontainersEnv("RYUK_RECONNECTION_TIMEOUT")
135135
if timeout, err := time.ParseDuration(ryukReconnectionTimeoutEnv); err == nil {
136136
config.RyukReconnectionTimeout = timeout
137137
}
138138

139-
ryukConnectionTimeoutEnv := os.Getenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT")
139+
ryukConnectionTimeoutEnv := readTestcontainersEnv("RYUK_CONNECTION_TIMEOUT")
140140
if timeout, err := time.ParseDuration(ryukConnectionTimeoutEnv); err == nil {
141141
config.RyukConnectionTimeout = timeout
142142
}
@@ -168,3 +168,18 @@ func parseBool(input string) bool {
168168
_, err := strconv.ParseBool(input)
169169
return err == nil
170170
}
171+
172+
// readTestcontainersEnv reads the environment variable with the given name.
173+
// It checks for the environment variable with the given name first, and then
174+
// checks for the environment variable with the given name prefixed with "TESTCONTAINERS_".
175+
func readTestcontainersEnv(envVar string) string {
176+
value := os.Getenv(envVar)
177+
if value != "" {
178+
return value
179+
}
180+
181+
// TODO: remove this prefix after the next major release
182+
const prefix string = "TESTCONTAINERS_"
183+
184+
return os.Getenv(prefix + envVar)
185+
}

internal/config/config_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func resetTestEnv(t *testing.T) {
2323
t.Setenv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", "")
2424
t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "")
2525
t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "")
26-
t.Setenv("TESTCONTAINERS_RYUK_VERBOSE", "")
27-
t.Setenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT", "")
28-
t.Setenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT", "")
26+
t.Setenv("RYUK_VERBOSE", "")
27+
t.Setenv("RYUK_RECONNECTION_TIMEOUT", "")
28+
t.Setenv("RYUK_CONNECTION_TIMEOUT", "")
2929
}
3030

3131
func TestReadConfig(t *testing.T) {
@@ -77,8 +77,8 @@ func TestReadTCConfig(t *testing.T) {
7777
t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true")
7878
t.Setenv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", defaultHubPrefix)
7979
t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true")
80-
t.Setenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT", "13s")
81-
t.Setenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT", "12s")
80+
t.Setenv("RYUK_RECONNECTION_TIMEOUT", "13s")
81+
t.Setenv("RYUK_CONNECTION_TIMEOUT", "12s")
8282

8383
config := read()
8484

@@ -125,9 +125,9 @@ func TestReadTCConfig(t *testing.T) {
125125
t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true")
126126
t.Setenv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", defaultHubPrefix)
127127
t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true")
128-
t.Setenv("TESTCONTAINERS_RYUK_VERBOSE", "true")
129-
t.Setenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT", "13s")
130-
t.Setenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT", "12s")
128+
t.Setenv("RYUK_VERBOSE", "true")
129+
t.Setenv("RYUK_RECONNECTION_TIMEOUT", "13s")
130+
t.Setenv("RYUK_CONNECTION_TIMEOUT", "12s")
131131

132132
config := read()
133133
expected := Config{
@@ -278,8 +278,8 @@ func TestReadTCConfig(t *testing.T) {
278278
"With Ryuk container timeouts configured using env vars",
279279
``,
280280
map[string]string{
281-
"TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT": "13s",
282-
"TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT": "12s",
281+
"RYUK_RECONNECTION_TIMEOUT": "13s",
282+
"RYUK_CONNECTION_TIMEOUT": "12s",
283283
},
284284
Config{
285285
RyukReconnectionTimeout: 13 * time.Second,
@@ -291,8 +291,8 @@ func TestReadTCConfig(t *testing.T) {
291291
`ryuk.connection.timeout=22s
292292
ryuk.reconnection.timeout=23s`,
293293
map[string]string{
294-
"TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT": "13s",
295-
"TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT": "12s",
294+
"RYUK_RECONNECTION_TIMEOUT": "13s",
295+
"RYUK_CONNECTION_TIMEOUT": "12s",
296296
},
297297
Config{
298298
RyukReconnectionTimeout: 13 * time.Second,
@@ -377,7 +377,7 @@ func TestReadTCConfig(t *testing.T) {
377377
"With Ryuk verbose using an env var and properties. Env var wins (0)",
378378
`ryuk.verbose=true`,
379379
map[string]string{
380-
"TESTCONTAINERS_RYUK_VERBOSE": "true",
380+
"RYUK_VERBOSE": "true",
381381
},
382382
Config{
383383
RyukVerbose: true,
@@ -389,7 +389,7 @@ func TestReadTCConfig(t *testing.T) {
389389
"With Ryuk verbose using an env var and properties. Env var wins (1)",
390390
`ryuk.verbose=false`,
391391
map[string]string{
392-
"TESTCONTAINERS_RYUK_VERBOSE": "true",
392+
"RYUK_VERBOSE": "true",
393393
},
394394
Config{
395395
RyukVerbose: true,
@@ -401,15 +401,15 @@ func TestReadTCConfig(t *testing.T) {
401401
"With Ryuk verbose using an env var and properties. Env var wins (2)",
402402
`ryuk.verbose=true`,
403403
map[string]string{
404-
"TESTCONTAINERS_RYUK_VERBOSE": "false",
404+
"RYUK_VERBOSE": "false",
405405
},
406406
defaultConfig,
407407
},
408408
{
409409
"With Ryuk verbose using an env var and properties. Env var wins (3)",
410410
`ryuk.verbose=false`,
411411
map[string]string{
412-
"TESTCONTAINERS_RYUK_VERBOSE": "false",
412+
"RYUK_VERBOSE": "false",
413413
},
414414
defaultConfig,
415415
},

0 commit comments

Comments
 (0)