mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
GitHub Actions Runner
This commit is contained in:
49
src/Runner.Worker/Container/DockerUtil.cs
Normal file
49
src/Runner.Worker/Container/DockerUtil.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace GitHub.Runner.Worker.Container
|
||||
{
|
||||
public class DockerUtil
|
||||
{
|
||||
public static List<PortMapping> ParseDockerPort(IList<string> portMappingLines)
|
||||
{
|
||||
const string targetPort = "targetPort";
|
||||
const string proto = "proto";
|
||||
const string host = "host";
|
||||
const string hostPort = "hostPort";
|
||||
|
||||
//"TARGET_PORT/PROTO -> HOST:HOST_PORT"
|
||||
string pattern = $"^(?<{targetPort}>\\d+)/(?<{proto}>\\w+) -> (?<{host}>.+):(?<{hostPort}>\\d+)$";
|
||||
|
||||
List<PortMapping> portMappings = new List<PortMapping>();
|
||||
foreach(var line in portMappingLines)
|
||||
{
|
||||
Match m = Regex.Match(line, pattern, RegexOptions.None, TimeSpan.FromSeconds(1));
|
||||
if (m.Success)
|
||||
{
|
||||
portMappings.Add(new PortMapping(
|
||||
m.Groups[hostPort].Value,
|
||||
m.Groups[targetPort].Value,
|
||||
m.Groups[proto].Value
|
||||
));
|
||||
}
|
||||
}
|
||||
return portMappings;
|
||||
}
|
||||
|
||||
public static string ParsePathFromConfigEnv(IList<string> configEnvLines)
|
||||
{
|
||||
// Config format is VAR=value per line
|
||||
foreach (var line in configEnvLines)
|
||||
{
|
||||
var keyValue = line.Split("=", 2);
|
||||
if (keyValue.Length == 2 && string.Equals(keyValue[0], "PATH"))
|
||||
{
|
||||
return keyValue[1];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user