从无法在gitlab CI中工作的资源读取文件

时间:2019-06-19 19:27:33

标签: java docker-compose gitlab gitlab-ci testcontainers

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

./gradlew clean test

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

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

@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文件。不确定为什么在运行代码时不可用。

1 个答案:

答案 0 :(得分:0)

基于Testcontainers文档here。 Gitlab CI上的Testcontainer需要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