I run my pipeline in image: docker/compose:latest
.
I use this script to build and run containers in this image:
script:
- docker-compose up -d
- CONTAINER_ID=$(docker-compose ps -q karate)
- EXIT_CODE=$(docker inspect -f '{{.State.ExitCode}}' $CONTAINER_ID)
- |
if [ $EXIT_CODE -eq 0 ]; then
echo "Tests passed!"
else
echo "Tests failed with exit code: $EXIT_CODE"
exit 1
fi
And check exit code of my container with Karate tests.
Test have access to API (send request to http://api:35000/
), and to Kafka-Rest (send request to http://kafkarest:38082), but only locally, if I run docker-compose up -d
on my PC.
If I run pipeline via script above, I can just connect and send request from my tests to API (via http://api/assets-api/upload-photo), but when i send request to Kafka-Rest to http://kafkarest:38082/consumers/testgroup
, I got error: Connect to kafkarest:38082 [kafkarest/172.20.0.12] failed: Connection refused (Connection refused), http call failed after 43 milliseconds for url: http://kafkarest:38082/consumers/testgroup
.
Also I tried to access http://kafkarest/, http://docker:38082, http://localhost, but it didn't help me. Which url I should use to connect to Kafka Rest?
My docker-compose:
api:
container_name: 'api'
depends_on:
- "db"
- "kafka"
build:
dockerfile: Dockerfile
context: .
ports:
- 35000:80
environment:
- ASPNETCORE_ENVIRONMENT=Docker
networks:
- capy-network
karate:
build:
context: .
dockerfile: Dockerfile-karate
environment:
- KARATE_ENV=mr
depends_on:
- db
- s3
- api
- kafkarest
networks:
- capy-network
zookeeper:
image: confluentinc/cp-zookeeper:4.1.1
container_name: 'zookeeper'
hostname: zookeeper
ports:
- "32181:32181"
environment:
ZOOKEEPER_CLIENT_PORT: 32181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_SYNC_LIMIT: 2
networks:
- capy-network
kafka:
image: confluentinc/cp-kafka:4.1.1
container_name: 'kafka'
hostname: kafka
ports:
- "29092:29092"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:32181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
networks:
- capy-network
kafka-ui:
image: provectuslabs/kafka-ui
container_name: 'kafka-ui'
ports:
- 8090:8080
restart: always
environment:
- KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka:29092
- KAFKA_CLUSTERS_0_ZOOKEEPER=zookeeper:32181
links:
- kafka
- zookeeper
networks:
- capy-network
schema-registry:
image: confluentinc/cp-schema-registry:4.1.1
container_name: 'schema-registry'
hostname: schema-registry
ports:
- "38081:38081"
depends_on:
- kafka
environment:
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: zookeeper:32181
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_LISTENERS: http://schema-registry:38081
SCHEMA_REGISTRY_DEBUG: "true"
networks:
- capy-network
kafkarest:
image: confluentinc/cp-kafka-rest:4.1.1
container_name: 'kafkarest'
hostname: kafkarest
ports:
- "38082:38082"
depends_on:
- schema-registry
environment:
KAFKA_REST_ZOOKEEPER_CONNECT: zookeeper:32181
KAFKA_REST_SCHEMA_REGISTRY_URL: schema-registry:38081
KAFKA_REST_HOST_NAME: kafkarest
KAFKA_REST_LISTENERS: http://kafkarest:38082
networks:
- capy-network
So, I detected a problem. We need to restart container with tests or add a delay for it, because Kafka Rest need some time to "wake up". After 3 restarts I've got test results. Tests were passed.