---
version: '3'

services:
  proftpd:
    build:
      context: .
    # Use this to keep the container running
    command: tail -f /dev/null
    depends_on:
      - kafka
    expose:
      - 2121
    privileged: true
    volumes:
      - ./files/proftpd/proftpd.conf:/usr/local/etc/proftpd.conf:ro
      - ./proftpd:/src/proftpd

  kafka:
    hostname: kafka
    image: bitnami/kafka:3.0
    depends_on:
      - zookeeper
    environment:
      ALLOW_PLAINTEXT_LISTENER: 'yes'
      KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://:9092,SSL://:9093
      KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: 'true'
      KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,SSL://:9093
      KAFKA_CFG_SSL_CLIENT_AUTH: requested
      KAFKA_CFG_SSL_KEYSTORE_LOCATION: /opt/bitnami/kafka/config/certs/kafka.keystore.pem
      KAFKA_CFG_SSL_KEY_PASSWORD: ''
      KAFKA_CFG_SSL_KEYSTORE_TYPE: PEM
      KAFKA_CFG_SSL_TRUSTSTORE_LOCATION: /opt/bitnami/kafka/config/certs/kafka.truststore.pem
      KAFKA_CFG_SSL_TRUSTSTORE_TYPE: PEM
      KAFKA_CFG_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_OPTS: -Djavax.net.debug=all
      KAFKA_TLS_CLIENT_AUTH: requested
      KAFKA_TLS_TYPE: PEM
    expose:
      - 9092
      - 9093
    healthcheck:
      test: "kafka-broker-api-versions.sh --version"
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - ./files/kafka/ca-cert.pem:/opt/bitnami/kafka/config/certs/kafka.truststore.pem:ro
      # NOTE: Apache Java can't handle the cert and key in the same PEM file.
      - ./files/kafka/server-cert.pem:/opt/bitnami/kafka/config/certs/kafka.keystore.pem:ro
      - ./files/kafka/server-key.pem:/opt/bitnami/kafka/config/certs/kafka.keystore.key:ro

  zookeeper:
    hostname: zookeeper
    image: bitnami/zookeeper:3.8
    environment:
      ALLOW_ANONYMOUS_LOGIN: 'yes'
    expose:
      - 2181
    healthcheck:
      test: "echo mntr | nc -w 2 -q 2 localhost 2181"
      interval: 10s
      timeout: 5s
      retries: 5
