mirror of
https://github.com/actions/runner.git
synced 2025-12-12 05:37:01 +00:00
Compare commits
2 Commits
docker-log
...
thboop/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0508abb77 | ||
|
|
75786756bb |
@@ -16,7 +16,7 @@ We should give them that option, and publish examples how how they can create th
|
|||||||
- For example, the current runner overrides `HOME`, we can do that in the hook, but we shouldn't pass that hook as an ENV with the other env's the user has set, as that is not user input, it is how the runner invokes containers
|
- For example, the current runner overrides `HOME`, we can do that in the hook, but we shouldn't pass that hook as an ENV with the other env's the user has set, as that is not user input, it is how the runner invokes containers
|
||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
- You will set the variable `ACTIONS_RUNNER_CONTAINER_HOOK=/Users/foo/runner/hooks.js` which is the entrypoint to your hook handler.
|
- You will set the variable `ACTIONS_RUNNER_CONTAINER_HOOKS=/Users/foo/runner/hooks.js` which is the entrypoint to your hook handler.
|
||||||
- There is no partial opt in, you must handle every hook
|
- There is no partial opt in, you must handle every hook
|
||||||
- We will pass a command and some args via `stdin`
|
- We will pass a command and some args via `stdin`
|
||||||
- An exit code of 0 is a success, every other exit code is a failure
|
- An exit code of 0 is a success, every other exit code is a failure
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ namespace GitHub.Runner.Worker
|
|||||||
ArgUtil.NotNull(executionContext, nameof(executionContext));
|
ArgUtil.NotNull(executionContext, nameof(executionContext));
|
||||||
ArgUtil.NotNull(container, nameof(container));
|
ArgUtil.NotNull(container, nameof(container));
|
||||||
ArgUtil.NotNullOrEmpty(container.ContainerImage, nameof(container.ContainerImage));
|
ArgUtil.NotNullOrEmpty(container.ContainerImage, nameof(container.ContainerImage));
|
||||||
|
|
||||||
Trace.Info($"Container name: {container.ContainerName}");
|
Trace.Info($"Container name: {container.ContainerName}");
|
||||||
Trace.Info($"Container image: {container.ContainerImage}");
|
Trace.Info($"Container image: {container.ContainerImage}");
|
||||||
Trace.Info($"Container options: {container.ContainerCreateOptions}");
|
Trace.Info($"Container options: {container.ContainerCreateOptions}");
|
||||||
@@ -197,8 +198,6 @@ namespace GitHub.Runner.Worker
|
|||||||
container.ContainerId = await _dockerManager.DockerCreate(executionContext, container);
|
container.ContainerId = await _dockerManager.DockerCreate(executionContext, container);
|
||||||
ArgUtil.NotNullOrEmpty(container.ContainerId, nameof(container.ContainerId));
|
ArgUtil.NotNullOrEmpty(container.ContainerId, nameof(container.ContainerId));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Start container
|
// Start container
|
||||||
int startExitCode = await _dockerManager.DockerStart(executionContext, container.ContainerId);
|
int startExitCode = await _dockerManager.DockerStart(executionContext, container.ContainerId);
|
||||||
if (startExitCode != 0)
|
if (startExitCode != 0)
|
||||||
@@ -208,36 +207,19 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
// Make sure container is up and running
|
// Make sure container is up and running
|
||||||
var psOutputs = await _dockerManager.DockerPS(executionContext, $"--all --filter id={container.ContainerId} --filter status=running --no-trunc --format \"{{{{.ID}}}} {{{{.Status}}}}\"");
|
var psOutputs = await _dockerManager.DockerPS(executionContext, $"--all --filter id={container.ContainerId} --filter status=running --no-trunc --format \"{{{{.ID}}}} {{{{.Status}}}}\"");
|
||||||
|
|
||||||
if (psOutputs.FirstOrDefault(x => !string.IsNullOrEmpty(x))?.StartsWith(container.ContainerId) != true)
|
if (psOutputs.FirstOrDefault(x => !string.IsNullOrEmpty(x))?.StartsWith(container.ContainerId) != true)
|
||||||
{
|
{
|
||||||
// container is not up and running, pull docker log for this container.
|
// container is not up and running, pull docker log for this container.
|
||||||
await _dockerManager.DockerPS(executionContext, $"--all --filter id={container.ContainerId} --no-trunc --format \"{{{{.ID}}}} {{{{.Status}}}}\"");
|
await _dockerManager.DockerPS(executionContext, $"--all --filter id={container.ContainerId} --no-trunc --format \"{{{{.ID}}}} {{{{.Status}}}}\"");
|
||||||
|
|
||||||
|
|
||||||
//executionContext.Output("##[group]Getting docker logs..");
|
|
||||||
|
|
||||||
int logsExitCode = await _dockerManager.DockerLogs(executionContext, container.ContainerId);
|
int logsExitCode = await _dockerManager.DockerLogs(executionContext, container.ContainerId);
|
||||||
|
|
||||||
if (logsExitCode != 0)
|
if (logsExitCode != 0)
|
||||||
{
|
{
|
||||||
executionContext.Warning($"Docker logs fail with exit code {logsExitCode}");
|
executionContext.Warning($"Docker logs fail with exit code {logsExitCode}");
|
||||||
}
|
}
|
||||||
//executionContext.Output("##[endgroup]");
|
|
||||||
executionContext.Warning($"Docker container {container.ContainerId} is not in running state.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
executionContext.Output($"##[group]Container {container.ContainerId} is not running!");
|
|
||||||
string opt = "--format=\'{{.State.ExitCode}}\'";
|
|
||||||
await _dockerManager.DockerInspect(executionContext, container.ContainerId, opt);
|
|
||||||
await _dockerManager.DockerLogs(executionContext, container.ContainerId);
|
|
||||||
//if exit code is not 0 we can maybe print a message?
|
|
||||||
//executionContext.Output("Container exit code: ");
|
|
||||||
|
|
||||||
executionContext.Output("##[endgroup]");
|
executionContext.Warning($"Docker container {container.ContainerId} is not in running state.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ namespace GitHub.Runner.Worker
|
|||||||
// Keep track of embedded steps states
|
// Keep track of embedded steps states
|
||||||
Dictionary<Guid, Dictionary<string, string>> EmbeddedIntraActionState { get; }
|
Dictionary<Guid, Dictionary<string, string>> EmbeddedIntraActionState { get; }
|
||||||
|
|
||||||
|
IList<Issue> EmbeddedIssues { get; }
|
||||||
|
|
||||||
bool EchoOnActionCommand { get; set; }
|
bool EchoOnActionCommand { get; set; }
|
||||||
|
|
||||||
bool IsEmbedded { get; }
|
bool IsEmbedded { get; }
|
||||||
@@ -91,6 +93,7 @@ namespace GitHub.Runner.Worker
|
|||||||
void SetOutput(string name, string value, out string reference);
|
void SetOutput(string name, string value, out string reference);
|
||||||
void SetTimeout(TimeSpan? timeout);
|
void SetTimeout(TimeSpan? timeout);
|
||||||
void AddIssue(Issue issue, string message = null);
|
void AddIssue(Issue issue, string message = null);
|
||||||
|
void AddIssueToTimelineRecord(Issue issue);
|
||||||
void Progress(int percentage, string currentOperation = null);
|
void Progress(int percentage, string currentOperation = null);
|
||||||
void UpdateDetailTimelineRecord(TimelineRecord record);
|
void UpdateDetailTimelineRecord(TimelineRecord record);
|
||||||
|
|
||||||
@@ -180,6 +183,8 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
public Dictionary<Guid, Dictionary<string, string>> EmbeddedIntraActionState { get; private set; }
|
public Dictionary<Guid, Dictionary<string, string>> EmbeddedIntraActionState { get; private set; }
|
||||||
|
|
||||||
|
public IList<Issue> EmbeddedIssues { get; } = new List<Issue>();
|
||||||
|
|
||||||
public bool EchoOnActionCommand { get; set; }
|
public bool EchoOnActionCommand { get; set; }
|
||||||
|
|
||||||
// An embedded execution context shares the same record ID, record name, and logger
|
// An embedded execution context shares the same record ID, record name, and logger
|
||||||
@@ -575,7 +580,31 @@ namespace GitHub.Runner.Worker
|
|||||||
long logLineNumber = Write(WellKnownTags.Error, logMessage);
|
long logLineNumber = Write(WellKnownTags.Error, logMessage);
|
||||||
issue.Data["logFileLineNumber"] = logLineNumber.ToString();
|
issue.Data["logFileLineNumber"] = logLineNumber.ToString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (issue.Type == IssueType.Warning)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(logMessage))
|
||||||
|
{
|
||||||
|
long logLineNumber = Write(WellKnownTags.Warning, logMessage);
|
||||||
|
issue.Data["logFileLineNumber"] = logLineNumber.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (issue.Type == IssueType.Notice)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(logMessage))
|
||||||
|
{
|
||||||
|
long logLineNumber = Write(WellKnownTags.Notice, logMessage);
|
||||||
|
issue.Data["logFileLineNumber"] = logLineNumber.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AddIssueToTimelineRecord(issue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddIssueToTimelineRecord(Issue issue)
|
||||||
|
{
|
||||||
|
ArgUtil.NotNull(issue, nameof(issue));
|
||||||
|
if (issue.Type == IssueType.Error)
|
||||||
|
{
|
||||||
if (_record.ErrorCount < _maxIssueCount)
|
if (_record.ErrorCount < _maxIssueCount)
|
||||||
{
|
{
|
||||||
_record.Issues.Add(issue);
|
_record.Issues.Add(issue);
|
||||||
@@ -585,12 +614,6 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
else if (issue.Type == IssueType.Warning)
|
else if (issue.Type == IssueType.Warning)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(logMessage))
|
|
||||||
{
|
|
||||||
long logLineNumber = Write(WellKnownTags.Warning, logMessage);
|
|
||||||
issue.Data["logFileLineNumber"] = logLineNumber.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_record.WarningCount < _maxIssueCount)
|
if (_record.WarningCount < _maxIssueCount)
|
||||||
{
|
{
|
||||||
_record.Issues.Add(issue);
|
_record.Issues.Add(issue);
|
||||||
@@ -600,12 +623,6 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
else if (issue.Type == IssueType.Notice)
|
else if (issue.Type == IssueType.Notice)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(logMessage))
|
|
||||||
{
|
|
||||||
long logLineNumber = Write(WellKnownTags.Notice, logMessage);
|
|
||||||
issue.Data["logFileLineNumber"] = logLineNumber.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_record.NoticeCount < _maxIssueCount)
|
if (_record.NoticeCount < _maxIssueCount)
|
||||||
{
|
{
|
||||||
_record.Issues.Add(issue);
|
_record.Issues.Add(issue);
|
||||||
@@ -613,10 +630,19 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
_record.NoticeCount++;
|
_record.NoticeCount++;
|
||||||
}
|
}
|
||||||
|
// Composite actions should never upload a timeline record to the server
|
||||||
|
// We add these to a list and let composite action handler bubble it up recursively
|
||||||
|
if (this.IsEmbedded)
|
||||||
|
{
|
||||||
|
EmbeddedIssues.Add(issue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_jobServerQueue.QueueTimelineRecordUpdate(_mainTimelineId, _record);
|
_jobServerQueue.QueueTimelineRecordUpdate(_mainTimelineId, _record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateDetailTimelineRecord(TimelineRecord record)
|
public void UpdateDetailTimelineRecord(TimelineRecord record)
|
||||||
{
|
{
|
||||||
ArgUtil.NotNull(record, nameof(record));
|
ArgUtil.NotNull(record, nameof(record));
|
||||||
|
|||||||
@@ -413,6 +413,12 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
|
|
||||||
// Update context
|
// Update context
|
||||||
step.ExecutionContext.UpdateGlobalStepsContext();
|
step.ExecutionContext.UpdateGlobalStepsContext();
|
||||||
|
|
||||||
|
// Update annotations
|
||||||
|
foreach (var issue in step.ExecutionContext.EmbeddedIssues)
|
||||||
|
{
|
||||||
|
ExecutionContext.AddIssueToTimelineRecord(issue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
preJobSteps.Add(new JobExtensionRunner(runAsync: containerProvider.StartContainersAsync,
|
preJobSteps.Add(new JobExtensionRunner(runAsync: containerProvider.StartContainersAsync,
|
||||||
condition: $"{PipelineTemplateConstants.Success}()",
|
condition: $"{PipelineTemplateConstants.Success}()",
|
||||||
displayName: "**Initialize containers**",
|
displayName: "Initialize containers",
|
||||||
data: (object)containers));
|
data: (object)containers));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user