0

使用以下命令在 gitlab CI 上运行测试时出现错误:

./gradlew clean test

我正在使用测试容器来运行我的测试:https ://www.testcontainers.org/modules/docker_compose/

这是我用来加载位于 src/test/resources 的 docker compose 文件的代码。

@ClassRule
public static DockerComposeContainer container = new DockerComposeContainer(new File(BaseServiceTest.class.getClassLoader().getResource("docker-compose.yml").getFile()));

我在本地运行时运行良好,在 gitlab 上运行 ci 时购买,我收到以下错误:

{"timestamp":"2019-06-17T18:47:44.903Z","level":"ERROR","thread":"Test worker","logger":"docker[docker/compose:1.8.0]","message":"Log output from the failed container:\n.IOError: [Errno 2] No such file or directory: '/builds/xxxx/xxxx/xxxx-xxxx/src/test/resources/docker-compose.yml'\n","context":"default"}

以下是我的 gitlab-ci.yml 文件:

include:
  - project: 'xxxx/xxxx/sdlc'
    file: '/sdlc.yml'

variables:
  CONTAINER_NAME: xxxx-xxxx

test:
  stage: test
  image: registry.xxxx.com/xxxx-alpine-jdk8:v1_8_181
  script:
    - ls -la src/test/resources
    - ./gradlew clean test -i

在我的脚本中,我有ls -la src/test/resources并且可以在运行该脚本时看到该docker-compose.yml文件。不知道为什么在运行代码时它不可用。

4

1 回答 1

0

基于此处的 Testcontainers 文档。Gitlab CI 上的测试容器需要 DinD 服务

这里有一个例子:

# DinD service is required for Testcontainers
services:
  - docker:dind

variables:
  # Instruct Testcontainers to use the daemon of DinD.
  DOCKER_HOST: "tcp://docker:2375"
  # Improve performance with overlayfs.
  DOCKER_DRIVER: overlay2

test:
 image: gradle:5.0
 stage: test
 script: ./gradlew test
于 2019-06-19T19:53:35.307 回答