为了执行单元测试和集成测试,我在gitlab中构建了以下CI。
stages:
- build
- test
variables:
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
cache:
key: "$CI_BUILD_REF"
paths:
- .m2/repository/
unit-tests:
image: maven:latest
stage: test
script:
- cd source_code
- mvn test -P test
intergration-tests:
image: docker
stage: test
services:
- docker:dind
script:
- apk add --no-cache docker-compose
- docker-compose up -d
- docker exec -t account_service_container sh "integration_tests.sh"
- docker-compose down --rmi all
重点是,当我在阶段之间使用Maven映像时,我能够将Maven依赖项缓存在m2存储库中。但是,在进行集成测试的情况下,我使用不同的映像,并且带有docker dind的容器使用docker-compose创建了一组隔离的容器,因此无需访问以前定义和缓存的mvn存储库。有什么解决办法吗我应该创建包括所有获取的和必需的mvn依赖项的自定义映像,并将其保留在docker hub上,然后在每个阶段之间以及在docker-compose中使用该映像。