version: '3.6'

# This is an example docker-compose file to quickly test an IPFS Cluster
# with multiple peers on a contained environment.

# It runs 3 cluster peers (cluster0, cluster1...) attached to go-ipfs daemons
# (ipfs0, ipfs1...) using the CRDT consensus component. Cluster peers
# autodiscover themselves using mDNS on the docker internal network.
#
# To interact with the cluster use "ipfs-cluster-ctl" (the cluster0 API port is
# exposed to the locahost. You can also "docker exec -ti cluster0 sh" and run
# it from the container. "ipfs-cluster-ctl peers ls" should show all 3 peers a few
# seconds after start.
#
# For persistance, a "compose" folder is created and used to store configurations
# and states. This can be used to edit configurations in subsequent runs. It looks
# as follows:
#
# compose/
# |-- cluster0
# |-- cluster1
# |-- ...
# |-- ipfs0
# |-- ipfs1
# |-- ...
# 
# During the first start, default configurations are created for all peers.
volumes:
  cluster0:
  ipfs0:

services:

  ##################################################################################
  ## Cluster PEER 0 ################################################################
  ##################################################################################

    ipfs0:
      container_name: ipfs0
      image: ipfs/go-ipfs:v0.10.0 # update this when go-ipfs M1 macs https://github.com/ipfs/go-ipfs/issues/8645
      volumes:
        - ipfs0:/data/ipfs
      ports:
        - "8080:8080" # ipfs gateway - expose if needed/wanted
      #- "4001:4001" # ipfs swarm - expose if needed/wanted
      #- "5001:5001" # ipfs api - expose if needed/wanted
        
    cluster0:
      container_name: cluster0
      image: ipfs/ipfs-cluster:v1.0.0-rc4
      depends_on:
        - ipfs0
      environment:
        CLUSTER_PEERNAME: cluster0
        CLUSTER_SECRET: ${CLUSTER_SECRET} # From shell variable if set
        CLUSTER_IPFSHTTP_NODEMULTIADDRESS: /dns4/ipfs0/tcp/5001
        CLUSTER_CRDT_TRUSTEDPEERS: '*' # Trust all peers in Cluster
        CLUSTER_RESTAPI_HTTPLISTENMULTIADDRESS: /ip4/0.0.0.0/tcp/9094 # Expose API
        CLUSTER_RESTAPI_BASICAUTHCREDENTIALS: test:test
        CLUSTER_RESTAPI_CORSALLOWEDMETHODS: GET,POST,OPTIONS
        CLUSTER_RESTAPI_CORSALLOWEDHEADERS: authorization
        CLUSTER_MONITORPINGINTERVAL: 2s # Speed up peer discovery
      volumes:
        - cluster0:/data/ipfs-cluster
      ports:
            # Open API port (allows ipfs-cluster-ctl usage on host)
            - "127.0.0.1:9094:9094"
            # The cluster swarm port would need  to be exposed if this container
            # was to connect to cluster peers on other hosts.
            # But this is just a testing cluster.
            # - "9096:9096" # Cluster IPFS Proxy endpoint
