Skip to content

Commit

Permalink
Fallback from Node 20 to Node 16
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisRumyantsev committed Sep 11, 2024
1 parent 363ba84 commit c306151
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/Agent.Worker/ContainerOperationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c306151

Please sign in to comment.