在运行测试之前让Docker等待Kafka启动

时间:2017-09-15 16:28:27

标签: jenkins apache-kafka docker-compose

我有以下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容器(代理)上的服务启动?

0 个答案:

没有答案