version: "3"

x-scanner: &scanner
  build:
    context: .
    dockerfile: Dockerfile
  networks:
    - ps_net
    - bs_net
    - tp_net
    - ua_net
    - bs_redis_db
    - bs_mongo_db
  restart: always
  logging:
    driver: "json-file"
    options:
      max-size: "5M"
      max-file: "2"

x-db: &db
  REDIS_URL: redis://bs_redis:6379
  REDIS_PORT: 6379
  REDIS_HOST: bs_redis
  MONGO_URL: mongodb://piperFinance:Piper2022@bs_mongo:27017

services:
  bs:
    <<: *scanner
    hostname: BS
    container_name: bs
    ports:
      - 7001:7001
      - 6001:6001
    environment:
      ASYNQ_MON_URL: ":7001"
      API_URL: ":6001"
      MONGO_DBNAME: BS
      REDIS_DB: 1
      LOG_LEVEL: warn
      MAX_CONCURRENT_WORKER: 500
      MONGO_MAX_POOL_SIZE: 1000
      BLOCK_HEAD_DELAY: 15
      LIMIT_USERS: "false"
      SCAN_TASK_TIMEOUT: 20s
      TEST_RPC_CONNECTION_TIMEOUT: 12s
      RPC_ERROR_SILENCE: "true"
      PARSE_ERROR_SILENCE: "true"
      MULTICALL_ERROR_SILENCE: "true"
      SAVE_ALL_TRANSFER_LOGS: "false"
      # Easier Chains are 1,56,137,43114,9001,100,1284,10
      SUPPORTED_CHAINS: 1,250,56,137,43114,42161,9001,100,1284,10
      BS_URL: http://BS:6001
      PS_URL: http://PS:6002
      UA_URL: http://UA:6003
      TP_URL: http://TP:6004
      <<: *db
    volumes:
      - ./logs/:/var/bs/log/
    deploy:
      resources:
        limits:
          cpus: "1"
          memory: 650M

  redis:
    image: redis:latest
    hostname: bs_redis
    ports:
      - 127.0.0.1:6379:6379
    restart: always
    networks:
      - bs_redis_db
    healthcheck:
      test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
    volumes:
      - ./data/redis:/data
    command: >
      --port 6379 --maxclients 10000  --tcp-keepalive 300  --databases 8  --save 3000 500000  --rdbcompression yes --rdbchecksum no
    deploy:
      resources:
        limits:
          cpus: "1"
          memory: 1200M

  ## Maybe this bit will be seperated
  mongo-express:
    image: mongo-express:latest
    restart: always
    environment:
      - ME_CONFIG_BASICAUTH_USERNAME=admin
      - ME_CONFIG_BASICAUTH_PASSWORD=adminadminadminadmin
      - ME_CONFIG_MONGODB_ADMINUSERNAME=piperFinance
      - ME_CONFIG_MONGODB_ADMINPASSWORD=Piper2022
      - ME_CONFIG_MONGODB_SERVER=mongo
      - ME_CONFIG_MONGODB_PORT="27017"
    ports:
      - "5001:8081"
    networks:
      - bs_mongo_db

  mongo:
    image: mongo:4.4.6
    hostname: bs_mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: piperFinance
      MONGO_INITDB_ROOT_PASSWORD: Piper2022
      MONGO_INITDB_DATABASE: piper
    command: --wiredTigerCacheSizeGB 2
    volumes:
      - ./data/mongodb:/data/db
    ports:
      - 127.0.0.1:27017:27017
    restart: always
    healthcheck:
      test: echo 'db.stats().ok' | mongosh localhost:27017/test --quiet
      interval: 10s
      timeout: 10s
      retries: 5
      start_period: 40s
    networks:
      - bs_mongo_db
    deploy:
      resources:
        limits:
          cpus: "1"
          memory: 2048M

networks:
  bs_redis_db:
    driver: bridge
    name: bs_redis_db
  bs_mongo_db:
    name: bs_mongo_db
  bs_net:
    driver: bridge
    name: bs_net
  tp_net:
    external: true
    name: tp_net
  ua_net:
    external: true
    name: ua_net
  ps_net:
    external: true
    name: ps_net
