services:
  emqx:
    image: emqx/emqx:5.8.8
    container_name: emqx
    environment:
      - EMQX_DASHBOARD__DEFAULT_USERNAME=user
      - EMQX_DASHBOARD__DEFAULT_PASSWORD=pass
    ports:
      - "127.0.0.1:1883:1883"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:18083/api/v5/status"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 20s

  kafka:
    image: apache/kafka:3.9.0
    container_name: kafka
    environment:
      - KAFKA_NODE_ID=1
      - KAFKA_PROCESS_ROLES=broker,controller
      - KAFKA_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
      - KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER
      - KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka:9093
      - KAFKA_LOG_DIRS=/tmp/kraft-combined-logs
      - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
    ports:
      - "127.0.0.1:9092:9092"

  valkey:
    image: valkey/valkey:9.0.0
    container_name: valkey
    ports:
      - "127.0.0.1:6379:6379"

  presense-decoder:
    build:
      context: ../
      dockerfile: build/package/Dockerfile.decoder
    image: presense-decoder
    container_name: presense-decoder
    environment:
      - REDIS_URL=valkey:6379
      - KAFKA_URL=kafka:9092
    depends_on:
      - kafka
      - valkey
    restart: always

  presense-server:
    build:
      context: ../
      dockerfile: build/package/Dockerfile.server
    image: presense-server
    container_name: presense-server
    environment:
      - REDIS_URL=valkey:6379
      - KAFKA_URL=kafka:9092
    depends_on:
      - kafka
      - emqx
    ports:
      - "127.0.0.1:1902:1902"
    restart: always

  presense-bridge:
    build:
      context: ../
      dockerfile: build/package/Dockerfile.bridge
    image: presense-bridge
    container_name: presense-bridge
    environment:
      - KAFKA_URL=kafka:9092
      - MQTT_HOST=emqx:1883
      - MQTT_USERNAME=user
      - MQTT_PASSWORD=pass
    depends_on:
      kafka:
        condition: service_started
      emqx:
        condition: service_healthy
    restart: always
