version: '3.2'

services:

  uniswap-watcher-db:
    restart: unless-stopped
    image: postgres:14-alpine
    environment:
      - POSTGRES_USER=vdbm
      - POSTGRES_MULTIPLE_DATABASES=erc20-watcher,uni-watcher,uni-info-watcher,erc20-watcher-job-queue,uni-watcher-job-queue,uni-info-watcher-job-queue
      - POSTGRES_EXTENSION=erc20-watcher-job-queue:pgcrypto,uni-watcher-job-queue:pgcrypto,uni-info-watcher-job-queue:pgcrypto
      - POSTGRES_PASSWORD=password
    command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-c", "work_mem=2GB"]
    volumes:
      - ../config/postgresql/multiple-postgressql-databases.sh:/docker-entrypoint-initdb.d/multiple-postgressql-databases.sh
      - ../config/postgresql/create-pg-stat-statements.sql:/docker-entrypoint-initdb.d/create-pg-stat-statements.sql
      - uniswap_watcher_db_data:/var/lib/postgresql/data
    ports:
      - "0.0.0.0:15435:5432"
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "5432"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 10s
    shm_size: '8GB'

  erc20-watcher-server:
    restart: unless-stopped
    depends_on:
      uniswap-watcher-db:
        condition: service_healthy
    image: cerc/watcher-uniswap-v3:local
    working_dir: /app/packages/erc20-watcher
    environment:
      - DEBUG=vulcanize:*
    command: ["node", "--enable-source-maps", "dist/server.js"]
    volumes:
      - ../config/watcher-uniswap-v3/erc20-watcher.toml:/app/packages/erc20-watcher/environments/local.toml
    ports:
      - "0.0.0.0:3005:3001"
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "3001"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  uni-watcher-job-runner:
    restart: unless-stopped
    depends_on:
      uniswap-watcher-db:
        condition: service_healthy
    image: cerc/watcher-uniswap-v3:local
    working_dir: /app/packages/uni-watcher
    environment:
      - DEBUG=vulcanize:*
    command: ["sh", "-c", "./watch-contract.sh && node --enable-source-maps dist/job-runner.js"]
    volumes:
      - ../config/watcher-uniswap-v3/uni-watcher.toml:/app/packages/uni-watcher/environments/local.toml
      - ../config/watcher-uniswap-v3/watch-contract.sh:/app/packages/uni-watcher/watch-contract.sh
    ports:
      - "0.0.0.0:9004:9000"
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "9000"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  uni-watcher-server:
    restart: unless-stopped
    depends_on:
      uniswap-watcher-db:
        condition: service_healthy
      uni-watcher-job-runner:
        condition: service_healthy
    image: cerc/watcher-uniswap-v3:local
    environment:
      - UNISWAP_START_BLOCK=12369621
      - DEBUG=vulcanize:*
    working_dir: /app/packages/uni-watcher
    command: ["./run.sh"]
    volumes:
      - ../config/watcher-uniswap-v3/uni-watcher.toml:/app/packages/uni-watcher/environments/local.toml
      - ../config/watcher-uniswap-v3/run.sh:/app/packages/uni-watcher/run.sh
    ports:
      - "0.0.0.0:3003:3003"
      - "0.0.0.0:9005:9001"
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "3003"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  uni-info-watcher-job-runner:
    restart: unless-stopped
    depends_on:
      uniswap-watcher-db:
        condition: service_healthy
      erc20-watcher-server:
        condition: service_healthy
      uni-watcher-server:
        condition: service_healthy
    image: cerc/watcher-uniswap-v3:local
    working_dir: /app/packages/uni-info-watcher
    environment:
      - DEBUG=vulcanize:*
    command: ["node", "--enable-source-maps", "dist/job-runner.js"]
    volumes:
      - ../config/watcher-uniswap-v3/uni-info-watcher.toml:/app/packages/uni-info-watcher/environments/local.toml
    ports:
      - "0.0.0.0:9006:9002"
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "9002"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  uni-info-watcher-server:
    restart: unless-stopped
    depends_on:
      uniswap-watcher-db:
        condition: service_healthy
      erc20-watcher-server:
        condition: service_healthy
      uni-watcher-server:
        condition: service_healthy
      uni-info-watcher-job-runner:
        condition: service_healthy
    image: cerc/watcher-uniswap-v3:local
    environment:
      - UNISWAP_START_BLOCK=12369621
    working_dir: /app/packages/uni-info-watcher
    command: ["./run.sh"]
    volumes:
      - ../config/watcher-uniswap-v3/uni-info-watcher.toml:/app/packages/uni-info-watcher/environments/local.toml
      - ../config/watcher-uniswap-v3/run.sh:/app/packages/uni-info-watcher/run.sh
    ports:
      - "0.0.0.0:3004:3004"
      - "0.0.0.0:9007:9003"
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "3004"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  uniswap-v3-info:
    depends_on:
      uni-info-watcher-server:
        condition: service_healthy
    image: cerc/uniswap-v3-info:local
    ports:
      - "0.0.0.0:3006:3000"

volumes:
  uniswap_watcher_db_data: