version: "3"
services:
  nginx:
    image: nginx
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx/logs:/var/log/nginx
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/certs:/certs
    depends_on:
      - contact-center

  contact-center:
    image: ${CC_IMAGE:-chatopera/contact-center:develop}
    restart: always
    ports:
      - "${CC_WEB_PORT:-8035}:8035"
      - "${CC_SOCKET_PORT:-8036}:8036"
    volumes:
      - ./contact-center/data:/data
      - ./contact-center/logs:/logs
    environment:
      - "JAVA_OPTS=-Xmx${CC_JAVA_XMX:-12288m} -Xms${CC_JAVA_XMS:-2048m} -XX:PermSize=256m -XX:MaxPermSize=1024m -Djava.net.preferIPv4Stack=true"
      - SERVER_PORT=8035
      - SERVER_LOG_PATH=/logs
      - SERVER_LOG_LEVEL=${LOG_LEVEL:-WARN}
      - WEB_UPLOAD_PATH=/data
      - SPRING_DATA_ELASTICSEARCH_PROPERTIES_PATH_DATA=/data
      - UK_IM_SERVER_PORT=8036
      - UK_IM_SERVER_HOST=localhost
      - UK_IM_SERVER_THREADS=10
      # set a separated port for SSL
      - CS_IM_SERVER_SSL_PORT=${CC_SOCKET_PORT:-8036}
      - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/cosinee?useUnicode=true&characterEncoding=UTF-8
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=${DB_PASSWD:-123456}
      - SPRING_REDIS_HOST=redis
      - SPRING_REDIS_PORT=6379
      - SPRING_REDIS_PASSWORD=${DB_PASSWD:-123456}
      - SPRING_DATA_ELASTICSEARCH_CLUSTER_NAME=elasticsearch
      - SPRING_DATA_ELASTICSEARCH_CLUSTER_NODES=elasticsearch:9300
      - SPRING_ACTIVEMQ_BROKER_URL=tcp://activemq:61616
      - CSKEFU_MODULE_CALLOUT=false
      - CSKEFU_MODULE_CONTACTS=true
      - CSKEFU_MODULE_CHATBOT=true
      - SKYPE_CHANNEL_CRM=${SKYPE_CHANNEL_CRM:-placeholder}
      - BOT_THRESHOLD_FAQ_BEST_REPLY=${BOT_THRESHOLD_FAQ_BEST_REPLY:-0.9}
      - BOT_THRESHOLD_FAQ_SUGG_REPLY=${BOT_THRESHOLD_FAQ_SUGG_REPLY:-0.3}
      - CSKEFU_SETTINGS_WEBIM_VISITOR_SEPARATE=true
      - TONGJI_BAIDU_SITEKEY=${TONGJI_BAIDU_SITEKEY:-placeholder}
      - ADS_LOGIN_BANNER=${ADS_LOGIN_BANNER:-off}
    depends_on:
      - mysql
      - redis
      - elasticsearch
      - activemq

  activemq:
    image: chatopera/activemq:5.14.3
    restart: always
    environment:
      - ACTIVEMQ_ADMIN_LOGIN=admin
      - ACTIVEMQ_ADMIN_PASSWORD=${DB_PASSWD:-123456}
      - ACTIVEMQ_ENABLED_SCHEDULER=true
      - ACTIVEMQ_MIN_MEMORY=1024
      - ACTIVEMQ_MAX_MEMORY=4096
    volumes:
      - ./database/activemq/data:/data
      - ./database/activemq/logs:/var/log/activemq
    ports:
      - "${ACTIVEMQ_PORT1:-8051}:8161"
      - "${ACTIVEMQ_PORT2:-8052}:61616"
      - "${ACTIVEMQ_PORT3:-8053}:61613"

  mysql:
    image: chatopera/mysql:5.7
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=${DB_PASSWD:-123456}
      - MYSQL_USER=admin
      - MYSQL_PASSWORD=${DB_PASSWD:-123456}
    ports:
      - "${MYSQL_PORT:-8037}:3306"
    volumes:
      - ./database/mysql/data:/var/lib/mysql
    command: --max_allowed_packet=32505856

  redis:
    image: chatopera/redis:5.0.5
    environment:
      - REDIS_PASSWORD=${DB_PASSWD:-123456}
    restart: always
    volumes:
      - ./database/redis/data:/data
    ports:
      - "${REDIS_PORT:-8041}:6379"

  elasticsearch:
    image: elasticsearch:2.4.6
    restart: always
    volumes:
      - ./database/elasticsearch/data:/usr/share/elasticsearch/data
      - ./database/elasticsearch/config:/usr/share/elasticsearch/config
      - ./database/elasticsearch/plugins:/usr/share/elasticsearch/plugins
    ports:
      - "${ES_PORT1:-8039}:9200"
      - "${ES_PORT2:-8040}:9300"
