让docker在运行测试之前等待kafka启动

0md85ypi  于 2021-06-07  发布在  Kafka
关注(0)|答案(0)|浏览(289)

我有以下docker-compose.yml文件

version: '3'
services:
  zookeeper:
    ports:
      - "2181:2181"
    hostname: zookeeper
    image: confluentinc/cp-zookeeper
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000

  broker:
    image: confluentinc/cp-enterprise-kafka
    hostname: broker
    ports:
      - "9092:9092"
    depends_on:
      - zookeeper
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
      KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT://broker:9092'
      KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:9092
      CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:2181
      CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
      CONFLUENT_METRICS_ENABLE: 'true'
      CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'

  test:
    image: java:8
    volumes:
        - .:/src
        - ${GRADLE_USER_HOME}:/gradle_mount
    environment:
      - GRADLE_USER_HOME=/gradle_mount
      - SPRING_KAFKA_BOOTSTRAP-SERVERS=broker:9092
    depends_on:
        - broker
        - zookeeper
    working_dir: /src
    privileged: true
    command:  "./gradlew --no-daemon clean test --info"

测试在本地通过,但在jenkins中失败,我怀疑这是因为测试是在kafka服务运行之前启动的。
有没有办法让测试容器等待kafka容器(代理)上的服务启动?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题