diff --git a/src/Runner.Worker/Container/DockerCommandManager.cs b/src/Runner.Worker/Container/DockerCommandManager.cs index ad9c074c4..6451a568d 100644 --- a/src/Runner.Worker/Container/DockerCommandManager.cs +++ b/src/Runner.Worker/Container/DockerCommandManager.cs @@ -276,9 +276,7 @@ namespace GitHub.Runner.Worker.Container return await ExecuteDockerCommandAsync(context, "exec", $"{options} {containerId} {command}", context.CancellationToken); } -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously (method has async logic on only certain platforms) public async Task DockerExec(IExecutionContext context, string containerId, string options, string command, List output) -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { ArgUtil.NotNull(output, nameof(output)); @@ -309,9 +307,10 @@ namespace GitHub.Runner.Worker.Container } }; -#if OS_WINDOWS || OS_OSX - throw new NotSupportedException($"Container operation is only supported on Linux"); -#else + if (!Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) + { + throw new NotSupportedException("Container operations are only supported on Linux runners"); + } return await processInvoker.ExecuteAsync( workingDirectory: HostContext.GetDirectory(WellKnownDirectory.Work), fileName: DockerPath, @@ -320,7 +319,6 @@ namespace GitHub.Runner.Worker.Container requireExitCodeZero: false, outputEncoding: null, cancellationToken: CancellationToken.None); -#endif } public async Task> DockerInspect(IExecutionContext context, string dockerObject, string options) @@ -339,9 +337,7 @@ namespace GitHub.Runner.Worker.Container return ExecuteDockerCommandAsync(context, command, options, null, cancellationToken); } -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously (method has async logic on only certain platforms) private async Task ExecuteDockerCommandAsync(IExecutionContext context, string command, string options, IDictionary environment, EventHandler stdoutDataReceived, EventHandler stderrDataReceived, CancellationToken cancellationToken = default(CancellationToken)) -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { string arg = $"{command} {options}".Trim(); context.Command($"{DockerPath} {arg}"); @@ -351,9 +347,10 @@ namespace GitHub.Runner.Worker.Container processInvoker.ErrorDataReceived += stderrDataReceived; -#if OS_WINDOWS || OS_OSX - throw new NotSupportedException($"Container operation is only supported on Linux"); -#else + if (!Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) + { + throw new NotSupportedException("Container operations are only supported on Linux runners"); + } return await processInvoker.ExecuteAsync( workingDirectory: context.GetGitHubContext("workspace"), fileName: DockerPath, @@ -363,12 +360,9 @@ namespace GitHub.Runner.Worker.Container outputEncoding: null, killProcessOnCancel: false, cancellationToken: cancellationToken); -#endif } -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously (method has async logic on only certain platforms) private async Task ExecuteDockerCommandAsync(IExecutionContext context, string command, string options, string workingDirectory, CancellationToken cancellationToken = default(CancellationToken)) -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { string arg = $"{command} {options}".Trim(); context.Command($"{DockerPath} {arg}"); @@ -384,9 +378,10 @@ namespace GitHub.Runner.Worker.Container context.Output(message.Data); }; -#if OS_WINDOWS || OS_OSX - throw new NotSupportedException($"Container operation is only supported on Linux"); -#else + if (!Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) + { + throw new NotSupportedException("Container operations are only supported on Linux runners"); + } return await processInvoker.ExecuteAsync( workingDirectory: workingDirectory ?? context.GetGitHubContext("workspace"), fileName: DockerPath, @@ -397,7 +392,6 @@ namespace GitHub.Runner.Worker.Container killProcessOnCancel: false, redirectStandardIn: null, cancellationToken: cancellationToken); -#endif } private async Task> ExecuteDockerCommandAsync(IExecutionContext context, string command, string options) diff --git a/src/Runner.Worker/ContainerOperationProvider.cs b/src/Runner.Worker/ContainerOperationProvider.cs index a1646e7ed..162c55a14 100644 --- a/src/Runner.Worker/ContainerOperationProvider.cs +++ b/src/Runner.Worker/ContainerOperationProvider.cs @@ -35,6 +35,10 @@ namespace GitHub.Runner.Worker public async Task StartContainersAsync(IExecutionContext executionContext, object data) { Trace.Entering(); + if (!Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) + { + throw new NotSupportedException("Container operations are only supported on Linux runners"); + } ArgUtil.NotNull(executionContext, nameof(executionContext)); List containers = data as List; ArgUtil.NotNull(containers, nameof(containers)); diff --git a/src/Runner.Worker/Handlers/StepHost.cs b/src/Runner.Worker/Handlers/StepHost.cs index b368c4360..08edc91a2 100644 --- a/src/Runner.Worker/Handlers/StepHost.cs +++ b/src/Runner.Worker/Handlers/StepHost.cs @@ -141,6 +141,13 @@ namespace GitHub.Runner.Worker.Handlers executionContext.Debug(line); if (line.ToLower().Contains("alpine")) { + if (!Constants.Runner.PlatformArchitecture.Equals(Constants.Architecture.X64)) + { + var os = Constants.Runner.Platform.ToString(); + var arch = Constants.Runner.PlatformArchitecture.ToString(); + var msg = $"JavaScript Actions in Alpine containers are only supported on x64 Linux runners. Detected {os} {arch}"; + throw new NotSupportedException(msg); + } nodeExternal = "node12_alpine"; executionContext.Output($"Container distribution is alpine. Running JavaScript Action with external tool: {nodeExternal}"); return nodeExternal;