version: '3.3'

services:
  artix-delivery:
    restart: always
    image: dockerregistry.artix.su:2443/artix-delivery-api:${TAG:-latest}
    container_name: delivery-api
    environment:
      kafka.enabled: 'true'
      kafka.server.ip: kafka
      kafka.server.port: 9092
      messaging.service.enabled: 'false'
      #messaging.service.host: 127.0.0.1
      #messaging.service.port: 12023
      #messaging.service.setting.key:
      postgresql_db: postgresql
      cs.host: 127.0.0.1
      cs.port: 38051
      cs.context.path: CSrest/rest
      cs.login: admin
      cs.password: admin
      accounting.server.type: BONUSES_CERTIFICATES
      accounting.host: 127.0.0.1
      accounting.port: 38056
      accounting.context.path: ACC
      accounting.terminal.id: LM_DEFAULT_TERMINAL
      accounting.auth.by.terminal.id: 'true'
      accounting.login: admin
      accounting.password: admin
    volumes:
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 18099:18099
    depends_on:
      postgresql:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - delivery_network
    healthcheck:
      test: curl --fail --silent localhost:18099/delivery/actuator/health | grep UP || exit 1
      interval: 10s
      timeout: 10s
      retries: 5

  artix-delivery-webapp:
    restart: always
    image: dockerregistry.artix.su:2443/artix-delivery-webapp:${TAG:-latest}
    container_name: delivery-webapp
    environment:
      service.host: delivery-api
      service.port: 18099
      service.login: admin
      service.password: admin
    ports:
      - 18065:18065
    depends_on:
      artix-delivery:
        condition: service_healthy
    networks:
      - delivery_network

  zookeeper:
    restart: always
    image: confluentinc/cp-zookeeper:latest
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    container_name: zookeeper
    ports:
      - 22181:2181
    networks:
      - delivery_network
    volumes:
      - ${PWD}/secrets:/etc/kafka/secrets
    healthcheck:
      test: nc -z localhost 2181 || exit -1
      interval: 10s
      timeout: 5s
      retries: 3

  kafka:
    restart: always
    image: confluentinc/cp-kafka:latest
    depends_on:
      zookeeper:
        condition: service_healthy
    ports:
      - 29092:29092
    container_name: kafka
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_LISTENERS: INTERNAL://0.0.0.0:9092,OUTSIDE://0.0.0.0:29092
      KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,OUTSIDE://localhost:29092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,OUTSIDE:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    networks:
      - delivery_network
    healthcheck:
      test: nc -z localhost 9092 || exit -1
      interval: 10s
      timeout: 5s
      retries: 3

  kafka-ui:
    restart: always
    container_name: kafka-ui
    image: provectuslabs/kafka-ui:latest
    ports:
      - 18080:8080
    depends_on:
      kafka:
        condition: service_healthy
    environment:
      DYNAMIC_CONFIG_ENABLED: 'true'
      AUTH_TYPE: "LOGIN_FORM"
      SPRING_SECURITY_USER_NAME: admin
      SPRING_SECURITY_USER_PASSWORD: admin
      KAFKA_CLUSTERS_0_NAME: delivery
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9092
    networks:
      - delivery_network
    healthcheck:
      test: nc -z localhost 8080 || exit -1
      interval: 10s
      timeout: 5s
      retries: 3

  postgresql:
    restart: always
    image: postgres:15.2
    container_name: postgresql
    environment:
      POSTGRES_USER: "netroot"
      POSTGRES_PASSWORD: "netroot"
      POSTGRES_DB: "delivery"
    volumes:
      - postgres-data:/var/lib/postgresql/data
    ports:
      - 15432:5432
    networks:
      - delivery_network
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U netroot -d delivery" ]
      interval: 10s
      timeout: 5s
      retries: 3

networks:
  delivery_network:

volumes:
  postgres-data:
