#
# Copyright © 2016-2026 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.
#

services:
# Valkey cluster
# The latest version of Valkey compatible with ThingsBoard is 8.0
  valkey-node-0:
    image: bitnamilegacy/valkey-cluster:8.0
    volumes:
      - ./tb-node/valkey-cluster-data-0:/bitnami/valkey/data
    environment:
      - 'VALKEY_PASSWORD=thingsboard'
      - 'VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5'

  valkey-node-1:
    image: bitnamilegacy/valkey-cluster:8.0
    volumes:
      - ./tb-node/valkey-cluster-data-1:/bitnami/valkey/data
    depends_on:
      - valkey-node-0
    environment:
      - 'VALKEY_PASSWORD=thingsboard'
      - 'VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5'

  valkey-node-2:
    image: bitnamilegacy/valkey-cluster:8.0
    volumes:
      - ./tb-node/valkey-cluster-data-2:/bitnami/valkey/data
    depends_on:
      - valkey-node-1
    environment:
      - 'VALKEY_PASSWORD=thingsboard'
      - 'VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5'

  valkey-node-3:
    image: bitnamilegacy/valkey-cluster:8.0
    volumes:
      - ./tb-node/valkey-cluster-data-3:/bitnami/valkey/data
    depends_on:
      - valkey-node-2
    environment:
      - 'VALKEY_PASSWORD=thingsboard'
      - 'VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5'

  valkey-node-4:
    image: bitnamilegacy/valkey-cluster:8.0
    volumes:
      - ./tb-node/valkey-cluster-data-4:/bitnami/valkey/data
    depends_on:
      - valkey-node-3
    environment:
      - 'VALKEY_PASSWORD=thingsboard'
      - 'VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5'

  valkey-node-5:
    image: bitnamilegacy/valkey-cluster:8.0
    volumes:
      - ./tb-node/valkey-cluster-data-5:/bitnami/valkey/data
    depends_on:
      - valkey-node-0
      - valkey-node-1
      - valkey-node-2
      - valkey-node-3
      - valkey-node-4
    environment:
      - 'VALKEY_PASSWORD=thingsboard'
      - 'REDISCLI_AUTH=thingsboard'
      - 'VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5'
      - 'VALKEY_CLUSTER_REPLICAS=1'
      - 'VALKEY_CLUSTER_CREATOR=yes'

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