5

I'd like to run Testontainers in Gitlab for testing Spring Boot applicaton. After I created Gitlab runner (changed URL and token):

sudo gitlab-runner register -n \
  --url https://gitlab.com/ \
  --registration-token REGISTRATION_TOKEN \
  --executor docker \
  --description "My Docker Runner" \
  --docker-image "docker:19.03.12" \
  --docker-privileged \
  --docker-volumes "/certs/client"

I've written a simple ci pipeline:

stages:
  - test

services:
  - docker:19.03.12-dind

variables:
  DOCKER_HOST: tcp://docker:2376
  DOCKER_TLS_CERTDIR: "/certs"
    
test:
  stage: test
  image: amazoncorretto:11
  script:
    - java -version
    - chmod +x gradlew
    - ./gradlew test
  tags:
    - docker-dind

The test looks like:

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

@SpringBootTest
@Testcontainers
class DemoApplicationTests {
    
    @Container
    protected static GenericContainer<?> kc = new GenericContainer<>("jboss/keycloak")
            .withEnv("KEYCLOAK_USER", "admin")
            .withEnv("KEYCLOAK_PASSWORD", "admin")
            .withExposedPorts(8080)
            .waitingFor(Wait.forHttp("/auth").forStatusCode(200));

    @Test
    void contextLoads() {
    }
}

Instead of Keycloak it could be something else, but the result would be the same:

DemoApplicationTests > initializationError FAILED
    org.testcontainers.containers.ContainerLaunchException at GenericContainer.java:327
        Caused by: org.testcontainers.containers.ContainerFetchException at GenericContainer.java:1278
            Caused by: java.lang.IllegalStateException at DockerClientProviderStrategy.java:214s

It looks to me, that build container (amazoncorreto:11) is not run as a docker in docker. If I check DockerClientProviderStrategy.java:214, I can see:

Could not find a valid Docker environment. Please see logs and check configuration

The Testontaniners version is 1.15.0. What I'm doing wrong? Am I mission something?

bert
  • 111
  • 1
  • 8
  • 1
    I just found this ticket on Gitlab: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3251 (Gitlab runner dind service cannot be used with Testcontainers) – abedurftig Mar 18 '21 at 21:29
  • @abedurftig gitlab CI can run testcontainers if you use docker-in-docker. We already made it without using DiD-Service – LenglBoy Dec 18 '21 at 09:10

0 Answers0