mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
Moved service containers error logs to separate group sections
This commit is contained in:
@@ -16,6 +16,7 @@ namespace GitHub.Runner.Worker.Container
|
|||||||
{
|
{
|
||||||
string DockerPath { get; }
|
string DockerPath { get; }
|
||||||
string DockerInstanceLabel { get; }
|
string DockerInstanceLabel { get; }
|
||||||
|
IList<ContainerInfo> UnhealthyContainers {get; set; }
|
||||||
Task<DockerVersion> DockerVersion(IExecutionContext context);
|
Task<DockerVersion> DockerVersion(IExecutionContext context);
|
||||||
Task<int> DockerPull(IExecutionContext context, string image);
|
Task<int> DockerPull(IExecutionContext context, string image);
|
||||||
Task<int> DockerPull(IExecutionContext context, string image, string configFileDirectory);
|
Task<int> DockerPull(IExecutionContext context, string image, string configFileDirectory);
|
||||||
@@ -42,6 +43,8 @@ namespace GitHub.Runner.Worker.Container
|
|||||||
|
|
||||||
public string DockerInstanceLabel { get; private set; }
|
public string DockerInstanceLabel { get; private set; }
|
||||||
|
|
||||||
|
public IList<ContainerInfo> UnhealthyContainers {get; set; }
|
||||||
|
|
||||||
public override void Initialize(IHostContext hostContext)
|
public override void Initialize(IHostContext hostContext)
|
||||||
{
|
{
|
||||||
base.Initialize(hostContext);
|
base.Initialize(hostContext);
|
||||||
|
|||||||
@@ -100,20 +100,33 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
|
|
||||||
executionContext.Output("##[group]Waiting for all services to be ready");
|
executionContext.Output("##[group]Waiting for all services to be ready");
|
||||||
|
|
||||||
bool IsAnyUnhealthy = false;
|
bool IsAnyUnhealthy = false;
|
||||||
|
_dockerManager.UnhealthyContainers = new List<ContainerInfo>();
|
||||||
foreach (var container in containers.Where(c => !c.IsJobContainer))
|
foreach (var container in containers.Where(c => !c.IsJobContainer))
|
||||||
{
|
{
|
||||||
|
|
||||||
var healthcheck = await Healthcheck(executionContext, container);
|
var healthcheck = await Healthcheck(executionContext, container);
|
||||||
if (!string.Equals(healthcheck, "healthy", StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(healthcheck, "healthy", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
IsAnyUnhealthy = true;
|
IsAnyUnhealthy = true;
|
||||||
|
_dockerManager.UnhealthyContainers.Add(container);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
executionContext.Output($"{container.ContainerNetworkAlias} service is healthy.");
|
||||||
}
|
}
|
||||||
await ContainerHealthcheckLogs(executionContext, container, healthcheck);
|
|
||||||
}
|
}
|
||||||
if (IsAnyUnhealthy) throw new InvalidOperationException("One or more containers failed to start.");
|
|
||||||
executionContext.Output("##[endgroup]");
|
executionContext.Output("##[endgroup]");
|
||||||
|
|
||||||
|
if (IsAnyUnhealthy)
|
||||||
|
{
|
||||||
|
foreach (var container in _dockerManager.UnhealthyContainers)
|
||||||
|
{
|
||||||
|
executionContext.Output($"##[group]Service container {container.ContainerNetworkAlias} failed.");
|
||||||
|
await ContainerErrorLogs(executionContext, container);
|
||||||
|
executionContext.Output("##[endgroup]");
|
||||||
|
}
|
||||||
|
throw new InvalidOperationException("One or more containers failed to start.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHello()
|
public void printHello()
|
||||||
@@ -323,7 +336,7 @@ namespace GitHub.Runner.Worker
|
|||||||
if (string.Equals(healthcheck, "healthy", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(healthcheck, "healthy", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
// Print logs for service container jobs (not the "action" job itself b/c that's already logged).
|
// Print logs for service container jobs (not the "action" job itself b/c that's already logged).
|
||||||
// Print them only if the service was healthy, else they were already logged via ContainerHealthCheckLogs.
|
// Print them only if the service was healthy, else they were already logged in the initialize containers section.
|
||||||
executionContext.Output($"Print service container logs: {container.ContainerDisplayName}");
|
executionContext.Output($"Print service container logs: {container.ContainerDisplayName}");
|
||||||
|
|
||||||
int logsExitCode = await _dockerManager.DockerLogs(executionContext, container.ContainerId);
|
int logsExitCode = await _dockerManager.DockerLogs(executionContext, container.ContainerId);
|
||||||
@@ -439,21 +452,12 @@ namespace GitHub.Runner.Worker
|
|||||||
return serviceHealth;
|
return serviceHealth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ContainerHealthcheckLogs(IExecutionContext executionContext, ContainerInfo container, string serviceHealth)
|
public async Task ContainerErrorLogs(IExecutionContext executionContext, ContainerInfo container)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (string.Equals(serviceHealth, "healthy", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
executionContext.Output($"{container.ContainerNetworkAlias} service is healthy.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
executionContext.Output($"Container {container.ContainerImage} failed healthchecks, printing logs:");
|
|
||||||
await _dockerManager.DockerLogs(context: executionContext, containerId: container.ContainerId);
|
await _dockerManager.DockerLogs(context: executionContext, containerId: container.ContainerId);
|
||||||
executionContext.Error($"Failed to initialize container {container.ContainerImage}");
|
executionContext.Error($"Failed to initialize container {container.ContainerImage}");
|
||||||
container.IsHealthy = false;
|
container.IsHealthy = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<string> ContainerRegistryLogin(IExecutionContext executionContext, ContainerInfo container)
|
private async Task<string> ContainerRegistryLogin(IExecutionContext executionContext, ContainerInfo container)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user