version: "3.6"

services:
  
  analyzer:
    image: ${REGISTRY}/analyzer:${TAG}
    restart: always
    network_mode: "host"
    volumes:
      - analyzer_data:/app/src/data
      - analyzer_config:/application/appConfigs
    depends_on:
      - rtsp-client-cpp
    logging:
      options:
        max-size: 1G

  api:
    image: ${REGISTRY}/api:${TAG}
    restart: always
    environment:
        - "TZ=Asia/Tehran"
        - "API_CONF=/go/bin/appConfigs/api.conf"
    network_mode: "host"
    volumes:
        - api_assets:/assets
        - /:/host
        - api_config:/go/bin/appConfigs
#    env_file:
#     - docker.env
    #depends_on:
      #- postgres 
      #- redis 
    privileged: true
    logging:
        options:
            max-size: 1G

  redis:
    image: ${REGISTRY}/redis:6.2.3
    restart: always
    ports:
      - 6379:6379
    volumes:
      - /var/lib/behnama/redis.conf:/usr/local/etc/redis/redis.conf"
      - "redis_data:/data"
    command: redis-server /usr/local/etc/redis/redis.conf
    logging:
      options:
        max-size: 1G

  stream:
    image: ${REGISTRY}/stream:${TAG}
    restart: always
    environment:
      - "TZ=Asia/Tehran"
      - "STREAM_CONF=/go/bin/appConfigs/stream.conf"
    network_mode: "host"
    volumes:
      - stream_config:/go/bin/appConfigs
      #- ${ROOT}/stream/records:/records
      - /:/host
#    env_file:
#      - docker.env
    # depends_on:
    #   - rtsp-client-cpp
    logging:
      options:
        max-size: 1G


  web:
    image: ${REGISTRY}/web:${TAG}
    restart: always
    network_mode: "host"
    logging:
      options:
        max-size: 1G

  onvifservice:
    image: ${REGISTRY}/onvifservice:${TAG}
    restart: always
#    env_file:
#     - docker.env
    network_mode: "host"
    environment:
      - "TZ=Asia/Tehran"
      - "ONVIF_CONF=/go/bin/onvif.conf" 
#      - "HTTP_PROXY=130.185.123.98:1234"
#      - "HTTPS_PROXY=130.185.123.98:1234"
    logging:
      options:
        max-size: 1G

  rtsp-client-cpp:
    image: ${REGISTRY}/rtsp-client-cpp:${TAG}
    restart: always
    network_mode: "host"
    environment:
      - "RTSP_CONF=./appConfigs/config.cfg"
    volumes:
      - rtsp_config:/app/appConfigs
#    depends_on:
#      - kafka  
    logging:
      options:
        max-size: 1G

  recorder:
    image: ${REGISTRY}/recorder:${TAG}
    restart: always
    environment:
      - "TZ=Asia/Tehran"
      - "RECORD_CONF=/go/bin/appConfigs/record.conf"
    network_mode: "host"
    volumes:
      - /:/host
#      - ./recorder/conf/record.conf:/go/bin/record.conf
      - recorder_config:/go/bin/appConfigs
    devices:
      - /dev:/dev
    privileged: true
    # depends_on:
    #   - rtsp-client-cpp
    logging:
      options:
        max-size: 1G


  postgres:
    image: ${REGISTRY}/postgres:13.0
    restart: always
    environment:
      - "POSTGRES_PASSWORD=123"
    volumes:
      - "postgress_data:/var/lib/postgresql/data"
      - "${ROOT}/postgresql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d"
    ports:
      - 5432:5432
    logging:
      options:
        max-size: 1G

#   influx:
#     image: ${REGISTRY}/influxdb:1.8.3
#     restart: always
#     volumes:
# #      - "./influx/conf/influxdb.conf:/etc/influxdb/influxdb.conf:ro"
#       - "${ROOT}/influxdb.conf:/etc/influxdb/influxdb.conf:ro"
#       - "${ROOT}/influx/data:/var/lib/influxdb"
#     environment:
#       - INFLUXDB_DB=behnama
#       - INFLUXDB_ADMIN_ENABLED=true
#       - INFLUXDB_ADMIN_USER=behuser
#       - INFLUXDB_ADMIN_PASSWORD=behuser
#     ports:
#       - 8088:8088
#       - 8086:8086
#       - 8082:8089
#     logging:
#       options:
#         max-size: 1G


  #influx-master:
  #  image: ${REGISTRY}/influxdb:1.8.3
  #  restart: always
  #  volumes:
  #    - "./influx-master/conf/influxdb.conf:/etc/influxdb/influxdb.conf:ro"
  #    - "./influx-master/data:/var/lib/influxdb"
  #  environment:
  #    - INFLUXDB_DB=behnama
  #    - INFLUXDB_ADMIN_ENABLED=true
  #    - INFLUXDB_ADMIN_USER=behuser
  #    - INFLUXDB_ADMIN_PASSWORD=behuser
  #  ports:
  #    - 8089:8088
  #    - 8087:8086
  #    - 8090:8089
  #  logging:
  #    options:
  #      max-size: 1G

  stunserver:
    image: ${REGISTRY}/stunserver:dev
    restart: always
    network_mode: "host"
    logging:
      options:
        max-size: 1G  

  zookeeper:
    image: '${REGISTRY}/zookeeper:3.6.2'
    restart: always
    ports:
      - 2181:2181
    volumes:
      - "zookeeper_data:/bitnami/zookeeper"
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
    logging:
      options:
        max-size: 1G

  kafka:
    image: '${REGISTRY}/kafka:2.8.0'
    restart: always
    network_mode: "host"
    volumes:
      - "kafka_data:/bitnami"
    environment:
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ZOOKEEPER_CONNECT: 127.0.0.1:2181
      ALLOW_PLAINTEXT_LISTENER: "yes"
      # KAFKA_CONF_FILE: "/opt/bitnami/kafka/config/server.properties"
      KAFKA_LOG_RETENTION_BYTES: 50000000
      KAFKA_LOG_SEGMENT_BYTES: 50000000
      # KAFKA_LOG_RETENTION_CHECK_INTERVAL_MS: 30000
      KAFKA_CFG_LOG_RETENTION_CHECK_INTERVAL_MS: 30000
      KAFKA_CFG_LOG_CLEANER_DELETE_RETENTION_MS: 5000
      KAFKA_CFG_LOG_CLEANER_MAX_COMPACTION_LAG_MS: 20000
      KAFKA_CFG_LOG_RETENTION_MS: 60000
      KAFKA_CFG_OFFSETS_RETENTION_CHECK_INTERVAL_MS: 120000
      KAFKA_CFG_UNCLEAN_LEADER_ELECTION_ENABLE: "true"
      # KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
      KAFKA_CFG_OFFSETS_RETENTION_MINUTES: 1
      LOG_RETENTION_CHECK_INTERVAL_MS: 30000
      KAFKA_HEAP_OPTS: -Xmx10G -Xms1G
    depends_on:
      - zookeeper
    logging:
      options:
        max-size: 1G
  jaeger:
    image: ${REGISTRY}/jaegertracing/all-in-one:1.23
    restart: always
    environment:
      - COLLECTOR_ZIPKIN_HOST_PORT=:9411
    ports:
      - "5775:5775/udp"
      - "6831:6831/udp"
      - "6832:6832/udp"
      - "5778:5778"
      - "16686:16686"
      - "14268:14268"
      - "14250:14250"
      - "9411:9411"
    logging:
      options:
        max-size: 1G
  seaweedfs:
    image: ${REGISTRY}/chrislusf/seaweedfs:3.23
    restart: always
    ports:
      - 9333:9333
      - 1091:8080
      - 8333:8333
      - 18080:8080
    command: 'server -s3 -s3.config=/etc/seaweedfs/s3.config -volume.max=${volumeMax} -master.volumeSizeLimitMB=${volumeSizeLimitMB} -dir="/data"'
    volumes:
      - ${seaweedfsData}:/data
      - ${ROOT}/seaweedfsStore.toml:/etc/seaweedfs/filer.toml
      - ${ROOT}/s3.config:/etc/seaweedfs/s3.config
  elk:
    image: ${REGISTRY}/sebp/elk:8.3.3
    user: root
    restart: always
    ports:
      - 5601:5601
      - 9200:9200
      - 5044:5044
    # logging:
    #  driver: none
      
 
  filebeat:
    image: ${REGISTRY}/filebeat:8.3.3
    user: root
    restart: always
    network_mode: "host"
    #logging:
    #  driver: none 
    depends_on:
      - elk
    volumes:
      - /var/lib/docker/containers:/var/lib/docker/containers:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ${ROOT}/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
      
  # minio1:
  #  image: 192.168.13.196:9000/minio:2022.05.04
  #  container_name: minio1
  #  restart: always
  #  command: "server /data --console-address :9001"
  #  ports:
  #   - "9000:10001"
  #   - "9001:9001"
  #  volumes:
  #   - "{ROOT}/minio:/data"
  #  environment:
  #   - "MINIO_ROOT_USER=zxASqw12"
  #   - "MINIO_ROOT_PASSWORD=zxASqw12"   
  
volumes:
  kafka_data:
  zookeeper_data:
  analyzer_config:
  api_config:
  api_assets:
  analyzer_data:
  rtsp_config:
  postgress_data:
  recorder_config:  
  stream_config:
  redis_data:
#  redis_config:
#    driver: local
#    driver_opts:
#      type: none
#      o: mount
#      device: /var/lib/behnama/recorder
  # driver_opts:
  #   type: 'none'
  #   o: 'bind,rw'
  #   device: '${ROOT}/kafka/bitnami'
#   zookeeper_data:
#     driver: local
  
#     driver_opts:
#       o: "size=5G"
#       device: tmpfs
#       type: tmpfs
