From aba9032487a0b2f414187bf4597cf0ce120d82c3 Mon Sep 17 00:00:00 2001 From: Jurrian Fahner Date: Tue, 7 Dec 2021 23:40:08 +0100 Subject: [PATCH 1/3] Update gitlab_ci.md I had problems to get my configuration working for testcontainers in combination with gitlab. On my machine everything did run completely fine. But in Gitlab CI I got problems with Ryuk and also my mongo container couldn't be found. This was due to a wrong resolved ip address. I found out when setting the `TESTCONTAINERS_HOST_OVERRIDE` to `host.docker.internal` that it helped me a lot to solve these issues (since testcontainers exposes the ports on the host). Since my configuration is quite generic, I thought it would be nice to include it in the docs so other people could also benefit. --- .../continuous_integration/gitlab_ci.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/supported_docker_environment/continuous_integration/gitlab_ci.md b/docs/supported_docker_environment/continuous_integration/gitlab_ci.md index 5e701007ab0..4c36b4d634b 100644 --- a/docs/supported_docker_environment/continuous_integration/gitlab_ci.md +++ b/docs/supported_docker_environment/continuous_integration/gitlab_ci.md @@ -1,5 +1,48 @@ # GitLab CI +## example with docker.sock +If you have your own docker runner installed and you have `/var/run/docker.sock` mounted in the gitlabrunner, please apply the following steps: + +See below for example configuration for your own docker gitlab runner: +```toml +[[runners]] + name = "MACHINE_NAME" + url = "https://gitlab.com/" + token = "GENERATED_GITLAB_RUNNER_TOKEN" + executor = "docker" + [runners.custom_build_dir] + [runners.cache] + [runners.cache.s3] + [runners.cache.gcs] + [runners.cache.azure] + [runners.docker] + tls_verify = false + image = "docker:latest" + privileged = false + disable_entrypoint_overwrite = false + oom_kill_disable = false + disable_cache = false + volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"] + shm_size = 0 +``` + +Here is a sample `.gitlab-ci.yml` that executes the test with maven: +```yml +compile:api: + image: maven:3-eclipse-temurin + stage: test + variables: + TESTCONTAINERS_HOST_OVERRIDE: "host.docker.internal" + script: + - mvn package -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B + artifacts: + untracked: true +``` + +The environment variable `TESTCONTAINERS_HOST_OVERRIDE` needs to be configured otherwise a wrong ip address would be assigned, which could lead to failing tests. + +## example with dind - docker-in-docker service + In order to use Testcontainers in a Gitlab CI pipeline, you need to run the job as a Docker container (see [Patterns for running inside Docker](dind_patterns.md)). So edit your `.gitlab-ci.yml` to include the [Docker-In-Docker service](https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-workflow-with-docker-executor) (`docker:dind`) and set the `DOCKER_HOST` variable to `tcp://docker:2375` and `DOCKER_TLS_CERTDIR` to empty string. From 269bab0507cc0a13c10db5a87d0d33039ee86917 Mon Sep 17 00:00:00 2001 From: Jurrian Fahner Date: Thu, 9 Dec 2021 18:55:07 +0100 Subject: [PATCH 2/3] Implement feedback --- .../continuous_integration/gitlab_ci.md | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/docs/supported_docker_environment/continuous_integration/gitlab_ci.md b/docs/supported_docker_environment/continuous_integration/gitlab_ci.md index 4c36b4d634b..8fe6b7508db 100644 --- a/docs/supported_docker_environment/continuous_integration/gitlab_ci.md +++ b/docs/supported_docker_environment/continuous_integration/gitlab_ci.md @@ -1,7 +1,7 @@ # GitLab CI ## example with docker.sock -If you have your own docker runner installed and you have `/var/run/docker.sock` mounted in the gitlabrunner, please apply the following steps: +If you have your own docker runner installed, and you have `/var/run/docker.sock` mounted in the gitlabrunner. See below for example configuration for your own docker gitlab runner: ```toml @@ -10,11 +10,6 @@ See below for example configuration for your own docker gitlab runner: url = "https://gitlab.com/" token = "GENERATED_GITLAB_RUNNER_TOKEN" executor = "docker" - [runners.custom_build_dir] - [runners.cache] - [runners.cache.s3] - [runners.cache.gcs] - [runners.cache.azure] [runners.docker] tls_verify = false image = "docker:latest" @@ -26,20 +21,14 @@ See below for example configuration for your own docker gitlab runner: shm_size = 0 ``` -Here is a sample `.gitlab-ci.yml` that executes the test with maven: +Please include the following in the test task for `.gitlab-ci.yml`: ```yml -compile:api: - image: maven:3-eclipse-temurin - stage: test - variables: - TESTCONTAINERS_HOST_OVERRIDE: "host.docker.internal" - script: - - mvn package -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B - artifacts: - untracked: true +variables: + TESTCONTAINERS_HOST_OVERRIDE: "host.docker.internal" ``` -The environment variable `TESTCONTAINERS_HOST_OVERRIDE` needs to be configured otherwise a wrong ip address would be assigned, which could lead to failing tests. +The environment variable `TESTCONTAINERS_HOST_OVERRIDE` needs to be configured otherwise a wrong ip address would be +assigned to resolve the host of the runner, which could lead to failing tests. ## example with dind - docker-in-docker service From cc376be800e93d77939b02a6d6bdaed11e1f3de7 Mon Sep 17 00:00:00 2001 From: Jurrian Fahner Date: Fri, 17 Dec 2021 21:46:16 +0100 Subject: [PATCH 3/3] Implement feedback --- .../continuous_integration/gitlab_ci.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/supported_docker_environment/continuous_integration/gitlab_ci.md b/docs/supported_docker_environment/continuous_integration/gitlab_ci.md index 8fe6b7508db..b4571403654 100644 --- a/docs/supported_docker_environment/continuous_integration/gitlab_ci.md +++ b/docs/supported_docker_environment/continuous_integration/gitlab_ci.md @@ -1,9 +1,9 @@ # GitLab CI -## example with docker.sock -If you have your own docker runner installed, and you have `/var/run/docker.sock` mounted in the gitlabrunner. +## Example using Docker socket +This applies if you have your own GitlabCI runner installed, use the Docker executor and you have `/var/run/docker.sock` mounted in the runner configuration. -See below for example configuration for your own docker gitlab runner: +See below for an example runner configuration: ```toml [[runners]] name = "MACHINE_NAME" @@ -21,16 +21,15 @@ See below for example configuration for your own docker gitlab runner: shm_size = 0 ``` -Please include the following in the test task for `.gitlab-ci.yml`: +Please also include the following in your GitlabCI pipeline definitions (`.gitlab-ci.yml`) that use Testcontainers: ```yml variables: TESTCONTAINERS_HOST_OVERRIDE: "host.docker.internal" ``` -The environment variable `TESTCONTAINERS_HOST_OVERRIDE` needs to be configured otherwise a wrong ip address would be -assigned to resolve the host of the runner, which could lead to failing tests. +The environment variable `TESTCONTAINERS_HOST_OVERRIDE` needs to be configured, otherwise, a wrong IP address would be used to resolve the Docker host, which will likely lead to failing tests. -## example with dind - docker-in-docker service +## Example using DinD (Docker-in-Docker) In order to use Testcontainers in a Gitlab CI pipeline, you need to run the job as a Docker container (see [Patterns for running inside Docker](dind_patterns.md)). So edit your `.gitlab-ci.yml` to include the [Docker-In-Docker service](https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-workflow-with-docker-executor) (`docker:dind`) and set the `DOCKER_HOST` variable to `tcp://docker:2375` and `DOCKER_TLS_CERTDIR` to empty string.