#
# Copyright © 2016-2022 The Thingsboard Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

version: '2.2'

services:
# Redis cluster
  redis-node-0:
    image: bitnami/redis-cluster:7.0
    volumes:
      - ./tb-node/redis-cluster-data-0:/bitnami/redis/data
    environment:
      - 'REDIS_PASSWORD=thingsboard'
      - 'REDISCLI_AUTH=thingsboard'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-1:
    image: bitnami/redis-cluster:7.0
    volumes:
      - ./tb-node/redis-cluster-data-1:/bitnami/redis/data
    depends_on:
      - redis-node-0
    environment:
      - 'REDIS_PASSWORD=thingsboard'
      - 'REDISCLI_AUTH=thingsboard'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-2:
    image: bitnami/redis-cluster:7.0
    volumes:
      - ./tb-node/redis-cluster-data-2:/bitnami/redis/data
    depends_on:
      - redis-node-1
    environment:
      - 'REDIS_PASSWORD=thingsboard'
      - 'REDISCLI_AUTH=thingsboard'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-3:
    image: bitnami/redis-cluster:7.0
    volumes:
      - ./tb-node/redis-cluster-data-3:/bitnami/redis/data
    depends_on:
      - redis-node-2
    environment:
      - 'REDIS_PASSWORD=thingsboard'
      - 'REDISCLI_AUTH=thingsboard'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-4:
    image: bitnami/redis-cluster:7.0
    volumes:
      - ./tb-node/redis-cluster-data-4:/bitnami/redis/data
    depends_on:
      - redis-node-3
    environment:
      - 'REDIS_PASSWORD=thingsboard'
      - 'REDISCLI_AUTH=thingsboard'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-5:
    image: bitnami/redis-cluster:7.0
    volumes:
      - ./tb-node/redis-cluster-data-5:/bitnami/redis/data
    depends_on:
      - redis-node-0
      - redis-node-1
      - redis-node-2
      - redis-node-3
      - redis-node-4
    environment:
      - 'REDIS_PASSWORD=thingsboard'
      - 'REDISCLI_AUTH=thingsboard'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
      - 'REDIS_CLUSTER_REPLICAS=1'
      - 'REDIS_CLUSTER_CREATOR=yes'

# ThingsBoard setup to use redis-cluster
  tb-core1:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-core2:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-rule-engine1:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-rule-engine2:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-mqtt-transport1:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-mqtt-transport2:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-http-transport1:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-http-transport2:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-coap-transport:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-lwm2m-transport:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-snmp-transport:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-vc-executor1:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
  tb-vc-executor2:
    env_file:
      - cache-redis-cluster.env
    depends_on:
      - redis-node-5
