I have a spring boot integration test using kafka testcontainer(v1.19.8). The test runs fine in local environment. In contrast, when running in Gitlab CI pipeline the test fails with the following error:
Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: advertised.listeners cannot use the nonroutable meta-address 0.0.0.0. Use a routable IP address.
My Gitlab CI job looks like the following:
# DinD service is required for Testcontainers
services:
- name: docker:dind
# explicitly disable tls to avoid docker startup interruption
command: ["--tls=false"]
variables:
# Instruct Testcontainers to use the daemon of DinD, use port 2375 for non-tls connections.
DOCKER_HOST: "tcp://docker:2375"
# Instruct Docker not to start over TLS.
DOCKER_TLS_CERTDIR: ""
# Improve performance with overlayfs.
DOCKER_DRIVER: overlay2
test:
image: gradle:5.0
stage: test
script: ./gradlew test
I didn't set KAFKA_ADVERTISED_LISTENERS for my test container as I don't know the mapped port in advance. The mapped port is only available after I start the testcontainer and after started, the addEnv()
method on the KafkaContainer
is not usable to redefine the value of advertised listeners.
Questions:
Is there anything I can change in gitlab-ci job configuration so that kafka testcontainer stops using 0.0.0.0 in KAFKA_ADVERTISED_LISTENERS ?
Is there any solution using KafkaContainer
or I have to switch to FixedHostPortGenericContainer
(although I don't like the idea of a fixed port and the constructor of FixedHostPortGenericContainer
is deprecated) ?
The reason was that I was using kafka testcontainer with an image "apache/kafka:3.9.0" and there was a bug in that kafka version: https://lists.apache.org/thread/hgp2z47p1bq1ghtlm2p927d9bs43l6yy