From 29367a883d4e2302e5ca7ae775bef00ba74bf901 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 12 Dec 2022 09:33:02 +0100 Subject: [PATCH] feat(#694): Add Resource Reaper (Ryuk) privileged mode support (#710) --- CHANGELOG.md | 3 ++- .../Configurations/TestcontainersSettings.cs | 7 +++++++ src/Testcontainers/Containers/ResourceReaper.cs | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e59363aba..f26540313 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ - 531 Add Docker health status wait strategy (@kfrajtak) - 640 Add `ITestcontainersBuilder.WithResourceMapping` to copy files or or any binary contents into the created container even before it is started - 654 Add `ITestcontainersNetworkBuilder.WithOption` (@vlaskal) -- 678 Add support of custom configuration `TESTCONTAINERS_HOST_OVERRIDE` and `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE`. +- 678 Add support of custom configuration `TESTCONTAINERS_HOST_OVERRIDE` and `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE` +- 694 Add Resource Reaper (Ryuk) privileged mode support (`TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED`) ### Changed diff --git a/src/Testcontainers/Configurations/TestcontainersSettings.cs b/src/Testcontainers/Configurations/TestcontainersSettings.cs index 54c2cd020..8a46628f5 100644 --- a/src/Testcontainers/Configurations/TestcontainersSettings.cs +++ b/src/Testcontainers/Configurations/TestcontainersSettings.cs @@ -118,6 +118,13 @@ static TestcontainersSettings() public static bool ResourceReaperEnabled { get; set; } = !PropertiesFileConfiguration.Instance.GetRyukDisabled() && !EnvironmentConfiguration.Instance.GetRyukDisabled(); + /// + /// Gets or sets a value indicating whether the privileged mode is enabled or not. + /// + [PublicAPI] + public static bool ResourceReaperPrivilegedModeEnabled { get; set; } + = PropertiesFileConfiguration.Instance.GetRyukContainerPrivileged() || EnvironmentConfiguration.Instance.GetRyukContainerPrivileged(); + /// /// Gets or sets the image. /// diff --git a/src/Testcontainers/Containers/ResourceReaper.cs b/src/Testcontainers/Containers/ResourceReaper.cs index 60600e4be..b3ab255bb 100644 --- a/src/Testcontainers/Containers/ResourceReaper.cs +++ b/src/Testcontainers/Containers/ResourceReaper.cs @@ -58,6 +58,7 @@ private ResourceReaper(Guid sessionId, IDockerEndpointAuthenticationConfiguratio .WithName($"testcontainers-ryuk-{sessionId:D}") .WithDockerEndpoint(dockerEndpointAuthConfig) .WithImage(resourceReaperImage) + .WithPrivileged(requiresPrivilegedMode) .WithAutoRemove(true) .WithCleanUp(false) .WithExposedPort(RyukPort) @@ -131,7 +132,9 @@ await DefaultLock.WaitAsync(ct) var resourceReaperImage = TestcontainersSettings.ResourceReaperImage ?? RyukImage; - defaultInstance = await GetAndStartNewAsync(DefaultSessionId, dockerEndpointAuthConfig, resourceReaperImage, UnixSocketMount.Instance, ct: ct) + var requiresPrivilegedMode = TestcontainersSettings.ResourceReaperPrivilegedModeEnabled; + + defaultInstance = await GetAndStartNewAsync(DefaultSessionId, dockerEndpointAuthConfig, resourceReaperImage, UnixSocketMount.Instance, requiresPrivilegedMode, ct: ct) .ConfigureAwait(false); return defaultInstance;