version: '3.2'

services:
  sushiswap-route-processor-watcher-db:
    restart: unless-stopped
    image: postgres:14-alpine
    environment:
      - POSTGRES_USER=vdbm
      - POSTGRES_MULTIPLE_DATABASES=sushiswap-route-processor-watcher,sushiswap-route-processor-watcher-job-queue
      - POSTGRES_EXTENSION=sushiswap-route-processor-watcher-job-queue:pgcrypto
      - POSTGRES_PASSWORD=password
    volumes:
      - ../config/postgresql/multiple-postgressql-databases.sh:/docker-entrypoint-initdb.d/multiple-postgressql-databases.sh
      - sushiswap_route-processor_watcher_db_data:/var/lib/postgresql/data
    ports:
      - "5432"
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "5432"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 10s

  sushiswap-route-processor-watcher-job-runner:
    restart: unless-stopped
    depends_on:
      sushiswap-route-processor-watcher-db:
        condition: service_healthy
    image: cerc/watcher-sushiswap:local
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_ETH_RPC_ENDPOINTS: ${CERC_ETH_RPC_ENDPOINTS}
    working_dir: /app/packages/route-processor-watcher
    command: ["bash", "./start-job-runner.sh"]
    volumes:
      - ../config/watcher-sushiswap-route-processor/watcher-config-template.toml:/app/packages/route-processor-watcher/environments/watcher-config-template.toml
      - ../config/common/start-job-runner.sh:/app/packages/route-processor-watcher/start-job-runner.sh
    ports:
      - "9000"
    healthcheck:
      test: ["CMD", "nc", "-vz", "127.0.0.1", "9000"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  sushiswap-route-processor-watcher-server:
    restart: unless-stopped
    depends_on:
      sushiswap-route-processor-watcher-db:
        condition: service_healthy
      sushiswap-route-processor-watcher-job-runner:
        condition: service_healthy
    image: cerc/watcher-sushiswap:local
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_ETH_RPC_ENDPOINTS: ${CERC_ETH_RPC_ENDPOINTS}
    working_dir: /app/packages/route-processor-watcher
    command: ["bash", "./start-server.sh"]
    volumes:
      - ../config/watcher-sushiswap-route-processor/watcher-config-template.toml:/app/packages/route-processor-watcher/environments/watcher-config-template.toml
      - ../config/common/start-server.sh:/app/packages/route-processor-watcher/start-server.sh
      - sushiswap_route-processor_watcher_gql_logs_data:/app/packages/route-processor-watcher/gql-logs
    ports:
      - "3008"
      - "9001"
    healthcheck:
      test: ["CMD", "nc", "-vz", "127.0.0.1", "3008"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

volumes:
  sushiswap_route-processor_watcher_db_data:
  sushiswap_route-processor_watcher_gql_logs_data:
