# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2.1'

services:

  ca:
    container_name: ca
    image: _DOCKER_NS_/fabric-ca:_CA_RELEASE_
    dns_search: .
    environment:
      - FABRIC_CA_SERVER_TLS_ENABLED=_TLS_ENABLED_
    logging: &logging
      driver: json-file
      options:
        max-size: "25m"
        max-file: "2"
    volumes:
      - ./nodes/ca:/etc/hyperledger/fabric-ca-server

  tlsca:
    container_name: tlsca
    image: _DOCKER_NS_/fabric-ca:_CA_RELEASE_
    dns_search: .
    environment:
      - FABRIC_CA_SERVER_TLS_ENABLED=_TLS_ENABLED_
    logging:
      <<: *logging
    volumes:
      - ./nodes/tlsca:/etc/hyperledger/fabric-ca-server

  orderer:
    container_name: orderer
    image: _DOCKER_NS_/fabric-orderer:_FABRIC_RELEASE_
    dns_search: .
    environment:
      - ORDERER_GENERAL_TLS_ENABLED=_TLS_ENABLED_
    logging:
      <<: *logging
    volumes:
      - ./nodes/orderer:/etc/hyperledger/fabric
    depends_on:
      - ca

  couchdb-base:
    image: _DOCKER_NS_/fabric-couchdb:_COUCH_RELEASE_
    logging:
      <<: *logging
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5984"]
      interval: 10s
      timeout: 10s
      retries: 10

  peer-base:
    image: _DOCKER_NS_/fabric-peer:_FABRIC_RELEASE_
    dns_search: .
    logging:
      <<: *logging
    environment:
      - CORE_PEER_TLS_ENABLED=_TLS_ENABLED_
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1:7051
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=compose_default
      - FABRIC_LOGGING_SPEC=WARNING
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: peer node start

  couchdb1:
    container_name: couchdb1
    extends:
      service: couchdb-base

  peer1:
    container_name: peer1
    extends:
      service: peer-base
    environment:
      - CORE_PEER_ID=peer1
      - CORE_PEER_ADDRESS=peer1:7051
      - CORE_PEER_GOSSIP_ENDPOINT=peer1:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.net:7051
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb1:5984
    volumes:
        - ./nodes/peer1:/etc/hyperledger/fabric
    depends_on:
      orderer:
          condition: service_started
      couchdb1:
          condition: service_healthy

  couchdb2:
    container_name: couchdb2
    extends:
      service: couchdb-base

  peer2:
    container_name: peer2
    extends:
      service: peer-base
    environment:
      - CORE_PEER_ID=peer2
      - CORE_PEER_ADDRESS=peer2:7051
      - CORE_PEER_GOSSIP_ENDPOINT=peer2:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2.org1.net:7051
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb2:5984
    volumes:
        - ./nodes/peer2:/etc/hyperledger/fabric
    depends_on:
      orderer:
        condition: service_started
      peer1:
        condition: service_started
      couchdb2:
        condition: service_healthy

  couchdb3:
    container_name: couchdb3
    extends:
      service: couchdb-base

  peer3:
    container_name: peer3
    extends:
      service: peer-base
    environment:
      - CORE_PEER_ID=peer3
      - CORE_PEER_ADDRESS=peer3:7051
      - CORE_PEER_GOSSIP_ENDPOINT=peer3:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer3.org1.net:7051
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb3:5984
    volumes:
        - ./nodes/peer3:/etc/hyperledger/fabric
    depends_on:
      orderer:
        condition: service_started
      peer1:
        condition: service_started
      couchdb3:
        condition: service_healthy

  couchdb4:
    container_name: couchdb4
    extends:
      service: couchdb-base

  peer4:
    container_name: peer4
    extends:
      service: peer-base
    environment:
      - CORE_PEER_ID=peer4
      - CORE_PEER_ADDRESS=peer4:7051
      - CORE_PEER_GOSSIP_ENDPOINT=peer4:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer4.org1.net:7051
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb4:5984
    volumes:
        - ./nodes/peer4:/etc/hyperledger/fabric
    depends_on:
      orderer:
        condition: service_started
      peer1:
        condition: service_started
      couchdb4:
        condition: service_healthy

  cli:
    image: _DOCKER_NS_/fabric-peer:_FABRIC_RELEASE_
    dns_search: .
    environment:
      - CORE_PEER_TLS_ENABLED=_TLS_ENABLED_
      - CORE_NEXT=true
      - FABRIC_LOGGING_SPEC=DEBUG
    volumes:
      - ./nodes/cli:/etc/hyperledger/fabric
      - .:/cli
    working_dir: /cli
    depends_on:
      - orderer
      - peer1
