networks:
  purple:
    external: true   # shared with purple-stack (bitcoinpurpled, electrumx)
  explorer-internal: # isolates MongoDB from the outside world
    name: purple-explorer-internal

services:
  mongodb:
    image: mongo:7
    container_name: purple-explorer-mongodb
    restart: unless-stopped
    networks:
      - explorer-internal
    volumes:
      # Keep MongoDB data in this repository's ./db directory.
      # Do not switch this back to a named Docker volume or the explorer will
      # stop using the already-synced local database.
      - type: bind
        source: ./db
        target: /data/db
        bind:
          create_host_path: true
      - ./docker/mongo-init.sh:/docker-entrypoint-initdb.d/init.sh:ro
    environment:
      # Root admin (used only by the init script to bootstrap the app user)
      MONGO_INITDB_ROOT_USERNAME: mongoadmin
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
      # Passed into mongo-init.sh to create the explorer app user
      MONGO_APP_USER: ${MONGO_USER}
      MONGO_APP_PASS: ${MONGO_PASSWORD}
      MONGO_APP_DB: ${MONGO_DATABASE:-explorerdb}
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

  explorer:
    build: .
    image: purple-explorer:local
    container_name: purple-explorer
    restart: unless-stopped
    depends_on:
      - mongodb
    networks:
      - purple           # reach bitcoinpurpled:13495 for RPC
      - explorer-internal
    ports:
      - "0.0.0.0:${EXPLORER_PORT:-3001}:3001"
    env_file: .env
    command: web
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

  sync-blocks:
    image: purple-explorer:local
    container_name: purple-explorer-sync-blocks
    restart: unless-stopped
    depends_on:
      - mongodb
      - explorer   # ensures the image is built before this runs
    networks:
      - purple           # reach bitcoinpurpled RPC
      - explorer-internal
    env_file: .env
    command: sync-blocks
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

  # sync-markets: disabled until exchanges are configured in docker/settings.json.tmpl
  # To enable: uncomment, configure markets_page.exchanges in the template, then redeploy.
  # sync-markets:
  #   image: purple-explorer:local
  #   container_name: purple-explorer-sync-markets
  #   restart: unless-stopped
  #   depends_on: [mongodb]
  #   networks: [explorer-internal]
  #   env_file: .env
  #   command: sync-markets

  sync-peers:
    image: purple-explorer:local
    container_name: purple-explorer-sync-peers
    restart: unless-stopped
    depends_on:
      - mongodb
    networks:
      - purple           # reach bitcoinpurpled for peer info
      - explorer-internal
    env_file: .env
    command: sync-peers
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
