Skip to content

Commit 9267eae

Browse files
allow dind via Feature Flag (#565)
* system.runner.server.allow_dind
1 parent b653ce3 commit 9267eae

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

src/Runner.Worker/ContainerOperationProvider.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -578,29 +578,31 @@ private void UpdateRegistryAuthForGitHubToken(IExecutionContext executionContext
578578

579579
private async Task AssertCompatibleOS(IExecutionContext executionContext)
580580
{
581-
// Check whether we are inside a container.
582-
// Our container feature requires to map working directory from host to the container.
583-
// If we are already inside a container, we will not able to find out the real working direcotry path on the host.
584-
if(System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) {
585-
// service CExecSvc is Container Execution Agent.
586-
ServiceController[] scServices = ServiceController.GetServices();
587-
if (scServices.Any(x => String.Equals(x.ServiceName, "cexecsvc", StringComparison.OrdinalIgnoreCase) && x.Status == ServiceControllerStatus.Running))
588-
{
589-
throw new NotSupportedException("Container feature is not supported when runner is already running inside container.");
590-
}
591-
} else {
592-
IEnumerable<string> initProcessCgroup = null;
593-
try
594-
{
595-
initProcessCgroup = File.ReadLines("/proc/1/cgroup");
596-
}
597-
catch
598-
{
599-
// This fails on macOS
600-
}
601-
if (initProcessCgroup != null && initProcessCgroup.Any(x => x.IndexOf(":/docker/", StringComparison.OrdinalIgnoreCase) >= 0))
602-
{
603-
throw new NotSupportedException("Container feature is not supported when runner is already running inside container.");
581+
if ((executionContext.Global.Variables.GetBoolean("system.runner.server.allow_dind") ?? false) == false) {
582+
// Check whether we are inside a container.
583+
// Our container feature requires to map working directory from host to the container.
584+
// If we are already inside a container, we will not able to find out the real working direcotry path on the host.
585+
if(System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) {
586+
// service CExecSvc is Container Execution Agent.
587+
ServiceController[] scServices = ServiceController.GetServices();
588+
if (scServices.Any(x => String.Equals(x.ServiceName, "cexecsvc", StringComparison.OrdinalIgnoreCase) && x.Status == ServiceControllerStatus.Running))
589+
{
590+
throw new NotSupportedException("Container feature is not supported when runner is already running inside container.");
591+
}
592+
} else {
593+
IEnumerable<string> initProcessCgroup = null;
594+
try
595+
{
596+
initProcessCgroup = File.ReadLines("/proc/1/cgroup");
597+
}
598+
catch
599+
{
600+
// This fails on macOS
601+
}
602+
if (initProcessCgroup != null && initProcessCgroup.Any(x => x.IndexOf(":/docker/", StringComparison.OrdinalIgnoreCase) >= 0))
603+
{
604+
throw new NotSupportedException("Container feature is not supported when runner is already running inside container.");
605+
}
604606
}
605607
}
606608

0 commit comments

Comments
 (0)