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
2
Answers
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.
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)