services:
  openwarehouse.auth.api:
    image: openwarehouse.auth.api
    build:
      context: .
      dockerfile: OpenWarehouse.auth.api/Dockerfile
    environment:
      - ConnectionString=Host=${postgres_host};Database=openWarehouse.auth;Username=${postgres_username};Password=${postgres_pass}
      - Kafka={"BootstrapServers":"kafka:9092","TopicRoot":"auth"}
      - ASPNETCORE_ENVIRONMENT=${ASP_NET_ENV}
    depends_on:
      - postgres.db
      - kafka
    networks:
      - open-warehouse

  openwarehouse.warehouse.api:
    image: openwarehouse.warehouse.api
    build:
      context: .
      dockerfile: OpenWarehouse.warehouse.api/Dockerfile
    networks:
      - open-warehouse
    environment:
      - Auth:Url=${auth_url}
      - ASPNETCORE_ENVIRONMENT=${ASP_NET_ENV}
      - Kafka={"BootstrapServers":"kafka:9092","TopicRoot":"warehouse"}
      - ConnectionString=Host=${postgres_host};Database=openWarehouse.warehouse;Username=${postgres_username};Password=${postgres_pass}
    depends_on:
      - kafka
      - postgres.db
      - openwarehouse.auth.api
  
  postgres.db:
    image: postgres:latest
    container_name: Openwarehouse-postgres
    volumes:
      - postgresData:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: ${postgres_pass}
    networks:
      - open-warehouse
    ports:
      - 5432:5432
  
  pgadmin4:
    image: dpage/pgadmin4
    container_name: pgadmin4
    environment:
      - PGADMIN_DEFAULT_EMAIL=user@domain.com
      - PGADMIN_DEFAULT_PASSWORD=!Q2w3e4r
    networks:
      - open-warehouse
  
  kafka:
    image: bitnami/kafka:latest
    ports:
      - "9092:9092" 
      - "9093:9093"   
    volumes:
      - kafka_data:/bitnami
      - ./create-topics.sh:/docker-entrypoint-initdb.d/create-topics.sh
    environment:
      - KAFKA_ENABLE_KRAFT=yes
      - KAFKA_CFG_NODE_ID=1
      - KAFKA_CFG_PROCESS_ROLES=broker,controller
      - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka:9094
      - KAFKA_CFG_LISTENERS=INTERNAL://:9092,EXTERNAL://:9093,CONTROLLER://:9094
      - KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://kafka:9092,EXTERNAL://localhost:9093
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT
      - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
      - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
      - KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR=1
      - KAFKA_CFG_DEFAULT_REPLICATION_FACTOR=1
      - KAFKA_CFG_MIN_INSYNC_REPLICAS=1
      - KAFKA_CLUSTER_ID=nKk3Nd8LQbyf9hl0cdfN0A
      - KAFKA_AUTO_CREATE_TOPICS_ENABLE=true
      - KAFKA_CFG_LOG_RETENTION_MS=86400000
      - KAFKA_CFG_LOG_CLEANUP_POLICY=delete
    networks:
      - open-warehouse
        
  nginx:
    image: nginx
    ports:
      - 80:80
      - 443:443
    networks:
      - open-warehouse
    depends_on:
      - openwarehouse.auth.api
      - openwarehouse.warehouse.api
      - kafka
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./certs/localhost.crt:/etc/ssl/certs/localhost.crt:ro
      - ./certs/localhost.key:/etc/ssl/private/localhost.key:ro

networks:
  open-warehouse:
    driver: bridge

volumes:
  postgresData:
    driver: local
  zookeeper_data:
    driver: local
  kafka_data:
    driver: local