version: '3.8'

services:
  postgres:
    image: postgres:15-alpine
    container_name: reward-test-postgres
    environment:
      POSTGRES_USER: test
      POSTGRES_PASSWORD: test
      POSTGRES_DB: reward_test
    ports:
      - '5433:5432'
    volumes:
      - postgres-test-data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U test -d reward_test']
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - reward-test-network

  redis:
    image: redis:7-alpine
    container_name: reward-test-redis
    ports:
      - '6380:6379'
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - reward-test-network

  zookeeper:
    image: confluentinc/cp-zookeeper:7.5.0
    container_name: reward-test-zookeeper
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    networks:
      - reward-test-network

  kafka:
    image: confluentinc/cp-kafka:7.5.0
    container_name: reward-test-kafka
    depends_on:
      - zookeeper
    ports:
      - '9093:9092'
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9093
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
    healthcheck:
      test: ['CMD-SHELL', 'kafka-broker-api-versions --bootstrap-server localhost:9092']
      interval: 10s
      timeout: 10s
      retries: 5
    networks:
      - reward-test-network

volumes:
  postgres-test-data:

networks:
  reward-test-network:
    name: reward-test-network
    driver: bridge
