version: "3.5"

services:
  cassandra:
    image: cassandra:4.1.1
    environment:
      - "MAX_HEAP_SIZE=256M"
      - "HEAP_NEWSIZE=128M"
    expose:
      - "9042"
    networks:
      services-network:
        aliases:
          - cassandra
    healthcheck:
      test: ["CMD", "cqlsh", "-u cassandra", "-p cassandra" ,"-e describe keyspaces"]
      interval: 15s
      timeout: 30s
      retries: 10

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_DATABASE: db
      MYSQL_ROOT_PASSWORD: cadence
    volumes:
      - ./mysql-init:/docker-entrypoint-initdb.d
    expose:
      - "3306"
    networks:
      services-network:
        aliases:
          - mysql

  postgres:
    image: postgres:12.4
    environment:
      POSTGRES_PASSWORD: cadence
      POSTGRES_USER: cadence
    expose:
      - "5432"
    networks:
      services-network:
        aliases:
          - postgres

  zookeeper:
    image: wurstmeister/zookeeper:3.4.6
    expose:
      - "2181"
    networks:
      services-network:
        aliases:
          - zookeeper

  kafka:
    image: wurstmeister/kafka:2.12-2.1.1
    depends_on:
      - zookeeper
    expose:
      - "9092"
    networks:
      services-network:
        aliases:
          - kafka
    environment:
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.22
    expose:
      - "9200"
    networks:
      services-network:
        aliases:
          - elasticsearch
    environment:
      - discovery.type=single-node

  mongo:
    image: mongo:5
    restart: always
    networks:
      services-network:
        aliases:
          - mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: cadence

  unit-test:
    build:
      context: ../../
      dockerfile: ./docker/buildkite/Dockerfile
    command: sh -c "make .just-build && make install-schema && make cover_profile"
    environment:
      - "CASSANDRA_HOST=cassandra"
      - "CASSANDRA=1"
      - "MYSQL=1"
      - "POSTGRES=1"
      - "MONGODB=1"
      - "CASSANDRA_SEEDS=cassandra"
      - "MYSQL_SEEDS=mysql"
      - "POSTGRES_SEEDS=postgres"
      - "POSTGRES_USER=cadence"
      - "POSTGRES_PASSWORD=cadence"
    depends_on:
      cassandra:
        condition: service_healthy
      mysql:
        condition: service_started
      postgres:
        condition: service_started
      mongo:
        condition: service_started
    volumes:
      - ../../:/cadence
      - /cadence/.build/ # ensure we don't mount the build directory
      - /cadence/.bin/ # ensure we don't mount the bin directory
    networks:
      services-network:
        aliases:
          - unit-test

  integration-test-cassandra:
    build:
      context: ../../
      dockerfile: ./docker/buildkite/Dockerfile
    command: make cover_integration_profile
    environment:
      - "CASSANDRA_HOST=cassandra"
      - "CASSANDRA=1"
      - "CASSANDRA_SEEDS=cassandra"
      - "ES_SEEDS=elasticsearch"
      - "KAFKA_SEEDS=kafka"
      - "TEST_TAG=esintegration"
    depends_on:
      cassandra:
        condition: service_healthy
      elasticsearch:
        condition: service_started
      kafka:
        condition: service_started
    volumes:
      - ../../:/cadence
      - /cadence/.build/ # ensure we don't mount the build directory
      - /cadence/.bin/ # ensure we don't mount the bin directory
    networks:
      services-network:
        aliases:
          - integration-test

  integration-test-mysql:
    build:
      context: ../../
      dockerfile: ./docker/buildkite/Dockerfile
    command: make cover_integration_profile
    environment:
      - "MYSQL=1"
      - "MYSQL_SEEDS=mysql"
      - "ES_SEEDS=elasticsearch"
      - "KAFKA_SEEDS=kafka"
      - "PERSISTENCE_TYPE=sql"
      - "PERSISTENCE_PLUGIN=mysql"
      - "TEST_TAG=esintegration"
    depends_on:
      - mysql
      - elasticsearch
      - kafka
    volumes:
      - ../../:/cadence
      - /cadence/.build/ # ensure we don't mount the build directory
      - /cadence/.bin/ # ensure we don't mount the bin directory
    networks:
      services-network:
        aliases:
          - integration-test

  integration-test-postgres:
    build:
      context: ../../
      dockerfile: ./docker/buildkite/Dockerfile
    command: make cover_integration_profile
    environment:
      - "POSTGRES=1"
      - "POSTGRES_SEEDS=postgres"
      - "PERSISTENCE_PLUGIN=postgres"
      - "ES_SEEDS=elasticsearch"
      - "KAFKA_SEEDS=kafka"
      - "PERSISTENCE_TYPE=sql"
      - "TEST_TAG=esintegration"
    depends_on:
      - postgres
      - elasticsearch
      - kafka
    volumes:
      - ../../:/cadence
      - /cadence/.build/ # ensure we don't mount the build directory
      - /cadence/.bin/ # ensure we don't mount the bin directory
    networks:
      services-network:
        aliases:
          - integration-test

  integration-test-v2:
    build:
      context: ../../
      dockerfile: ./docker/buildkite/Dockerfile
    command: make cover_integration_profile EVENTSV2=true
    environment:
      - "CASSANDRA_HOST=cassandra"
      - "CASSANDRA=1"
      - "CASSANDRA_SEEDS=cassandra"
      - "ES_SEEDS=elasticsearch"
      - "KAFKA_SEEDS=kafka"
      - "TEST_TAG=esintegration"
    depends_on:
      cassandra:
        condition: service_healthy
      elasticsearch:
        condition: service_started
      kafka:
        condition: service_started
    volumes:
      - ../../:/cadence
      - /cadence/.build/ # ensure we don't mount the build directory
      - /cadence/.bin/ # ensure we don't mount the bin directory
    networks:
      services-network:
        aliases:
          - integration-test

  integration-test-ndc-cassandra:
    build:
      context: ../../
      dockerfile: ./docker/buildkite/Dockerfile
    command: make cover_ndc_profile
    environment:
      - "CASSANDRA_HOST=cassandra"
      - "CASSANDRA=1"
      - "CASSANDRA_SEEDS=cassandra"
      - "ES_SEEDS=elasticsearch"
      - "KAFKA_SEEDS=kafka"
      - "TEST_TAG=esintegration"
    depends_on:
      cassandra:
        condition: service_healthy
      elasticsearch:
        condition: service_started
      kafka:
        condition: service_started
    volumes:
      - ../../:/cadence
      - /cadence/.build/ # ensure we don't mount the build directory
      - /cadence/.bin/ # ensure we don't mount the bin directory
    networks:
      services-network:
        aliases:
          - integration-test-ndc

  integration-test-ndc-mysql:
    build:
      context: ../../
      dockerfile: ./docker/buildkite/Dockerfile
    command: make cover_ndc_profile
    environment:
      - "MYSQL=1"
      - "MYSQL_SEEDS=mysql"
      - "ES_SEEDS=elasticsearch"
      - "KAFKA_SEEDS=kafka"
      - "PERSISTENCE_TYPE=sql"
      - "PERSISTENCE_PLUGIN=mysql"
      - "TEST_TAG=esintegration"
    depends_on:
      - mysql
      - elasticsearch
      - kafka
    volumes:
      - ../../:/cadence
      - /cadence/.build/ # ensure we don't mount the build directory
      - /cadence/.bin/ # ensure we don't mount the bin directory
    networks:
      services-network:
        aliases:
          - integration-test-ndc

networks:
  services-network:
    name: services-network
    driver: bridge
