Windows Runner with Linux Service Container #187246
-
Why are you starting this discussion?Question What GitHub Actions topic or product is this about?Actions Runner Image Discussion DetailsI'm working on a .Net open source project which multi-targets net472/netstandard2.0/net8.0/net10.0. To run test with code coverage analysis, I need to run the workflow on Windows runner, otherwise the tests targets net472 will fail. However, there are some tests are integration tests which require SQL Server/PostgresSql testing database (AdventureWorksLT). These database servers are running as Linux docker containers. It appears GitHub actions does not support this kind of mixed runner. Here is a sample repo: https://github.com/weifenluo/CITest/ I first tried using service containers in a windows runner, it is not supported. Then there are two GitHub workflow implemented: coverage.yml and coverage.windows.yml. The coverage.yml uses Linux runner end up with 1 out 3 tests failed (targeting net472); The coverage.windows.yml uses Windows runner with docker installed in WSL, which end up with all tests failed because the linux database containers cannot be connected. The other way I can think of is to have multiple jobs in the workflow, but I don't know how to connect database from test job (windows) to database job (linux). Is it possible? I tried something wild, by using Serveo to make database job public via SSH, with no luck (I believe it's blocked by the firewall). The only way I can get it working, is to use self hosted runner, running test locally on my laptop (Windows + Docker Desktop). Probably I should ask if Github actions provide such hosted environment? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
@fkerimk Thanks a lot for your reply. I added setup-wsl for a reason. Github's windows-latest image does have Docker Desktop pre-installed, but only support windows docker images :( To make the pre-installed Docker to support linux image, we must have WSL installed because we need a linux runtime. I also tried switch pre-installed Docker Desktop after setup-wsl, but with no luck - the DockerCli.exe does not even exist (It's installed under "C:\ProgramData\Docker"). If the pre-installed Docker can support Linux image, that would be no problem at all - that's how my laptop is configured. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
Here are a few options for a response, ranging from a direct technical fix to a more architectural advice style. You can choose the one that best fits your voice in the community. Option 1: The "Native Services" Approach (Most likely to solve the immediate problem) Subject: Re: Running mixed OS containers on Windows runners Hey @weifenluo, I feel your pain here. This is the classic conflict between legacy .NET Framework (which strictly needs Windows) and modern DevOps (which loves Linux containers). The core issue is that GitHub Actions Windows runners don't support Linux containers natively because they don't have the WSL2 backend enabled for Docker. Trying to hack around that with SSH tunnels or Docker-in-Docker on Windows is usually a rabbit hole of instability. Since you are forced to use the Windows runner for net472, the most reliable path is to ditch the containers for that specific job and use "native" Windows services instead: For SQL Server: The windows-latest image actually comes with SQL Server (LocalDB) pre-installed. You don't need a container. You just need to start the service or target (localdb)\MSSQLLocalDB in your connection string for the Windows run. For PostgreSQL: Since you can't run the Linux container, you can install the Windows version of Postgres directly on the runner using Chocolatey in a step before your tests run:
|
Beta Was this translation helpful? Give feedback.
-
|
It appears this cannot be supported, because the hypervisor does not support multiple levels of nested virtualization: https://github.com/orgs/community/discussions/25491 So @Codex2023-bits 's solution is the only way left. Good to know the windows-latest image already have SQL Server localDB pre-installed. Making the setup script a bit longer than a clean services YAML block is not a real problem, because we can make a custom resuable action to do that. Perhaps it's an opportunity for me to start writing my first GitHub action :). The real downside is CI is running differently on local and server, but it's acceptable for my case. |
Beta Was this translation helpful? Give feedback.
-
|
Finally get it working as @Codex2023-bits suggested approach: https://github.com/weifenluo/CITest/blob/main/.github/workflows/coverage.windows.yml Write two GitHub Actions: openentity/setup-adventuresworksltdb-mssql/openentity/setup-adventureworksltdb-postgres based on rails-sqlserver/setup-mssql/ikalnytskyi/action-setup-postgres It takes about 6 min to install and initialize MSSQL/Postgres databases. |
Beta Was this translation helpful? Give feedback.
Here are a few options for a response, ranging from a direct technical fix to a more architectural advice style. You can choose the one that best fits your voice in the community.
Option 1: The "Native Services" Approach (Most likely to solve the immediate problem)
Use this if you want to give him a way to keep running everything on the Windows runner without complex Docker hacks.
Subject: Re: Running mixed OS containers on Windows runners
Hey @weifenluo,
I feel your pain here. This is the classic conflict between legacy .NET Framework (which strictly needs Windows) and modern DevOps (which loves Linux containers).
The core issue is that GitHub Actions Windows runners don't support Linux …