diff --git a/src/Agent.Worker/ContainerOperationProvider.cs b/src/Agent.Worker/ContainerOperationProvider.cs index 68e9cecdbe..10cfb7bb7b 100644 --- a/src/Agent.Worker/ContainerOperationProvider.cs +++ b/src/Agent.Worker/ContainerOperationProvider.cs @@ -532,30 +532,34 @@ private async Task StartContainerAsync(IExecutionContext executionContext, Conta dockerObject: container.ContainerImage, options: $"--format=\"{{{{index .Config.Labels \\\"{_nodeJsPathLabel}\\\"}}}}\""); - string node; + string getNodeSetInterval(string node) + { + return $"\"{node}\" -e \"setInterval(function(){{}}, 24 * 60 * 60 * 1000);\""; + } + if (!string.IsNullOrEmpty(container.CustomNodePath)) { - node = container.CustomNodePath; + container.ContainerCommand = getNodeSetInterval(container.CustomNodePath); + } + else if (PlatformUtil.RunningOnMacOS || (PlatformUtil.RunningOnWindows && container.ImageOS == PlatformUtil.OS.Linux)) + { + // require container to have node if running on macOS, or if running on Windows and attempting to run Linux container + container.CustomNodePath = "node"; + container.ContainerCommand = getNodeSetInterval(container.CustomNodePath); } else { - node = container.TranslateToContainerPath(Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), AgentKnobs.UseNode20ToStartContainer.GetValue(executionContext).AsBoolean() ? NodeHandler.Node20_1Folder : NodeHandler.NodeFolder, "bin", $"node{IOUtil.ExeExtension}")); - - // if on Mac OS X, require container to have node - if (PlatformUtil.RunningOnMacOS) - { - container.CustomNodePath = "node"; - node = container.CustomNodePath; - } - // if running on Windows, and attempting to run linux container, require container to have node - else if (PlatformUtil.RunningOnWindows && container.ImageOS == PlatformUtil.OS.Linux) + string getContainerNodePath(string nodeFolder) { - container.CustomNodePath = "node"; - node = container.CustomNodePath; + return container.TranslateToContainerPath(Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), nodeFolder, "bin", $"node{IOUtil.ExeExtension}")); } + + string node = getNodeSetInterval(getContainerNodePath(NodeHandler.NodeFolder)); + string node16 = getNodeSetInterval(getContainerNodePath(NodeHandler.Node16Folder)); + string node20 = getNodeSetInterval(getContainerNodePath(NodeHandler.Node20_1Folder)); + + container.ContainerCommand = AgentKnobs.UseNode20ToStartContainer.GetValue(executionContext).AsBoolean() ? $"{node20} || {node16}" : node; } - string sleepCommand = $"\"{node}\" -e \"setInterval(function(){{}}, 24 * 60 * 60 * 1000);\""; - container.ContainerCommand = sleepCommand; } container.ContainerId = await _dockerManger.DockerCreate(executionContext, container);