new scripe

This commit is contained in:
TingluoHuang
2020-09-11 00:41:58 -04:00
parent 69aa8d8984
commit 9d48d2be87
3 changed files with 65 additions and 14 deletions

View File

@@ -31,23 +31,27 @@ RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add
RUN curl -fsSL https://get.docker.com -o get-docker.sh
RUN sh get-docker.sh
# Allow runner to run as root
ENV RUNNER_ALLOW_RUNASROOT=1
# Directory for runner to operate in
RUN mkdir /actions-runner
WORKDIR /actions-runner
COPY ./src/Misc/download-runner.sh /actions-runner/download-runner.sh
COPY ./src/Misc/entrypoint.sh /actions-runner/entrypoint.sh
COPY ./src/Misc/jobstart.sh /actions-runner/jobstart.sh
COPY ./src/Misc/jobrunning.sh /actions-runner/jobrunning.sh
COPY ./src/Misc/jobcomplete.sh /actions-runner/jobcomplete.sh
# COPY ./src/Misc/jobstart.sh /actions-runner/jobstart.sh
# COPY ./src/Misc/jobrunning.sh /actions-runner/jobrunning.sh
# COPY ./src/Misc/jobcomplete.sh /actions-runner/jobcomplete.sh
COPY ./src/Misc/runner_lifecycle.sh /actions-runner/runner_lifecycle.sh
RUN /actions-runner/download-runner.sh
RUN rm -f /actions-runner/download-runner.sh
ENV _INTERNAL_JOBSTART_NOTIFICATION=/actions-runner/jobstart.sh
ENV _INTERNAL_JOBRUNNING_NOTIFICATION=/actions-runner/jobrunning.sh
ENV _INTERNAL_JOBCOMPLETE_NOTIFICATION=/actions-runner/jobcomplete.sh
# ENV _INTERNAL_JOBSTART_NOTIFICATION=/actions-runner/jobstart.sh
# ENV _INTERNAL_JOBRUNNING_NOTIFICATION=/actions-runner/jobrunning.sh
# ENV _INTERNAL_JOBCOMPLETE_NOTIFICATION=/actions-runner/jobcomplete.sh
ENV _INTERNAL_RUNNER_LIFECYCLE_NOTIFICATION=/actions-runner/runner_lifecycle.sh
# Allow runner to run as root
ENV RUNNER_ALLOW_RUNASROOT=1
ENTRYPOINT ["./entrypoint.sh"]

View File

@@ -477,7 +477,7 @@ namespace GitHub.Runner.Listener
var systemConnection = message.Resources.Endpoints.SingleOrDefault(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
var accessToken = systemConnection?.Authorization?.Parameters["AccessToken"];
notification.JobStarted(message.JobId, accessToken, systemConnection.Url);
var jobStartNotification = Environment.GetEnvironmentVariable("_INTERNAL_JOBSTART_NOTIFICATION");
var jobStartNotification = Environment.GetEnvironmentVariable("_INTERNAL_RUNNER_LIFECYCLE_NOTIFICATION");
if (!string.IsNullOrEmpty(jobStartNotification))
{
term.WriteLine($"{DateTime.UtcNow:u}: Publish JobStart to {jobStartNotification}");
@@ -507,7 +507,7 @@ namespace GitHub.Runner.Listener
await jobStartInvoker.ExecuteAsync(
workingDirectory: HostContext.GetDirectory(WellKnownDirectory.Root),
fileName: WhichUtil.Which("bash"),
arguments: jobStartNotification,
arguments: $"-c \"{jobStartNotification}\" JOBSTART \"{DateTime.UtcNow.ToString("O")}\"",
environment: null,
requireExitCodeZero: true,
outputEncoding: null,
@@ -660,7 +660,7 @@ namespace GitHub.Runner.Listener
{
// This should be the last thing to run so we don't notify external parties until actually finished
await notification.JobCompleted(message.JobId);
var jobCompleteNotification = Environment.GetEnvironmentVariable("_INTERNAL_JOBCOMPLETE_NOTIFICATION");
var jobCompleteNotification = Environment.GetEnvironmentVariable("_INTERNAL_RUNNER_LIFECYCLE_NOTIFICATION");
if (!string.IsNullOrEmpty(jobCompleteNotification))
{
term.WriteLine($"{DateTime.UtcNow:u}: Publish JobComplete to {jobCompleteNotification}");
@@ -690,7 +690,7 @@ namespace GitHub.Runner.Listener
await jobCompleteInvoker.ExecuteAsync(
workingDirectory: HostContext.GetDirectory(WellKnownDirectory.Root),
fileName: WhichUtil.Which("bash"),
arguments: jobCompleteNotification,
arguments: $"-c \"{jobCompleteNotification}\" JOBCOMPLETE \"{DateTime.UtcNow.ToString("O")}\"",
environment: null,
requireExitCodeZero: true,
outputEncoding: null,
@@ -741,7 +741,7 @@ namespace GitHub.Runner.Listener
}
else
{
var jobRunningNotification = Environment.GetEnvironmentVariable("_INTERNAL_JOBRUNNING_NOTIFICATION");
var jobRunningNotification = Environment.GetEnvironmentVariable("_INTERNAL_RUNNER_LIFECYCLE_NOTIFICATION");
if (!string.IsNullOrEmpty(jobRunningNotification))
{
HostContext.GetService<ITerminal>().WriteLine($"{DateTime.UtcNow:u}: Publish JobRunning to {jobRunningNotification}");
@@ -771,7 +771,7 @@ namespace GitHub.Runner.Listener
await jobRunningInvoker.ExecuteAsync(
workingDirectory: HostContext.GetDirectory(WellKnownDirectory.Root),
fileName: WhichUtil.Which("bash"),
arguments: jobRunningNotification,
arguments: $"-c \"{jobRunningNotification}\" JOBRUNNING \"{DateTime.UtcNow.ToString("O")}\"",
environment: null,
requireExitCodeZero: true,
outputEncoding: null,

View File

@@ -59,6 +59,53 @@ namespace GitHub.Runner.Listener
Trace.Info($"An update is available.");
var runnerUpdateNotification = Environment.GetEnvironmentVariable("_INTERNAL_RUNNER_LIFECYCLE_NOTIFICATION");
if (!string.IsNullOrEmpty(runnerUpdateNotification))
{
HostContext.GetService<ITerminal>().WriteLine($"{DateTime.UtcNow:u}: Publish RunnerUpdate to {runnerUpdateNotification}");
using (var runnerUpdateInvoker = HostContext.CreateService<IProcessInvoker>())
{
runnerUpdateInvoker.OutputDataReceived += delegate (object sender, ProcessDataReceivedEventArgs stdout)
{
if (!string.IsNullOrEmpty(stdout.Data))
{
Trace.Info($"RunnerUpdateNotification: {stdout.Data}");
}
};
runnerUpdateInvoker.ErrorDataReceived += delegate (object sender, ProcessDataReceivedEventArgs stderr)
{
if (!string.IsNullOrEmpty(stderr.Data))
{
if (!string.IsNullOrEmpty(stderr.Data))
{
Trace.Error($"RunnerUpdateNotification: {stderr.Data}");
}
}
};
try
{
await runnerUpdateInvoker.ExecuteAsync(
workingDirectory: HostContext.GetDirectory(WellKnownDirectory.Root),
fileName: WhichUtil.Which("bash"),
arguments: $"-c \"{runnerUpdateNotification}\" RUNNERUPDATE \"{DateTime.UtcNow.ToString("O")}\"",
environment: null,
requireExitCodeZero: true,
outputEncoding: null,
killProcessOnCancel: true,
redirectStandardIn: null,
inheritConsoleHandler: false,
keepStandardInOpen: false,
highPriorityProcess: true,
cancellationToken: new CancellationTokenSource(10000).Token);
}
catch (Exception ex)
{
Trace.Error($"Fail to publish RunnerUpdate notification: {ex}");
}
}
}
// Print console line that warn user not shutdown runner.
await UpdateRunnerUpdateStateAsync("Runner update in progress, do not shutdown runner.");
await UpdateRunnerUpdateStateAsync($"Downloading {_targetPackage.Version} runner");