From 2cec4a1a76724a031360f03afefbb70a5e5c4bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 29 Oct 2024 01:41:04 +0100 Subject: [PATCH] chore: bump ryuk to 0.11.0 (#2853) * chore: bump ryuk * chore: use new ryuk variables, with a deprecation path --- docs/features/configuration.md | 12 +++++++++--- internal/config/config.go | 29 ++++++++++++++++++++++------- internal/config/config_test.go | 32 ++++++++++++++++---------------- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/docs/features/configuration.md b/docs/features/configuration.md index ee5b6a4d69..8da214e977 100644 --- a/docs/features/configuration.md +++ b/docs/features/configuration.md @@ -50,9 +50,9 @@ Please read more about customizing images in the [Image name substitution](image 1. If your environment already implements automatic cleanup of containers after the execution, but does not allow starting privileged containers, you can turn off the Ryuk container by setting `TESTCONTAINERS_RYUK_DISABLED` **environment variable** , or the `ryuk.disabled` **property** to `true`. -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. -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. -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`. +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. +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. +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`. !!!info 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 This is because the Compose module may take longer to start all the services. Besides, the `ryuk.reconnection.timeout` 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). +!!!warn + The following environment variables for configuring Ryuk have been deprecated: + `TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT`, `TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT` and + `TESTCONTAINERS_RYUK_VERBOSE` have been replaced by `RYUK_CONNECTION_TIMEOUT` + `RYUK_RECONNECTION_TIMEOUT` and `RYUK_VERBOSE` respectively. + ## Docker host detection _Testcontainers for Go_ will attempt to detect the Docker environment and configure everything to work automatically. diff --git a/internal/config/config.go b/internal/config/config.go index b0bcc24d3b..85be6acd86 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,7 +11,7 @@ import ( "github.com/magiconair/properties" ) -const ReaperDefaultImage = "testcontainers/ryuk:0.10.2" +const ReaperDefaultImage = "testcontainers/ryuk:0.11.0" var ( tcConfig Config @@ -68,17 +68,17 @@ type Config struct { // RyukReconnectionTimeout is the time to wait before attempting to reconnect to the Garbage Collector container. // - // Environment variable: TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT + // Environment variable: RYUK_RECONNECTION_TIMEOUT RyukReconnectionTimeout time.Duration `properties:"ryuk.reconnection.timeout,default=10s"` // RyukConnectionTimeout is the time to wait before timing out when connecting to the Garbage Collector container. // - // Environment variable: TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT + // Environment variable: RYUK_CONNECTION_TIMEOUT RyukConnectionTimeout time.Duration `properties:"ryuk.connection.timeout,default=1m"` // RyukVerbose is a flag to enable or disable verbose logging for the Garbage Collector. // - // Environment variable: TESTCONTAINERS_RYUK_VERBOSE + // Environment variable: RYUK_VERBOSE RyukVerbose bool `properties:"ryuk.verbose,default=false"` // TestcontainersHost is the address of the Testcontainers host. @@ -126,17 +126,17 @@ func read() Config { config.RyukPrivileged = ryukPrivilegedEnv == "true" } - ryukVerboseEnv := os.Getenv("TESTCONTAINERS_RYUK_VERBOSE") + ryukVerboseEnv := readTestcontainersEnv("RYUK_VERBOSE") if parseBool(ryukVerboseEnv) { config.RyukVerbose = ryukVerboseEnv == "true" } - ryukReconnectionTimeoutEnv := os.Getenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT") + ryukReconnectionTimeoutEnv := readTestcontainersEnv("RYUK_RECONNECTION_TIMEOUT") if timeout, err := time.ParseDuration(ryukReconnectionTimeoutEnv); err == nil { config.RyukReconnectionTimeout = timeout } - ryukConnectionTimeoutEnv := os.Getenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT") + ryukConnectionTimeoutEnv := readTestcontainersEnv("RYUK_CONNECTION_TIMEOUT") if timeout, err := time.ParseDuration(ryukConnectionTimeoutEnv); err == nil { config.RyukConnectionTimeout = timeout } @@ -168,3 +168,18 @@ func parseBool(input string) bool { _, err := strconv.ParseBool(input) return err == nil } + +// readTestcontainersEnv reads the environment variable with the given name. +// It checks for the environment variable with the given name first, and then +// checks for the environment variable with the given name prefixed with "TESTCONTAINERS_". +func readTestcontainersEnv(envVar string) string { + value := os.Getenv(envVar) + if value != "" { + return value + } + + // TODO: remove this prefix after the next major release + const prefix string = "TESTCONTAINERS_" + + return os.Getenv(prefix + envVar) +} diff --git a/internal/config/config_test.go b/internal/config/config_test.go index c5b48244bd..f1c7d3bbf3 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -23,9 +23,9 @@ func resetTestEnv(t *testing.T) { t.Setenv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", "") t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "") t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "") - t.Setenv("TESTCONTAINERS_RYUK_VERBOSE", "") - t.Setenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT", "") - t.Setenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT", "") + t.Setenv("RYUK_VERBOSE", "") + t.Setenv("RYUK_RECONNECTION_TIMEOUT", "") + t.Setenv("RYUK_CONNECTION_TIMEOUT", "") } func TestReadConfig(t *testing.T) { @@ -77,8 +77,8 @@ func TestReadTCConfig(t *testing.T) { t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true") t.Setenv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", defaultHubPrefix) t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true") - t.Setenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT", "13s") - t.Setenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT", "12s") + t.Setenv("RYUK_RECONNECTION_TIMEOUT", "13s") + t.Setenv("RYUK_CONNECTION_TIMEOUT", "12s") config := read() @@ -125,9 +125,9 @@ func TestReadTCConfig(t *testing.T) { t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true") t.Setenv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", defaultHubPrefix) t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true") - t.Setenv("TESTCONTAINERS_RYUK_VERBOSE", "true") - t.Setenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT", "13s") - t.Setenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT", "12s") + t.Setenv("RYUK_VERBOSE", "true") + t.Setenv("RYUK_RECONNECTION_TIMEOUT", "13s") + t.Setenv("RYUK_CONNECTION_TIMEOUT", "12s") config := read() expected := Config{ @@ -278,8 +278,8 @@ func TestReadTCConfig(t *testing.T) { "With Ryuk container timeouts configured using env vars", ``, map[string]string{ - "TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT": "13s", - "TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT": "12s", + "RYUK_RECONNECTION_TIMEOUT": "13s", + "RYUK_CONNECTION_TIMEOUT": "12s", }, Config{ RyukReconnectionTimeout: 13 * time.Second, @@ -291,8 +291,8 @@ func TestReadTCConfig(t *testing.T) { `ryuk.connection.timeout=22s ryuk.reconnection.timeout=23s`, map[string]string{ - "TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT": "13s", - "TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT": "12s", + "RYUK_RECONNECTION_TIMEOUT": "13s", + "RYUK_CONNECTION_TIMEOUT": "12s", }, Config{ RyukReconnectionTimeout: 13 * time.Second, @@ -377,7 +377,7 @@ func TestReadTCConfig(t *testing.T) { "With Ryuk verbose using an env var and properties. Env var wins (0)", `ryuk.verbose=true`, map[string]string{ - "TESTCONTAINERS_RYUK_VERBOSE": "true", + "RYUK_VERBOSE": "true", }, Config{ RyukVerbose: true, @@ -389,7 +389,7 @@ func TestReadTCConfig(t *testing.T) { "With Ryuk verbose using an env var and properties. Env var wins (1)", `ryuk.verbose=false`, map[string]string{ - "TESTCONTAINERS_RYUK_VERBOSE": "true", + "RYUK_VERBOSE": "true", }, Config{ RyukVerbose: true, @@ -401,7 +401,7 @@ func TestReadTCConfig(t *testing.T) { "With Ryuk verbose using an env var and properties. Env var wins (2)", `ryuk.verbose=true`, map[string]string{ - "TESTCONTAINERS_RYUK_VERBOSE": "false", + "RYUK_VERBOSE": "false", }, defaultConfig, }, @@ -409,7 +409,7 @@ func TestReadTCConfig(t *testing.T) { "With Ryuk verbose using an env var and properties. Env var wins (3)", `ryuk.verbose=false`, map[string]string{ - "TESTCONTAINERS_RYUK_VERBOSE": "false", + "RYUK_VERBOSE": "false", }, defaultConfig, },