services:
  app:
    container_name: ${CONTAINER_NAME}-app
    build:
      context: ./
      dockerfile: ./docker/app/Dockerfile
      target: app-dev
      args:
        COMPOSER_AUTH: "{}"
        APP_BASE_DIR: ${APP_BASE_DIR-.}
    depends_on:
      db:
        condition: service_healthy
    environment:
      XDEBUG_IDE_KEY: ${XDEBUG_IDE_KEY}
    restart: unless-stopped
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ${APP_BASE_DIR-.}:/app

  db:
    container_name: ${CONTAINER_NAME}-db
    image: postgres:16-alpine3.18
    environment:
      USER_ID: ${USER_ID}
      GROUP_ID: ${GROUP_ID}
      PGDATA: /data/postgres
      PGUSER: ${DB_ROOT_USERNAME}
      POSTGRES_DB: ${DB_DATABASE}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - sqldata:/data/postgres
    ports:
      - ${DB_PORT}:5432
    restart: unless-stopped
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready", "-d" ]
      timeout: 5s
      retries: 3

  zookeeper:
    image: confluentinc/cp-zookeeper:latest
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - 22181:2181

  kafka:
    image: confluentinc/cp-kafka:latest
    container_name: kafka
    depends_on:
      - zookeeper
    ports:
      - 2181:2181
      - 9092:9092
      - 29092:29092
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

  kafdrop:
    image: obsidiandynamics/kafdrop
    restart: "no"
    ports:
      - 9900:9000
    environment:
      KAFKA_BROKERCONNECT: kafka:9092
    depends_on:
      - "kafka"

volumes:
  sqldata:
