Gitlab-CI Docker In Docker with Dotnet Testcontainers
下午好,各位。我正在尝试在使用 nuget 包的 DotNet 项目上运行 Gitlab-CI 管道 https://github .com/HofmeisterAn/dotnet-testcontainers 用于在测试执行期间管理 docker 容器。在过去的几天里,我尝试了许多不同的配置变化,包括结合 Dotnet 和 docker 的自定义 docker 镜像。然而,可能由于我缺乏 CI/CD 领域的知识,我尚未获得成功的构建。最终结果是我无法让所有码头工人适当地相互交谈。我正在寻求任何帮助来设置此构建系统。
谢谢。
当前配置:
在 Windows 上运行 Docker Desktop (4.5.1),并在设置中启用 Expose 守护进程。
Gitlab-Runner 在本地注册并运行\
<前><代码>[[跑步者]] name =“Siegeon Docker Runner” url =“https://gitlab.com/” 令牌=“保留” 执行者=“码头工人” [runners.custom_build_dir] [跑步者缓存] [runners.cache.s3] [runners.cache.gcs] [runners.cache.azure] [跑步者.docker] tls_verify = false 图像=“码头工人:稳定” 特权=真 禁用_入口点_覆盖=假 oom_kill_disable = false 禁用缓存=假 卷= [“/缓存”] shm_大小 = 0Gitlab-ci.yml
<前><代码>阶段: - 测试 测试覆盖率: 图片:mcr.microsoft.com/dotnet/sdk:6.0 阶段:测试 服务: 服务: # 测试容器需要 DinD 服务 - 名称:docker:dind 命令:[“--tls = false”] 之前的脚本: - 码头工人信息 变量: # 指示 Docker 不要通过 TLS 启动。 DOCKER_TLS_CERTDIR:“” # 使用overlayfs 提高性能。 DOCKER_DRIVER:覆盖2 DOCKER_HOST: tcp://docker:2375 配置:“调试” COVERAGE_FLAG:“XPlat 代码覆盖率” LOGGER_FLAG:“junit;LogFilePath=$CI_PROJECT_DIR/junit/junit-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose” 脚本: - '点网测试 -c $配置 -r $CI_PROJECT_DIR/cobertura --collect:"$COVERAGE_FLAG" --测试适配器路径:。 --logger:"$LOGGER_FLAG"' - 光盘脚本 - chmod +x print-dotnet-coverage.sh - ./print-dotnet-coverage.sh $CI_PROJECT_DIR/cobertura 覆盖范围:/TOTAL_COVERAGE=(\d+.\d+)/ 文物: 路径: - $CI_PROJECT_DIR/cobertura/*/coverage.cobertura.xml - $CI_PROJECT_DIR/junit/junit-test-result.xml 报告: 科贝图拉: - $CI_PROJECT_DIR/cobertura/*/coverage.cobertura.xml 朱尼特: - $CI_PROJECT_DIR/junit/junit-test-result.xml
Gitlab 日志
```
Running with gitlab-runner 14.7.0 (98daeee0)
on Siegeon Docker Runner TdwgDJWA
Preparing the "docker" executor
00:50
Using Docker executor with image mcr.microsoft.com/dotnet/sdk:6.0 ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:1a42336ff683d7dadd320ea6fe9d93a5b101474346302d23f96c9b4546cb414d
for docker:dind with digest docker@sha256:6f2ae4a5fd85ccf85cdd829057a34ace894d25d544e5e4d9f2e7109297fedf8d ...
Waiting for services to be up and running...
*** WARNING: Service runner-tdwgdjwa-project-33678908-concurrent-0-82673b37ef5d9ae1-docker-0 probably didn't start properly.
Health check error:
service "runner-tdwgdjwa-project-33678908-concurrent-0-82673b37ef5d9ae1-docker-0-wait-for-service" timeout
Health check container logs:
Service container logs:
2022-03-02T17:34:46.439281600Z time="2022-03-02T17:34:46.438975100Z" level=info msg="Starting up"
2022-03-02T17:34:46.440522500Z time="2022-03-02T17:34:46.440396800Z" level=warning msg="could not change group
/var/run/docker.sock to docker: group docker not found"
```
Good afternoon, folks. I am attempting to run a Gitlab-CI pipeline on a DotNet project that utilizes the nuget package https://github.com/HofmeisterAn/dotnet-testcontainers to manage docker containers during test execution. Over the past few days, I have tried many different configuration variations, including custom docker images incorporating Dotnet and docker. However, likely due to my lack of knowledge in the CI/CD area, I have yet to get a successful build. The net result is that I cannot get all of the dockers to talk to each other appropriately. I am reaching out for any help in getting this build system setup.
Thank you.
Current Configuration:
Docker Desktop (4.5.1) running on windows with Expose daemon enabled in the settings.
Gitlab-Runner registered and running locally\
[[runners]] name = "Siegeon Docker Runner" url = "https://gitlab.com/" token = "withheld" executor = "docker" [runners.custom_build_dir] [runners.cache] [runners.cache.s3] [runners.cache.gcs] [runners.cache.azure] [runners.docker] tls_verify = false image = "docker:stable" privileged = true disable_entrypoint_overwrite = false oom_kill_disable = false disable_cache = false volumes = ["/cache"] shm_size = 0
Gitlab-ci.yml
stages: - tests test-with-coverage: image: mcr.microsoft.com/dotnet/sdk:6.0 stage: tests services: services: # DinD service is required for Testcontainers - name: docker:dind command: ["--tls=false"] before_script: - docker info variables: # Instruct Docker not to start over TLS. DOCKER_TLS_CERTDIR: "" # Improve performance with overlayfs. DOCKER_DRIVER: overlay2 DOCKER_HOST: tcp://docker:2375 CONFIGURATION: "Debug" COVERAGE_FLAG: "XPlat Code Coverage" LOGGER_FLAG: "junit;LogFilePath=$CI_PROJECT_DIR/junit/junit-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose" script: - 'dotnet test -c $CONFIGURATION -r $CI_PROJECT_DIR/cobertura --collect:"$COVERAGE_FLAG" --test-adapter-path:. --logger:"$LOGGER_FLAG"' - cd scripts - chmod +x print-dotnet-coverage.sh - ./print-dotnet-coverage.sh $CI_PROJECT_DIR/cobertura coverage: /TOTAL_COVERAGE=(\d+.\d+)/ artifacts: paths: - $CI_PROJECT_DIR/cobertura/*/coverage.cobertura.xml - $CI_PROJECT_DIR/junit/junit-test-result.xml reports: cobertura: - $CI_PROJECT_DIR/cobertura/*/coverage.cobertura.xml junit: - $CI_PROJECT_DIR/junit/junit-test-result.xml
Gitlab logs
```
Running with gitlab-runner 14.7.0 (98daeee0)
on Siegeon Docker Runner TdwgDJWA
Preparing the "docker" executor
00:50
Using Docker executor with image mcr.microsoft.com/dotnet/sdk:6.0 ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:1a42336ff683d7dadd320ea6fe9d93a5b101474346302d23f96c9b4546cb414d
for docker:dind with digest docker@sha256:6f2ae4a5fd85ccf85cdd829057a34ace894d25d544e5e4d9f2e7109297fedf8d ...
Waiting for services to be up and running...
*** WARNING: Service runner-tdwgdjwa-project-33678908-concurrent-0-82673b37ef5d9ae1-docker-0 probably didn't start properly.
Health check error:
service "runner-tdwgdjwa-project-33678908-concurrent-0-82673b37ef5d9ae1-docker-0-wait-for-service" timeout
Health check container logs:
Service container logs:
2022-03-02T17:34:46.439281600Z time="2022-03-02T17:34:46.438975100Z" level=info msg="Starting up"
2022-03-02T17:34:46.440522500Z time="2022-03-02T17:34:46.440396800Z" level=warning msg="could not change group
/var/run/docker.sock to docker: group docker not found"
```
9/27/2022 For completeness
During the initialization of build I reconfigured the docker host
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当使用 testcontainers-dotnet 与 .net6.0 结合使用时,此示例确实对我有用,ef核心和 gitlab 管道。希望它可以帮助别人。
初始化测试容器的应用程序代码:
gitlab-ci.yaml(测试作业部分)
This example did work for me when using testcontainers-dotnet in combination with .net6.0, ef core and the gitlab pipeline. Hope it can help someone.
Application Code to initialize Testcontainers:
gitlab-ci.yaml (test job part)
我不确定它是否 100% 兼容,但是 Testcontainers-java 的 Gitlab 示例配置 有一些差异:
在禁用 TLS 的情况下启动 docker:
此外,
DOCKER_HOST
字符串也不同:希望这些配置会改变它工作方式与 Testcontainers-java 构建类似。
I'm not sure it's 100% compatible, but Testcontainers-java's example config for Gitlab has a few differences:
Start docker with TLS disabled:
Also the
DOCKER_HOST
string is different:Hope with these config changes it works just like for the Testcontainers-java builds.