问题描述
我们在 testcontainers-java 项目中大量使用 spring-boot-admin。由于我们还希望能够在 Windows 上运行我们的 Maven 构建,因此我们使用矩阵策略构建 (as supposed in this answer) 向我们的 GitHub 操作管道添加了一个 windows-latest
环境,如下所示:
name: build
on:
push:
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest,windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: |
mvn -B install --no-transfer-progress
现在我们的 Testcontainers JUnit 测试用例失败(参见 full build log):
[INFO] Running de.codecentric.boot.admin.server.eventstore.HazelcastEventStoreWithClientConfigTest
Error: Tests run: 1,Failures: 0,Errors: 1,Skipped: 0,Time elapsed: 0.877 s <<< FAILURE! - in de.codecentric.boot.admin.server.eventstore.HazelcastEventStoreWithClientConfigTest
Error: de.codecentric.boot.admin.server.eventstore.HazelcastEventStoreWithClientConfigTest Time elapsed: 0.877 s <<< ERROR!
java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
那么知道我们可以做些什么来解决这个问题吗?
解决方法
问题是在 Windows Server 中,默认情况下只有 Windows 容器被激活(没有 Linux 容器)。 As Sergei Egorov stated:
windows-latest 的问题在于它使用 Windows 容器,而不是 Linux 容器。这意味着 Testcontainers 本身可以工作,但它启动的所有映像都是基于 Linux 的,并且在 Windows 容器模式下,它们显然无法启动:)
对此的“修复”是拥有启用 Linux 容器的 GitHub Action 环境!但经过一些谷歌搜索后,这似乎并不那么容易。首先,我认为 LCOW(Windows 上的 Linux 容器)只需要启用即可。但正如 this great elaboration 所述,在 GitHub Actions Windows 环境中激活 LCOW 并不容易(甚至不可能)。
我深入研究了这个问题,发现 that LCOW was officially deprecated in 20.10
? 支持 WSL2,它带来了原生 Linux 运行时和 Docker for Desktop on Windows 10 already favours this approach。
但是:我们使用的是 Windows Server 2019,而不是 Windows 10 桌面版。在 GitHub Actions 上,我们只有 nano 风格的服务器版本。遗憾的是an open issue for the WSL2 support in Windows Server 2019。扫描 GitHub Actions Windows Server 2019 docs 我发现现在只安装了 WSLv1。