diff --git a/src/Runner.Worker/Container/DockerCommandManager.cs b/src/Runner.Worker/Container/DockerCommandManager.cs index 86cf0eeedf2..82d4366975c 100644 --- a/src/Runner.Worker/Container/DockerCommandManager.cs +++ b/src/Runner.Worker/Container/DockerCommandManager.cs @@ -162,6 +162,12 @@ public async Task DockerCreate(IExecutionContext context, ContainerInfo { // Named Docker volume / host bind mount volumeArg = $"-v \"{volume.SourceVolumePath.Replace("\"", "\\\"")}\":\"{volume.TargetVolumePath.Replace("\"", "\\\"")}\""; +#if OS_WINDOWS + if (!Directory.Exists(volume.SourceVolumePath)) + { + Directory.CreateDirectory(volume.SourceVolumePath); + } +#endif } if (volume.ReadOnly) { @@ -333,9 +339,9 @@ public async Task DockerExec(IExecutionContext context, string containerId, } }; - if (!Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) + if (!(Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux) || (Constants.Runner.Platform.Equals(Constants.OSPlatform.Windows) && Constants.Runner.PlatformArchitecture.Equals(Constants.Architecture.X64)))) { - throw new NotSupportedException("Container operations are only supported on Linux runners"); + throw new NotSupportedException("Container operations are only supported on Linux or 64 bit Windows server runners"); } return await processInvoker.ExecuteAsync( workingDirectory: HostContext.GetDirectory(WellKnownDirectory.Work), @@ -395,9 +401,9 @@ public Task DockerLogin(IExecutionContext context, string configFileDirecto processInvoker.ErrorDataReceived += stderrDataReceived; - if (!Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) + if (!(Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux) || (Constants.Runner.Platform.Equals(Constants.OSPlatform.Windows) && Constants.Runner.PlatformArchitecture.Equals(Constants.Architecture.X64)))) { - throw new NotSupportedException("Container operations are only supported on Linux runners"); + throw new NotSupportedException("Container operations are only supported on Linux or 64 bit Windows server runners"); } return await processInvoker.ExecuteAsync( workingDirectory: context.GetGitHubContext("workspace"), @@ -426,9 +432,9 @@ public Task DockerLogin(IExecutionContext context, string configFileDirecto context.Output(message.Data); }; - if (!Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) + if (!(Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux) || (Constants.Runner.Platform.Equals(Constants.OSPlatform.Windows) && Constants.Runner.PlatformArchitecture.Equals(Constants.Architecture.X64)))) { - throw new NotSupportedException("Container operations are only supported on Linux runners"); + throw new NotSupportedException("Container operations are only supported on Linux or 64 bit Windows server runners"); } return await processInvoker.ExecuteAsync( workingDirectory: workingDirectory ?? context.GetGitHubContext("workspace"), diff --git a/src/Runner.Worker/ContainerOperationProvider.cs b/src/Runner.Worker/ContainerOperationProvider.cs index 62ef1df473c..3badba195a8 100644 --- a/src/Runner.Worker/ContainerOperationProvider.cs +++ b/src/Runner.Worker/ContainerOperationProvider.cs @@ -35,9 +35,9 @@ public override void Initialize(IHostContext hostContext) public async Task StartContainersAsync(IExecutionContext executionContext, object data) { Trace.Entering(); - if (!Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) + if (!(Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux) || (Constants.Runner.Platform.Equals(Constants.OSPlatform.Windows) && Constants.Runner.PlatformArchitecture.Equals(Constants.Architecture.X64)))) { - throw new NotSupportedException("Container operations are only supported on Linux runners"); + throw new NotSupportedException("Container operations are only supported on Linux or 64 bit Windows server runners"); } ArgUtil.NotNull(executionContext, nameof(executionContext)); List containers = data as List; @@ -256,18 +256,33 @@ private async Task StartContainerAsync(IExecutionContext executionContext, Conta var tempHomeDirectory = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Temp), "_github_home"); Directory.CreateDirectory(tempHomeDirectory); +#if OS_WINDOWS + container.MountVolumes.Add(new MountVolume(tempHomeDirectory, "C:\\ghhome")); + container.AddPathTranslateMapping(tempHomeDirectory, "C:\\ghhome"); +#else container.MountVolumes.Add(new MountVolume(tempHomeDirectory, "/github/home")); container.AddPathTranslateMapping(tempHomeDirectory, "/github/home"); +#endif container.ContainerEnvironmentVariables["HOME"] = container.TranslateToContainerPath(tempHomeDirectory); var tempWorkflowDirectory = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Temp), "_github_workflow"); Directory.CreateDirectory(tempWorkflowDirectory); +#if OS_WINDOWS + container.MountVolumes.Add(new MountVolume(tempWorkflowDirectory, "C:\\ghworkflow")); + container.AddPathTranslateMapping(tempWorkflowDirectory, "C:\\ghworkflow"); +#else container.MountVolumes.Add(new MountVolume(tempWorkflowDirectory, "/github/workflow")); container.AddPathTranslateMapping(tempWorkflowDirectory, "/github/workflow"); +#endif container.ContainerWorkDirectory = container.TranslateToContainerPath(workingDirectory); +#if OS_WINDOWS + //container.ContainerEntryPoint = "ping"; + container.ContainerEntryPointArgs = "\"ping\" \"-t\" \"localhost\""; +#else container.ContainerEntryPoint = "tail"; container.ContainerEntryPointArgs = "\"-f\" \"/dev/null\""; +#endif } container.ContainerId = await _dockerManager.DockerCreate(executionContext, container);